Add some if-tags and such to make meta-tags more editable

This commit is contained in:
Sofia 2018-04-19 01:33:48 +03:00
parent 49db42c82f
commit b8a4e97ae2
5 changed files with 81 additions and 41 deletions

View File

@ -7,10 +7,20 @@ css = []
before_navbar_url = "test_page/resources/before_navbar.html" before_navbar_url = "test_page/resources/before_navbar.html"
before_content_url = "test_page/resources/before_content.html" before_content_url = "test_page/resources/before_content.html"
after_content_url = "test_page/resources/after_content.html" after_content_url = "test_page/resources/after_content.html"
#favicon = "favicon.png" favicon = "favicon.png"
#twitter_author = "@teascade"
#google_robots = "all" charset = "utf-8"
#google_site_verification = "" mobile_viewport = true
meta_description = true
meta_og = true
[google]
google_robots = "all"
google_site_verification = "some_verification"
[twitter]
twitter_site = "@teascade"
twitter_creator = "@teascade"
[navbar] [navbar]
items = ["about", "other", "google"] items = ["about", "other", "google"]

View File

@ -15,6 +15,8 @@ pub struct GlobalConfigToml {
pub navbar: Option<NavbarConfig>, pub navbar: Option<NavbarConfig>,
#[serde(rename = "resource")] #[serde(rename = "resource")]
pub resources: Option<HashMap<String, ResourceConfig>>, pub resources: Option<HashMap<String, ResourceConfig>>,
pub twitter: Option<TwitterConfig>,
pub google: Option<GoogleConfig>,
} }
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]
@ -30,13 +32,28 @@ pub struct WebsiteConfig {
pub use_default_css: bool, pub use_default_css: bool,
pub javascript: Vec<String>, pub javascript: Vec<String>,
pub css: Vec<String>, pub css: Vec<String>,
pub favicon: Option<String>, pub favicon: Option<String>,
pub before_navbar_url: Option<String>, pub before_navbar_url: Option<String>,
pub before_content_url: Option<String>, pub before_content_url: Option<String>,
pub after_content_url: Option<String>, pub after_content_url: Option<String>,
pub twitter_author: Option<String>,
pub google_robots: Option<String>, pub mobile_viewport: Option<bool>,
pub google_site_verification: Option<String>, pub meta_description: Option<bool>,
pub charset: Option<String>,
pub meta_og: Option<bool>,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct GoogleConfig {
pub google_robots: String,
pub google_site_verification: String,
}
#[derive(Deserialize, Serialize, Clone, Debug)]
pub struct TwitterConfig {
pub twitter_site: String,
pub twitter_creator: String,
} }
#[derive(Deserialize, Serialize, Clone, Debug)] #[derive(Deserialize, Serialize, Clone, Debug)]

View File

