Hi!
(and thanks for the amazing static site generator <3)
Various platforms - like chat applications and social media - provide automatic link previews, when a link is shared. These previews / “unfurls” are based on metadata, see more information e.g. here in a Medium article by Slack developers. Both “native” html metadata tags and OpenGraph metadata are often parsed for by various services.
It is pretty easy - and common, i would guess - to add the title
and description
metadata in the front-matter of the markdown files. Those fields are well supported by Zola, and available for use as variables to access in the templates.
However, actually using those pieces of article metadata for the generated html page metadata requires quite a bit of boilerplate-writing in your template fields. See below for an example that populates both the generic meta tags and the OpenGraph ones:
<meta property="og:type" content="website" />
<meta property="og:site_name" content="example.com" />
{%if section.title%}
<title>{{ section.title }}</title>
<meta name="og:title" content="{{ section.title }}" />
{%endif%}
{%if page.title%}
<title>{{ page.title }}</title>
<meta name="og:title" content="{{ page.title }}" />
{%endif%}
{%if section.description%}
<meta name="description" content="{{ section.description }}" />
<meta name="og:description" content="{{ section.description }}" />
{%endif%}
{%if page.description%}
<meta name="description" content="{{ page.description }}" />
<meta name="og:description" content="{{ page.description }}" />
{%endif%}
Could it be possible to have some sort of shorthand for filling in all of these in Zola templating - or e.g. a configuration setting for automatically adding these in the generated page metadata, for each metadata field that has been provided in the page’s front-matter? Currently, if a user doesn’t manually add any of these in their template, none of the metadata gets into the generated html.
(Bonus round: how would you implement support for declaring the page’s intended main image as a url in the markdown frontmatter, for use in an og:image
tag - while conforming to the support for asset colocation in the directory structure?)