opengraph tags, favicon

This commit is contained in:
Tomáš Mládek 2020-12-28 19:59:57 +01:00
parent 874219f22f
commit 4116713c1f
3 changed files with 22 additions and 3 deletions

View file

@ -24,6 +24,7 @@ struct State {
garden_dir: PathBuf,
index_file: Option<String>,
title: Option<String>,
server_name: String,
tera: Tera,
}
@ -84,6 +85,13 @@ fn main() -> anyhow::Result<()> {
.short("t")
.long("title")
.help("Title of this digital garden."),
)
.arg(
Arg::with_name("SERVER_NAME")
.takes_value(true)
.short("u")
.long("garden-url")
.help("Hostname of the server of this digital garden (for metadata)."),
);
let matches = app.get_matches();
@ -115,6 +123,11 @@ fn main() -> anyhow::Result<()> {
garden_dir: directory.to_path_buf(),
index_file: matches.value_of("INDEX_FILE").map(|s| s.to_string()),
title: matches.value_of("TITLE").map(|s| s.to_string()),
server_name: matches
.value_of("SERVER_NAME")
.map_or(matches.value_of("BIND").unwrap().to_string(), |s| {
s.to_string()
}),
tera,
};
@ -167,9 +180,7 @@ async fn render(
let full_path = data.garden_dir.join(path.as_str());
// Redirect to ".md" version if requested path matches a .md file without the extension
if !full_path.exists()
&& Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists()
{
if !full_path.exists() && Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists() {
return Ok(HttpResponse::Found()
.header(http::header::LOCATION, format!("{}.md", path.to_string()))
.finish());
@ -241,6 +252,8 @@ async fn render(
None => None,
},
);
context.insert("server_name", &data.server_name);
context.insert("path", &path.to_string());
Ok(HttpResponse::Ok().body(
data.tera

BIN
templates/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -9,6 +9,12 @@
href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400;1,700&family=Montserrat&display=swap"
rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:site_name" content="{{garden_title}}" />
<meta property="og:title" content="{{page_title}}" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://{{server_name}}/{{path}}" />
<meta property="og:image" content="/static/favicon.png" />
<link rel="shortcut icon" href="/static/favicon.png" type="image/x-icon">
<link href="/static/main.css" rel="stylesheet">
</head>