sphinxext-opengraph icon indicating copy to clipboard operation
sphinxext-opengraph copied to clipboard

Copy other metadata systematically

Open mrocklin opened this issue 2 years ago • 3 comments

So, in my site my pages have consistent metadata with fields like title. I'd love to have these automatically also populate the og:title field. Any suggestions on how this could be done?

mrocklin avatar Jan 06 '23 20:01 mrocklin

My pages today look like the following (with MyST)

---
title: How I Conduct an Interview
og:title: How I Conduct an Interview
date: 2023-01-06
...

mrocklin avatar Jan 06 '23 20:01 mrocklin

How are you injecting titles or other metadata into pages conditionally? The regular default for OpenGraph (being the first header on the page) for titles solves most cases, as the first header is usually identical to the title of the page.

Daltz333 avatar Jan 08 '23 20:01 Daltz333

I put the following in my template, mostly to help avoid duplication

{%- if meta is mapping and "title" in meta %}
<h1> {{ meta.get("title") }} </h1>
{%- endif %}

mrocklin avatar Jan 09 '23 00:01 mrocklin