Skip to content

Commit 0294d9a

Browse files
committed
Embed JSON-LD metadata in HTML documentation pages
Issue: RiverBench/RiverBench#148
1 parent 25e303a commit 0294d9a

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

hooks/embed_jsonld.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import logging, os
2+
import mkdocs.plugins
3+
from mkdocs.structure.pages import Page
4+
5+
6+
log = logging.getLogger('mkdocs')
7+
8+
9+
# Embeds a JSON-LD snippet into the head of a page
10+
# Issue: https://github.com/RiverBench/RiverBench/issues/148
11+
def on_post_page(html: str, page: Page, config) -> str:
12+
embed_path = 'docs/' + page.file.src_path.replace('.md', '_embed.jsonld')
13+
if os.path.exists(embed_path):
14+
log.info(f'Embedding {embed_path} into {page.file.src_path}')
15+
with open(embed_path) as f:
16+
embed = f.read()
17+
html = html.replace('</head>', f'<script type="application/ld+json">{embed}</script></head>')
18+
return html

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins:
1212

1313
hooks:
1414
- hooks/fix_title.py
15+
- hooks/embed_jsonld.py
1516

1617
markdown_extensions:
1718
- attr_list

0 commit comments

Comments
 (0)