From fba44ba09d96accbff81185c97b8426919fa95d6 Mon Sep 17 00:00:00 2001 From: Folyd Date: Fri, 27 Jan 2023 11:32:24 +0800 Subject: [PATCH] Support specify canonical url for articles (#149) --- src/entity/article.rs | 4 ++++ templates/_meta.jinja | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/entity/article.rs b/src/entity/article.rs index 82d7a8c..9495887 100644 --- a/src/entity/article.rs +++ b/src/entity/article.rs @@ -57,6 +57,9 @@ pub struct Article { /// generate HTML file in this mode. #[serde(default)] pub publish: bool, + /// The canonical link of this article. + /// See issue: https://github.com/zineland/zine/issues/141 + pub canonical: Option, #[serde(default, skip_serializing)] pub i18n: HashMap, } @@ -191,6 +194,7 @@ impl Article { ); context.insert("page_type", "article"); context.insert("article", &self); + context.insert("canonical_url", &self.canonical); let zine_data = data::read(); let markdown_config = zine_data.get_markdown_config(); diff --git a/templates/_meta.jinja b/templates/_meta.jinja index b0e9b9d..a46b217 100644 --- a/templates/_meta.jinja +++ b/templates/_meta.jinja @@ -31,4 +31,11 @@ +{% endif -%} +{% if page_type and page_type == "article" -%} +{% if canonical_url -%} + +{% else -%} + +{% endif -%} {% endif -%} \ No newline at end of file