mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
* Add Bootstrap Extension * Rename main.yml * Artifact Upload * Fix Bootstrap Reference Error * BootstrapTreeProcessor * getiterator removed * keys function * Style Images * Update docs_build.yml * Added Meta Files * Template Get * Fix Page Ref * Update BASE_URL * Sort Schemas * Add Sitemaps * Add favicons, open-graph, and setup guide * Update Setup.md * Update .gitignore * Update Setup.md * Use _blank on external links * Restructured Docs * Fix Links * Added XML Schemas * Name XML Schemas * Improved Best Practices * Add Logs For Static Files * Make docs build happen on PR * Responsive Footer * Started On Table OF Contents * Added Table Of Contents * Fix <code> bg colors * Remove unused CSS * Add canonical link * Fix OGP Image * Try ScrollSpy on TOC * Added ScrollSpy * Improve TOC Spacing * Custom Scroll Bars * Fix Formatting in ship_log.md
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
from markdown import Markdown
|
|
|
|
from lib.Content.AbstractTemplatedItem import AbstractTemplatedItem
|
|
from lib.BootstrapExtension import BootstrapExtension
|
|
|
|
|
|
class MDPage(AbstractTemplatedItem):
|
|
root_dir = Path("pages/")
|
|
extensions = ('md', 'markdown')
|
|
|
|
MARKDOWN_SETTINGS = {
|
|
'extensions': ['extra', 'toc', 'meta', BootstrapExtension()]
|
|
}
|
|
|
|
def load_metadata(self):
|
|
md = self.__get_md()
|
|
with self.in_path.open(mode='r', encoding='utf-8') as file:
|
|
md.convert(file.read())
|
|
|
|
self.title = md.Meta.get('title')[0]
|
|
self.description = md.Meta.get('description', [None])[0]
|
|
self.render_toc = md.Meta.get('toc', ['True'])[0].strip().lower() == "true"
|
|
if self.render_toc:
|
|
self.table_of_contents = md.toc_tokens
|
|
raw_priority = md.Meta.get('sort-priority')
|
|
if raw_priority is not None:
|
|
self.sort_priority = int(raw_priority[0])
|
|
out_name = md.Meta.get('out-file', None)
|
|
if out_name is not None:
|
|
self.out_path = self.out_path.with_stem(out_name[0])
|
|
super(MDPage, self).load_metadata()
|
|
|
|
def __get_md(self):
|
|
return Markdown(**self.MARKDOWN_SETTINGS)
|
|
|
|
def inner_render(self, template, **context):
|
|
rendered_markdown = super(MDPage, self).inner_render(template, **context)
|
|
md = self.__get_md()
|
|
return md.convert(rendered_markdown)
|
|
|