Ben C 61cdb1b9f5
Update Documentation Site (#54)
* 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
2022-03-03 17:08:06 -08:00

43 lines
1.5 KiB
Python

from dataclasses import dataclass
from pathlib import Path
from jinja2 import Environment
from markdown import Markdown
@dataclass
class Page:
sort_priority: int
in_path: Path
out_path: Path
title: str
description: str | None
env: Environment
def __init__(self, path, environment, options):
self.in_path = path
self.env = environment
md = Markdown(**options)
with path.open() as file:
md.convert(file.read())
self.sort_priority = int(md.Meta.get('sort-priority', '20')[0])
self.title = md.Meta.get('title', (path.stem,))[0]
self.description = md.Meta.get('description', None)
outfile: Path
try:
outfile = Path("out/", path.relative_to(Path("content/pages/")).parent,
md.Meta['out-file'][0] + '.html')
except KeyError:
outfile = Path("out/", path.relative_to(Path("content/pages/"))).with_suffix('.html')
self.out_path = outfile
def render(self, **options):
template = self.env.get_template(str(self.in_path.relative_to(Path("content/")).as_posix()))
page_template = self.env.get_template("base/page_template.jinja2")
rendered_string = page_template.render(content=template.render(**options), **options)
self.out_path.parent.mkdir(mode=511, parents=True, exist_ok=True)
with self.out_path.open(mode='w+', encoding='utf-8') as file:
file.write(rendered_string)