Add css/js tags and make new page better a bit
This commit is contained in:
parent
e8f8650dce
commit
2659bb61a1
@ -2,8 +2,8 @@
|
||||
website_name = "Test Website Name!"
|
||||
built_pages = ["test_page/about.toml", "test_page/other.toml"]
|
||||
use_default_css = true
|
||||
javascript = []
|
||||
css = []
|
||||
javascript = ["test.js"]
|
||||
css = ["test.css"]
|
||||
before_navbar_url = "test_page/resources/before_navbar.html"
|
||||
before_content_url = "test_page/resources/before_content.html"
|
||||
after_content_url = "test_page/resources/after_content.html"
|
||||
@ -12,6 +12,11 @@ after_content_url = "test_page/resources/after_content.html"
|
||||
#google_robots = "all"
|
||||
#google_site_verification = ""
|
||||
|
||||
[resource.test] todo
|
||||
source = "source_path"
|
||||
destination = "destination_path"
|
||||
is_recursive_folder = false
|
||||
|
||||
[navbar]
|
||||
items = ["about", "other", "google"]
|
||||
|
||||
|
@ -12,6 +12,8 @@ const DEFAULT_CSS: &'static str = include_str!("templates/default-css.css");
|
||||
const PAGE_TEMPLATE: &'static str = include_str!("templates/page-template.html");
|
||||
const NAVBAR_ITEM: &'static str = include_str!("templates/navbar/item-template.html");
|
||||
const NAVBAR_IMAGE_ITEM: &'static str = include_str!("templates/navbar/image-item-template.html");
|
||||
const CSS_TAG: &'static str = include_str!("templates/meta_tags/css_tag.html");
|
||||
const JS_TAG: &'static str = include_str!("templates/meta_tags/js_tag.html");
|
||||
|
||||
fn fetch_config() -> Result<Config, Error> {
|
||||
match Config::new() {
|
||||
@ -32,6 +34,8 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
||||
|
||||
logger.log(LogLevel::INFO, "Generating page templates");
|
||||
let page_template = Template::new(PAGE_TEMPLATE);
|
||||
let css_tag_template = Template::new(CSS_TAG);
|
||||
let js_tag_template = Template::new(JS_TAG);
|
||||
|
||||
let mut navbar_content = String::new();
|
||||
if config.global_config.navbar.is_some() {
|
||||
@ -46,14 +50,43 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
||||
let configs = config.get_configs()?;
|
||||
let mut renders = Vec::new();
|
||||
for config in configs.clone() {
|
||||
logger.log(
|
||||
LogLevel::DETAILER,
|
||||
format!("Setting up to render {}", config.page_config.page.html_path),
|
||||
);
|
||||
|
||||
// Generate CSS tagstags
|
||||
logger.log(LogLevel::DETAILER, "Generating CSS tags");
|
||||
let mut css_string = String::new();
|
||||
let mut css_list = config.global_config.website.css.clone();
|
||||
if let Some(mut list) = config.page_config.page.css.clone() {
|
||||
css_list.append(&mut list);
|
||||
}
|
||||
|
||||
for item in css_list {
|
||||
let data = Template::css_tag_data_from(item);
|
||||
css_string += &*css_tag_template.render(&data);
|
||||
}
|
||||
|
||||
// Generate JS tags
|
||||
logger.log(LogLevel::DETAILER, "Generating JS tags");
|
||||
let mut js_string = String::new();
|
||||
let mut js_list = config.global_config.website.javascript.clone();
|
||||
if let Some(mut list) = config.page_config.page.javascript.clone() {
|
||||
js_list.append(&mut list);
|
||||
}
|
||||
|
||||
for item in js_list {
|
||||
let data = Template::css_tag_data_from(item);
|
||||
js_string += &*js_tag_template.render(&data);
|
||||
}
|
||||
|
||||
// Generate and render Injections
|
||||
logger.log(LogLevel::DETAILER, "Rendering injections.");
|
||||
let (before_navbar, before_content, after_content) =
|
||||
renderer::render_injections(&logger, &config)?;
|
||||
|
||||
logger.log(
|
||||
LogLevel::DETAILER,
|
||||
format!("Rendering {}", config.page_config.page.html_path),
|
||||
);
|
||||
logger.log(LogLevel::DETAILER, "Rendering");
|
||||
|
||||
let markdown = renderer::render_markdown_content(&config)?;
|
||||
let data = Template::page_data_from(
|
||||
@ -62,6 +95,8 @@ pub fn build(logger: &Logger, opt: &Opt, _: &BuildOpt) -> Result<(), Error> {
|
||||
before_navbar,
|
||||
before_content,
|
||||
after_content,
|
||||
css_string,
|
||||
js_string,
|
||||
markdown,
|
||||
);
|
||||
let rendered = page_template.render(&data);
|
||||
|
@ -108,6 +108,10 @@ pub fn generate_new_page(logger: &Logger, opt: &Opt, new_opt: &NewOpt) -> Result
|
||||
file_writer::write_file(&markdown_path, PLACEHOLDER_MARKDOWN, opt.overwrite)?;
|
||||
|
||||
if !new_opt.no_modify_config {
|
||||
if !opt.overwrite && PathBuf::from("config.toml").exists() {
|
||||
return Err(Error::new(LogLevel::SEVERE, "Add --overwrite flag to overwrite config.toml, or --no-modify-config to not modify config.toml automatically."));
|
||||
}
|
||||
|
||||
logger.log(
|
||||
LogLevel::INFO,
|
||||
format!("Adding page config path to config.toml"),
|
||||
|
@ -63,6 +63,12 @@ impl Template {
|
||||
result
|
||||
}
|
||||
|
||||
pub fn css_tag_data_from(link: String) -> Data {
|
||||
hashmap!(
|
||||
"link".to_owned() => link
|
||||
)
|
||||
}
|
||||
|
||||
pub fn navbar_item_data_from(item: NavbarItem) -> Data {
|
||||
let map = hashmap!(
|
||||
"title".to_owned() => item.title,
|
||||
@ -79,6 +85,8 @@ impl Template {
|
||||
before_navbar: String,
|
||||
before_content: String,
|
||||
after_content: String,
|
||||
css_tags: String,
|
||||
js_tags: String,
|
||||
content: String,
|
||||
) -> Data {
|
||||
let favicon = config.page_config.page.favicon.unwrap_or(
|
||||
@ -116,6 +124,9 @@ impl Template {
|
||||
"before_content".to_owned() => before_content,
|
||||
"after_content".to_owned() => after_content,
|
||||
|
||||
"css_links".to_owned() => css_tags,
|
||||
"javascript_links".to_owned() => js_tags,
|
||||
|
||||
"use_default_css".to_owned() => config.global_config.website.use_default_css.to_string(),
|
||||
"navbar".to_owned() => config.global_config.navbar.is_some().to_string(),
|
||||
|
||||
|
1
src/templates/meta_tags/css_tag.html
Normal file
1
src/templates/meta_tags/css_tag.html
Normal file
@ -0,0 +1 @@
|
||||
<link rel="stylesheet" href="{{link}}">
|
1
src/templates/meta_tags/js_tag.html
Normal file
1
src/templates/meta_tags/js_tag.html
Normal file
@ -0,0 +1 @@
|
||||
<script type="text/javascript" src="{{link}}"></script>
|
Loading…
Reference in New Issue
Block a user