@ -108,12 +108,16 @@ fn run() -> Result<(), ()> {
before_navbar_url: None, before_navbar_url: None,
before_content_url: None, before_content_url: None,
after_content_url: None, after_content_url: None,
twitter_author: init_opt.twitter_author,
google_robots: None, mobile_viewport: None,
google_site_verification: None, meta_description: None,
charset: Some("utf-8".to_owned()),
meta_og: None,
}, },
navbar: navbar, navbar: navbar,
resources: None, resources: None,
twitter: None,
google: None,
}; };
match file_writer::write_toml(&PathBuf::from("config.toml"), &config, opt.overwrite) { match file_writer::write_toml(&PathBuf::from("config.toml"), &config, opt.overwrite) {

View File

@ -96,29 +96,26 @@ impl Template {
.favicon .favicon
.unwrap_or(String::new()), .unwrap_or(String::new()),
); );
let google_robots = config
.global_config let mut twitter_site = String::new();
.website let mut twitter_creator = String::new();
.google_robots if let Some(twitter) = config.global_config.twitter.clone() {
.unwrap_or(String::new()); twitter_site = twitter.twitter_site;
let google_verification = config twitter_creator = twitter.twitter_creator;
.global_config }
.website
.google_site_verification let mut google_robots = String::new();
.unwrap_or(String::new()); let mut google_site_verification = String::new();
let twitter_author = config if let Some(google) = config.global_config.google.clone() {
.global_config google_robots = google.google_robots;
.website google_site_verification = google.google_site_verification;
.twitter_author }
.unwrap_or(String::new());
let map = hashmap!( let map = hashmap!(
"website_name".to_owned() => config.global_config.website.website_name, "website_name".to_owned() => config.global_config.website.website_name,
"page_title".to_owned() => config.page_config.page.title, "page_title".to_owned() => config.page_config.page.title,
"page_description".to_owned() => config.page_config.page.description,
"favicon".to_owned() => favicon.to_owned(), "favicon".to_owned() => favicon.to_owned(),
"google_robots".to_owned() => google_robots,
"google_verification".to_owned() => google_verification,
"twitter_author".to_owned() => twitter_author,
"before_navbar".to_owned() => before_navbar, "before_navbar".to_owned() => before_navbar,
"before_content".to_owned() => before_content, "before_content".to_owned() => before_content,
@ -131,7 +128,21 @@ impl Template {
"navbar".to_owned() => config.global_config.navbar.is_some().to_string(), "navbar".to_owned() => config.global_config.navbar.is_some().to_string(),
"navbar_content".to_owned() => navbar_content, "navbar_content".to_owned() => navbar_content,
"content".to_owned() => content "content".to_owned() => content,
"mobile_viewport".to_owned() => config.global_config.website.mobile_viewport.unwrap_or(true).to_string(),
"meta_description".to_owned() => config.global_config.website.meta_description.unwrap_or(true).to_string(),
"charset".to_owned() => config.global_config.website.charset.unwrap_or("utf-8".to_owned()),
"meta_og".to_owned() => config.global_config.website.meta_og.unwrap_or(true).to_string(),
"twitter".to_owned() => config.global_config.twitter.is_some().to_string(),
"google".to_owned() => config.global_config.google.is_some().to_string(),
"twitter_site".to_owned() => twitter_site,
"twitter_creator".to_owned() => twitter_creator,
"google_robots".to_owned() => google_robots,
"google_site_verification".to_owned() => google_site_verification
); );
map map

View File

@ -2,14 +2,13 @@
<html> <html>
<head> <head>
<meta name="viewport" content="width=device-width, initial-scale=1"> {{if mobile_viewport}}
<meta name="description" content="{{page_description}}"> <meta name="viewport" content="width=device-width, initial-scale=1">{{endif}} {{if meta_description}}
<meta charset="utf-8">
<meta name="robots" content="{{google_robots}}">
<meta name="google-site-verification" content="{{google_verification}}" />
<meta name="title" content="{{website_name}}"> <meta name="title" content="{{website_name}}">
<meta name="description" content="{{page_description}}">{{endif}}
<meta charset="{{charset}}"> {{if google}}
<meta name="robots" content="{{google_robots}}">
<meta name="google-site-verification" content="{{google_site_verification}}" /> {{endif}} {{if meta_og}}
<meta property="og:title" content="{{page_title}}"> <meta property="og:title" content="{{page_title}}">
<meta property="og:site_name" content="{{website_name}}"> <meta property="og:site_name" content="{{website_name}}">
<meta property="og:type" content="website"> <meta property="og:type" content="website">
@ -18,13 +17,12 @@
<meta property="og:image:secure_url" content="{{favicon}}"> <meta property="og:image:secure_url" content="{{favicon}}">
<meta property="og:image:type" content="image/png"> <meta property="og:image:type" content="image/png">
<meta property="og:image:width" content="512"> <meta property="og:image:width" content="512">
<meta property="og:image:height" content="512"> <meta property="og:image:height" content="512"> {{endif}} {{if twitter}}
<meta name="twitter:site" content="{{twitter_site}}">
<meta name="twitter:site" content="{{twitter_author}}"> <meta name="twitter:creator" content="{{twitter_creator}}">
<meta name="twitter:creator" content="{{twitter_author}}">
<meta name="twitter:title" content="{{page_title}}"> <meta name="twitter:title" content="{{page_title}}">
<meta name="twitter:description" content="{{page_description}}"> <meta name="twitter:description" content="{{page_description}}">
<meta name="twitter:image" content="{{favicon}}"> {{if use_default_css}} <meta name="twitter:image" content="{{favicon}}"> {{endif}} {{if use_default_css}}
<link rel="stylesheet" href="/css/default.css"> {{endif}} {{css_links}}{{javascript_links}} <link rel="stylesheet" href="/css/default.css"> {{endif}} {{css_links}}{{javascript_links}}
<link rel="shortcut icon" href="{{favicon}}"></link> <link rel="shortcut icon" href="{{favicon}}"></link>