opengraph tags, favicon
This commit is contained in:
parent
874219f22f
commit
4116713c1f
3 changed files with 22 additions and 3 deletions
19
src/main.rs
19
src/main.rs
|
@ -24,6 +24,7 @@ struct State {
|
||||||
garden_dir: PathBuf,
|
garden_dir: PathBuf,
|
||||||
index_file: Option<String>,
|
index_file: Option<String>,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
|
server_name: String,
|
||||||
tera: Tera,
|
tera: Tera,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +85,13 @@ fn main() -> anyhow::Result<()> {
|
||||||
.short("t")
|
.short("t")
|
||||||
.long("title")
|
.long("title")
|
||||||
.help("Title of this digital garden."),
|
.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();
|
let matches = app.get_matches();
|
||||||
|
@ -115,6 +123,11 @@ fn main() -> anyhow::Result<()> {
|
||||||
garden_dir: directory.to_path_buf(),
|
garden_dir: directory.to_path_buf(),
|
||||||
index_file: matches.value_of("INDEX_FILE").map(|s| s.to_string()),
|
index_file: matches.value_of("INDEX_FILE").map(|s| s.to_string()),
|
||||||
title: matches.value_of("TITLE").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,
|
tera,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -167,9 +180,7 @@ async fn render(
|
||||||
let full_path = data.garden_dir.join(path.as_str());
|
let full_path = data.garden_dir.join(path.as_str());
|
||||||
|
|
||||||
// Redirect to ".md" version if requested path matches a .md file without the extension
|
// Redirect to ".md" version if requested path matches a .md file without the extension
|
||||||
if !full_path.exists()
|
if !full_path.exists() && Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists() {
|
||||||
&& Path::new(&format!("{}.md", full_path.to_str().unwrap())).exists()
|
|
||||||
{
|
|
||||||
return Ok(HttpResponse::Found()
|
return Ok(HttpResponse::Found()
|
||||||
.header(http::header::LOCATION, format!("{}.md", path.to_string()))
|
.header(http::header::LOCATION, format!("{}.md", path.to_string()))
|
||||||
.finish());
|
.finish());
|
||||||
|
@ -241,6 +252,8 @@ async fn render(
|
||||||
None => None,
|
None => None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
context.insert("server_name", &data.server_name);
|
||||||
|
context.insert("path", &path.to_string());
|
||||||
|
|
||||||
Ok(HttpResponse::Ok().body(
|
Ok(HttpResponse::Ok().body(
|
||||||
data.tera
|
data.tera
|
||||||
|
|
BIN
templates/favicon.png
Normal file
BIN
templates/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
|
@ -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"
|
href="https://fonts.googleapis.com/css2?family=Merriweather:ital,wght@0,400;0,700;1,400;1,700&family=Montserrat&display=swap"
|
||||||
rel="stylesheet">
|
rel="stylesheet">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<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">
|
<link href="/static/main.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue