From 5017fa536ead8ba0259487595f909f31ae3c70d5 Mon Sep 17 00:00:00 2001 From: Leonard Lorenz Date: Sat, 21 Nov 2020 22:35:36 +0100 Subject: [PATCH] added optional social media buttons --- content/static/css/index.css | 5 +++++ content/templates/index.html | 20 ++++++++++++++++++++ site/Cargo.lock | 2 +- site/src/main.rs | 15 +++++++++++++++ site/src/routes.rs | 15 +++++++++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) diff --git a/content/static/css/index.css b/content/static/css/index.css index 50e4f53..beb14fc 100644 --- a/content/static/css/index.css +++ b/content/static/css/index.css @@ -10,6 +10,11 @@ html { padding-left: 20%; } +.social-icon { + height: 1em; + width: 1em; +} + @media (max-width:1080px) { html { font-family: sans-serif; diff --git a/content/templates/index.html b/content/templates/index.html index a0b9750..ccc480d 100644 --- a/content/templates/index.html +++ b/content/templates/index.html @@ -17,5 +17,25 @@ I have a blog.
If you have questions or input for me please send me an E-Mail to {{ email }}

+
+

+

+

diff --git a/site/Cargo.lock b/site/Cargo.lock index 53dde99..984dc4b 100644 --- a/site/Cargo.lock +++ b/site/Cargo.lock @@ -561,7 +561,7 @@ checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] name = "crablog" -version = "0.2.0" +version = "0.2.1" dependencies = [ "actix-files", "actix-web", diff --git a/site/src/main.rs b/site/src/main.rs index 46357b4..5f2287a 100644 --- a/site/src/main.rs +++ b/site/src/main.rs @@ -21,6 +21,21 @@ pub static CONFIG_MAP: Lazy>> = Lazy::new(|| { config.insert(String::from("USERNAME"), env::var("USERNAME").expect("USERNAME variable not set.")); config.insert(String::from("EMAIL"), env::var("EMAIL").expect("EMAIL variable not set.")); config.insert(String::from("BIND_PORT"), env::var("BIND_PORT").expect("BIND_PORT variable not set.")); + if let Ok(acc) = env::var("GITHUB_ACCOUNT") { + config.insert(String::from("GITHUB_ACCOUNT"), acc.clone()); + } + if let Ok(acc) = env::var("TWITTER_ACCOUNT") { + config.insert(String::from("TWITTER_ACCOUNT"), acc.clone()); + } + if let Ok(acc) = env::var("MASTODON_ACCOUNT") { + config.insert(String::from("MASTODON_ACCOUNT"), acc.clone()); + } + if let Ok(acc) = env::var("DISCORD_ACCOUNT") { + config.insert(String::from("DISCORD_ACCOUNT"), acc.clone()); + } + if let Ok(acc) = env::var("REDDIT_ACCOUNT") { + config.insert(String::from("REDDIT_ACCOUNT"), acc.clone()); + } RwLock::new(config) }); diff --git a/site/src/routes.rs b/site/src/routes.rs index d065380..fd820de 100644 --- a/site/src/routes.rs +++ b/site/src/routes.rs @@ -38,6 +38,21 @@ async fn root(tmpl: web::Data) -> Result { let mut context = Context::new(); context.insert("username", CONFIG_MAP.read().unwrap().get("USERNAME").unwrap()); context.insert("email", CONFIG_MAP.read().unwrap().get("EMAIL").unwrap()); + if let Some(acc) = CONFIG_MAP.read().unwrap().get("GITHUB_ACCOUNT") { + context.insert("github_account", acc); + } + if let Some(acc) = CONFIG_MAP.read().unwrap().get("TWITTER_ACCOUNT") { + context.insert("twitter_account", acc); + } + if let Some(acc) = CONFIG_MAP.read().unwrap().get("MASTODON_ACCOUNT") { + context.insert("mastodon_account", acc); + } + if let Some(acc) = CONFIG_MAP.read().unwrap().get("DISCORD_ACCOUNT") { + context.insert("discord_account", acc); + } + if let Some(acc) = CONFIG_MAP.read().unwrap().get("REDDIT_ACCOUNT") { + context.insert("reddit_account", acc); + } let result = tmpl.render("index.html", &context) .map_err(|e| error::ErrorInternalServerError(format!("Template error\n{}", e)))?;