Skip to content

Commit

Permalink
Support specify canonical url for articles (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
Folyd authored Jan 27, 2023
1 parent 16012c3 commit fba44ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/entity/article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(default, skip_serializing)]
pub i18n: HashMap<String, Article>,
}
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions templates/_meta.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@
<meta name="twitter:card" content="summary_large_image">
<meta property="og:image" content="{{ image_url ~ image }}">
<meta name="twitter:image" content="{{ image_url ~ image }}">
{% endif -%}
{% if page_type and page_type == "article" -%}
{% if canonical_url -%}
<link rel="canonical" href="{{ canonical_url }}">
{% else -%}
<link rel="canonical" href="{{ site.url ~ '/' ~ meta.url }}">
{% endif -%}
{% endif -%}

0 comments on commit fba44ba

Please sign in to comment.