File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ plugins:
1212
1313hooks :
1414 - hooks/fix_title.py
15+ - hooks/embed_jsonld.py
1516
1617markdown_extensions :
1718 - attr_list
You can’t perform that action at this time.
0 commit comments