diff --git a/docs/content/base/base.jinja2 b/docs/content/base/base.jinja2 index 3a4ca8fe..46f05979 100644 --- a/docs/content/base/base.jinja2 +++ b/docs/content/base/base.jinja2 @@ -1,5 +1,4 @@ {% from 'base/macros.jinja2' import external_link, is_active_page, nav_item, defer_css with context %} - diff --git a/docs/content/pages/faq.jinja2 b/docs/content/pages/faq.jinja2 new file mode 100644 index 00000000..9a658def --- /dev/null +++ b/docs/content/pages/faq.jinja2 @@ -0,0 +1,26 @@ +{#~ Title:FAQ ~#} +{#~ Sort-Priority:95 ~#} + + +{% macro faq(id, q, a) %} +
+

+ +

+
+
+ {{ ("A: " + a)|simple_md|replace('p', 'p class="my-0 ms-2" ')|safe }} +
+
+
+{% endmacro %} + +

FAQ

+ +
+ {{ faq("jammer", "Will Jammer Be Added?", "Yes! Check **your front door**") }} + {{ faq("rails", "Will Rails Be Added?", "No") }} +
+ diff --git a/docs/content/static/styles/base.css b/docs/content/static/styles/base.css index 374bfbdd..24d6af98 100644 --- a/docs/content/static/styles/base.css +++ b/docs/content/static/styles/base.css @@ -20,3 +20,17 @@ pre > code { ::-webkit-scrollbar-thumb:hover { background: #555; } + +.accordion-button:not(.collapsed) { + color: #effff7; + background-color: #2b2b2b; +} + +.accordion-button:not(.collapsed)::after { + color: #effff7; + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e"); +} + +.accordion-item { + border: 1px solid rgba(0, 0, 0, 0.4); +} diff --git a/docs/content/static/styles/schema.css b/docs/content/static/styles/schema.css index ec4532ce..4d958a0b 100644 --- a/docs/content/static/styles/schema.css +++ b/docs/content/static/styles/schema.css @@ -14,20 +14,6 @@ } } -.accordion-button:not(.collapsed) { - color: #effff7; - background-color: #2b2b2b; -} - -.accordion-button:not(.collapsed)::after { - color: #effff7; - background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%23fff'%3e%3cpath fill-rule='evenodd' d='M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z'/%3e%3c/svg%3e"); -} - -.accordion-item { - border: 1px solid rgba(0, 0, 0, 0.4); -} - .bg-warning { color: #131313; } diff --git a/docs/generate.py b/docs/generate.py index df9a5a24..695ab116 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -4,6 +4,7 @@ from pathlib import Path from shutil import rmtree from jinja2 import Environment, select_autoescape, FileSystemLoader +from markdown import Markdown from lib.Content.CSSStaticItem import CSSStaticItem from lib.Content.HTMLPage import HTMLPage @@ -42,12 +43,16 @@ meta_files = [MinifiedMetaItem(Path('browserconfig.jinja2'), '.xml'), router = {} +filter_md = Markdown(extensions=['extra'], output_format='html5') + env.filters.update({ 'upper_first': lambda x: x[0].upper() + x[1:], 'static': lambda path: str(Path(OUT_DIR, path).as_posix()), 'route': lambda title: router.get(title.lower(), "#"), 'full_url': lambda relative: BASE_URL + (relative[1:] if relative[0] == "/" else relative), - 'gen_time': lambda x: GEN_TIME + 'gen_time': lambda x: GEN_TIME, + 'simple_md': lambda s: filter_md.convert(s), + 'inline_md': lambda s: filter_md.convert(s)[3:-4].replace("", "").replace("", "") }) MetaItem.initialize(env) diff --git a/docs/lib/Content/AbstractContentItem.py b/docs/lib/Content/AbstractContentItem.py deleted file mode 100644 index 53747d50..00000000 --- a/docs/lib/Content/AbstractContentItem.py +++ /dev/null @@ -1,58 +0,0 @@ -from abc import ABC -from pathlib import Path - -from htmlmin import minify -from jinja2 import Environment - - -class AbstractContentItem(ABC): - - output_ext: str = '.html' - env: Environment - in_path: Path - out_path: Path - root_dir: Path - - def __init__(self, in_path: Path, ext: str = None): - self.env = None - if ext is not None: - self.output_ext = ext - self.in_path = in_path - self.out_path = Path('out/', in_path.name).with_suffix(self.output_ext) - - @classmethod - def initialize(cls, env: Environment) -> list: - raise NotImplementedError() - - def render(self, **context) -> str: - raise NotImplementedError() - - def _save(self, rendered: str): - 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) - - def generate(self, **context) -> None: - print("Building:", self.in_path, "->", self.out_path) - self._save(self.render(**context)) - - def add_route(self, routes, out_dir): - pass - - -class MinifyMixin(AbstractContentItem, ABC): - - MINIFY_SETTINGS = { - 'remove_empty_space': True, - 'keep_pre': True, - 'remove_optional_attribute_quotes': False - } - - def _save(self, rendered: str): - rendered = minify(rendered, **self.MINIFY_SETTINGS) - super(MinifyMixin, self)._save(rendered) - - - - - diff --git a/docs/lib/Content/AbstractTemplatedItem.py b/docs/lib/Content/AbstractTemplatedItem.py index 8350f53e..3edce396 100644 --- a/docs/lib/Content/AbstractTemplatedItem.py +++ b/docs/lib/Content/AbstractTemplatedItem.py @@ -14,14 +14,16 @@ class AbstractTemplatedItem(MinifyMixin, AbstractItem, ABC): sort_priority: int = None render_toc: bool = False table_of_contents: dict = {} + meta: dict = { + 'title': None, + 'description': None, + 'sort_priority': 10 + } def load_metadata(self): - if self.title is None: - self.title = self.in_path.stem - if self.description is None: - self.description = None - if self.sort_priority is None: - self.sort_priority = 10 + self.title = self.meta['title'] if self.meta['title'] is not None else self.in_path.stem + self.description = self.meta['description'] + self.sort_priority = int(self.meta['sort_priority']) @classmethod def initialize(cls, env: Environment): diff --git a/docs/lib/Content/HTMLPage.py b/docs/lib/Content/HTMLPage.py index 0aa43f85..5e229e79 100644 --- a/docs/lib/Content/HTMLPage.py +++ b/docs/lib/Content/HTMLPage.py @@ -1,8 +1,19 @@ +import re from pathlib import Path from lib.Content.AbstractTemplatedItem import AbstractTemplatedItem class HTMLPage(AbstractTemplatedItem): + + def load_metadata(self): + with self.in_path.open(mode='r', encoding='utf-8') as file: + content = file.read() + for match in re.findall(r"{#~(.*?)~#}", content, re.MULTILINE): + seperated = match.strip().split(':') + print(match.strip()) + self.meta[seperated[0].lower().replace('-', '_')] = seperated[1] + super(HTMLPage, self).load_metadata() + root_dir = Path("pages/") extensions = ('html', 'jinja2', 'jinja') diff --git a/docs/lib/Content/JSONSchema.py b/docs/lib/Content/JSONSchema.py index 414fed62..679436b7 100644 --- a/docs/lib/Content/JSONSchema.py +++ b/docs/lib/Content/JSONSchema.py @@ -29,10 +29,10 @@ class JSONSchema(AbstractSchemaItem): extensions = ('json',) def load_metadata(self): - self.sort_priority = 10 + self.meta['sort_priority'] = 10 with self.in_path.open(mode='r', encoding='utf-8') as file: - self.title = json.load(file).get('title', self.in_path.stem) - self.description = "Schema for a " + self.title + " in New Horizons" + self.meta['title'] = json.load(file).get('title', self.in_path.stem) + self.meta['description'] = "Schema for a " + self.meta['title'] + " in New Horizons" super(JSONSchema, self).load_metadata() def render(self, **context): diff --git a/docs/lib/Content/MDPage.py b/docs/lib/Content/MDPage.py index 56e42c21..c76807a3 100644 --- a/docs/lib/Content/MDPage.py +++ b/docs/lib/Content/MDPage.py @@ -11,7 +11,8 @@ class MDPage(AbstractTemplatedItem): extensions = ('md', 'markdown') MARKDOWN_SETTINGS = { - 'extensions': ['extra', 'toc', 'meta', BootstrapExtension()] + 'extensions': ['extra', 'toc', 'meta', BootstrapExtension()], + 'output-format': 'html5' } def load_metadata(self): @@ -19,14 +20,14 @@ class MDPage(AbstractTemplatedItem): 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.meta['title'] = md.Meta.get('title')[0] + self.meta['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]) + self.meta['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]) diff --git a/docs/lib/Content/XMLSchema.py b/docs/lib/Content/XMLSchema.py index 63161c8b..69df1dc0 100644 --- a/docs/lib/Content/XMLSchema.py +++ b/docs/lib/Content/XMLSchema.py @@ -70,7 +70,7 @@ class XMLSchema(AbstractSchemaItem): file.readline() line = file.readline() if len(line.strip()) != 0 and '' in line: - self.title = line.replace('', '').strip() + self.meta['title'] = line.replace('', '').strip() super(XMLSchema, self).load_metadata() def render(self, **context):