From ad838b04664f9ab671a23fdfc7f5e32e05da5bfe Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 20:18:13 -0800 Subject: [PATCH 1/9] Update main.yml --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 86c3c9cc..530549e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,9 +26,9 @@ jobs: - name: Copy Schemas run: | mkdir schemas/ - cp NewHorizons/schema.json schemas/ - cp NewHorizons/star_system_schema.json schemas/ - cp NewHorizons/translation_schema.json schemas/ + cp NewHorizons/schema.json content/schemas/ + cp NewHorizons/star_system_schema.json content/schemas/ + cp NewHorizons/translation_schema.json content/schemas/ - name: Create Output Dir run: | From 290a7d54c967ac64f6a9ce52a905d22e3581381f Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 23:24:17 -0500 Subject: [PATCH 2/9] Redid Docs Generation --- NewHorizons/schema.json | 8 +- NewHorizons/star_system_schema.json | 1 + docs/Pipfile | 1 + docs/Pipfile.lock | 10 +- .../base}/badge_type.jinja2 | 0 .../templates => content/base}/base.jinja2 | 30 ++--- docs/content/base/breadcrumbs.jinja2 | 13 +++ .../templates => content/base}/content.jinja2 | 2 +- .../base}/macro_restriction.jinja2 | 0 docs/content/base/macros.jinja2 | 11 ++ docs/content/base/page_template.jinja2 | 16 +++ .../base}/schema_base.jinja2 | 0 .../base}/schema_doc.min.js | 0 .../base}/section_array.jinja2 | 28 ++--- .../section_conditional_subschema.jinja2 | 2 +- .../base}/section_description.jinja2 | 0 .../base}/section_examples.jinja2 | 18 +-- .../base}/section_not.jinja2 | 0 .../base}/section_properties.jinja2 | 2 +- ...on_undocumented_required_properties.jinja2 | 11 ++ .../base}/tabbed_section.jinja2 | 22 ++-- docs/content/pages/home.md | 21 ++++ .../static/images/home/create_planets.png | Bin .../static/images/home/home_logo.png | Bin .../static/images/home/mod_manager_dots.png | Bin docs/{ => content}/static/robots.txt | 0 .../templates/breadcrumbs.jinja2 | 17 --- docs/docs_templates/templates/home.jinja2 | 46 -------- ...on_undocumented_required_properties.jinja2 | 11 -- docs/generate.py | 106 +++++++----------- docs/lib/Page.py | 40 +++++++ docs/lib/Schema.py | 42 +++++++ docs/{docs_templates => lib}/__init__.py | 0 33 files changed, 262 insertions(+), 196 deletions(-) rename docs/{docs_templates/templates => content/base}/badge_type.jinja2 (100%) rename docs/{docs_templates/templates => content/base}/base.jinja2 (64%) create mode 100644 docs/content/base/breadcrumbs.jinja2 rename docs/{docs_templates/templates => content/base}/content.jinja2 (97%) rename docs/{docs_templates/templates => content/base}/macro_restriction.jinja2 (100%) create mode 100644 docs/content/base/macros.jinja2 create mode 100644 docs/content/base/page_template.jinja2 rename docs/{docs_templates/templates => content/base}/schema_base.jinja2 (100%) rename docs/{docs_templates/templates => content/base}/schema_doc.min.js (100%) rename docs/{docs_templates/templates => content/base}/section_array.jinja2 (67%) rename docs/{docs_templates/templates => content/base}/section_conditional_subschema.jinja2 (97%) rename docs/{docs_templates/templates => content/base}/section_description.jinja2 (100%) rename docs/{docs_templates/templates => content/base}/section_examples.jinja2 (60%) rename docs/{docs_templates/templates => content/base}/section_not.jinja2 (100%) rename docs/{docs_templates/templates => content/base}/section_properties.jinja2 (97%) create mode 100644 docs/content/base/section_undocumented_required_properties.jinja2 rename docs/{docs_templates/templates => content/base}/tabbed_section.jinja2 (54%) create mode 100644 docs/content/pages/home.md rename docs/{ => content}/static/images/home/create_planets.png (100%) rename docs/{ => content}/static/images/home/home_logo.png (100%) rename docs/{ => content}/static/images/home/mod_manager_dots.png (100%) rename docs/{ => content}/static/robots.txt (100%) delete mode 100644 docs/docs_templates/templates/breadcrumbs.jinja2 delete mode 100644 docs/docs_templates/templates/home.jinja2 delete mode 100644 docs/docs_templates/templates/section_undocumented_required_properties.jinja2 create mode 100644 docs/lib/Page.py create mode 100644 docs/lib/Schema.py rename docs/{docs_templates => lib}/__init__.py (100%) diff --git a/NewHorizons/schema.json b/NewHorizons/schema.json index e12179d6..c14361aa 100644 --- a/NewHorizons/schema.json +++ b/NewHorizons/schema.json @@ -70,8 +70,8 @@ "angle": { "type": "number", "default": 0, - "min": 0, - "max": 360 + "minimum": 0, + "maximum": 360 }, "curve": { "type": "array", @@ -104,7 +104,7 @@ } } }, - "title": "Planet", + "title": "Body", "description": "A planet or body to generate", "type": "object", "required": [ @@ -627,7 +627,7 @@ "shipSpawnPoint": { "$ref": "#/$defs/vector3" }, - "starWithSuit": { + "startWithSuit": { "type": "boolean", "default": false } diff --git a/NewHorizons/star_system_schema.json b/NewHorizons/star_system_schema.json index cf7f702c..52e6e732 100644 --- a/NewHorizons/star_system_schema.json +++ b/NewHorizons/star_system_schema.json @@ -1,6 +1,7 @@ { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", + "title": "Star System", "description": "Configuration for a specific star system", "properties": { "canEnterViaWarpDrive": { diff --git a/docs/Pipfile b/docs/Pipfile index d3679cdd..db301759 100644 --- a/docs/Pipfile +++ b/docs/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] jinja2 = "*" json-schema-for-humans = "*" +markdown = "*" [dev-packages] diff --git a/docs/Pipfile.lock b/docs/Pipfile.lock index 5f5f7055..5669f72f 100644 --- a/docs/Pipfile.lock +++ b/docs/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b4acdc18f2bf25fdf7a2448229884300b7e3ec47731a49ad482b21d32c627370" + "sha256": "600dddfc39d9e9ca825fd1870bfa2094e3124c7d1759be513936f1d0d842cd5c" }, "pipfile-spec": 6, "requires": { @@ -85,6 +85,14 @@ "index": "pypi", "version": "==0.40" }, + "markdown": { + "hashes": [ + "sha256:76df8ae32294ec39dcf89340382882dfa12975f87f45c3ed1ecdb1e8cefc7006", + "sha256:9923332318f843411e9932237530df53162e29dc7a4e2b91e35764583c46c9a3" + ], + "index": "pypi", + "version": "==3.3.6" + }, "markdown2": { "hashes": [ "sha256:8f4ac8d9a124ab408c67361090ed512deda746c04362c36c2ec16190c720c2b0", diff --git a/docs/docs_templates/templates/badge_type.jinja2 b/docs/content/base/badge_type.jinja2 similarity index 100% rename from docs/docs_templates/templates/badge_type.jinja2 rename to docs/content/base/badge_type.jinja2 diff --git a/docs/docs_templates/templates/base.jinja2 b/docs/content/base/base.jinja2 similarity index 64% rename from docs/docs_templates/templates/base.jinja2 rename to docs/content/base/base.jinja2 index 45cf9546..a0866c28 100644 --- a/docs/docs_templates/templates/base.jinja2 +++ b/docs/content/base/base.jinja2 @@ -1,3 +1,9 @@ +{% if dumb %} + {% from 'macros.jinja2' import external_link, is_active_page, nav_item with context %} +{% else %} + {% from 'base/macros.jinja2' import external_link, is_active_page, nav_item with context %} +{% endif %} + @@ -18,7 +24,7 @@
-
+
{% block content %} {% endblock %}
diff --git a/docs/content/base/breadcrumbs.jinja2 b/docs/content/base/breadcrumbs.jinja2 new file mode 100644 index 00000000..c3c8a92d --- /dev/null +++ b/docs/content/base/breadcrumbs.jinja2 @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/docs/docs_templates/templates/content.jinja2 b/docs/content/base/content.jinja2 similarity index 97% rename from docs/docs_templates/templates/content.jinja2 rename to docs/content/base/content.jinja2 index 8073062d..99dc9385 100644 --- a/docs/docs_templates/templates/content.jinja2 +++ b/docs/content/base/content.jinja2 @@ -52,7 +52,7 @@ {{ content(schema.kw_any_of.array_items[0]) }} {% else %} {% if schema.explicit_no_additional_properties %} - {{ " " }}No Additional Properties + {{ " " }}No Additional Properties {% endif %} {# Combining: allOf, anyOf, oneOf, not #} diff --git a/docs/docs_templates/templates/macro_restriction.jinja2 b/docs/content/base/macro_restriction.jinja2 similarity index 100% rename from docs/docs_templates/templates/macro_restriction.jinja2 rename to docs/content/base/macro_restriction.jinja2 diff --git a/docs/content/base/macros.jinja2 b/docs/content/base/macros.jinja2 new file mode 100644 index 00000000..c6aa2e0d --- /dev/null +++ b/docs/content/base/macros.jinja2 @@ -0,0 +1,11 @@ +{% macro external_link(display_name, link, class) %} + {{ display_name|safe }} +{% endmacro %} + +{% macro is_active_page(title) %}{% if title == page.title %}active{% endif %}{% endmacro %} + +{% macro nav_item(title, href) %} + +{% endmacro %} diff --git a/docs/content/base/page_template.jinja2 b/docs/content/base/page_template.jinja2 new file mode 100644 index 00000000..16003242 --- /dev/null +++ b/docs/content/base/page_template.jinja2 @@ -0,0 +1,16 @@ +{% extends "base/base.jinja2" %} + +{% block resources %} + + + +{% endblock %} + +{% block content %} +
+
+ {{ content|markdown }} +
+
+{% endblock %} diff --git a/docs/docs_templates/templates/schema_base.jinja2 b/docs/content/base/schema_base.jinja2 similarity index 100% rename from docs/docs_templates/templates/schema_base.jinja2 rename to docs/content/base/schema_base.jinja2 diff --git a/docs/docs_templates/templates/schema_doc.min.js b/docs/content/base/schema_doc.min.js similarity index 100% rename from docs/docs_templates/templates/schema_doc.min.js rename to docs/content/base/schema_doc.min.js diff --git a/docs/docs_templates/templates/section_array.jinja2 b/docs/content/base/section_array.jinja2 similarity index 67% rename from docs/docs_templates/templates/section_array.jinja2 rename to docs/content/base/section_array.jinja2 index a676f0d9..ecaa218f 100644 --- a/docs/docs_templates/templates/section_array.jinja2 +++ b/docs/content/base/section_array.jinja2 @@ -1,21 +1,21 @@ -{%- if schema.kw_min_items -%} - {{ restriction("Must contain a minimum of " ~ schema.kw_min_items.literal ~ " items", "min-items", schema.kw_min_items.html_id) }} -{%- endif -%} -{%- if schema.kw_max_items -%} - {{ restriction("Must contain a maximum of " ~ schema.kw_max_items.literal ~ " items", "max-items", schema.kw_max_items.html_id) }} -{%- endif -%} -{%- if schema.kw_unique_items and schema.kw_unique_items.literal == True -%} +{% if schema.kw_min_items %} + {{ restriction("Must contain a minimum of " ~ schema.kw_min_items.literal ~ " Items", "min-items", schema.kw_min_items.html_id) }} +{% endif %} +{% if schema.kw_max_items %} + {{ restriction("Must contain a maximum of " ~ schema.kw_max_items.literal ~ " Items", "max-items", schema.kw_max_items.html_id) }} +{% endif %} +{% if schema.kw_unique_items and schema.kw_unique_items.literal == True %} {{ restriction("All items must be unique", "unique-items", schema.kw_unique_items.html_id) }} -{%- endif -%} -{%- if schema.array_items_def -%} +{% endif %} +{% if schema.array_items_def %}

Each item of this array must be:

{{ content(schema.array_items_def) }}
-{%- endif -%} -{%- if schema.tuple_validation_items -%} +{% endif %} +{% if schema.tuple_validation_items %}

Tuple Validation

{% for item in schema.tuple_validation_items %}
Item at {{ loop.index }} must be:
@@ -25,12 +25,12 @@ {% endfor %} -{%- endif -%} -{%- if schema.kw_contains and schema.kw_contains.literal != {} -%} +{% endif %} +{% if schema.kw_contains and schema.kw_contains.literal != {} %}

At least one of the items must be:

{{ content(schema.kw_contains) }}
-{%- endif -%} \ No newline at end of file +{% endif %} \ No newline at end of file diff --git a/docs/docs_templates/templates/section_conditional_subschema.jinja2 b/docs/content/base/section_conditional_subschema.jinja2 similarity index 97% rename from docs/docs_templates/templates/section_conditional_subschema.jinja2 rename to docs/content/base/section_conditional_subschema.jinja2 index e543669d..973f8cfa 100644 --- a/docs/docs_templates/templates/section_conditional_subschema.jinja2 +++ b/docs/content/base/section_conditional_subschema.jinja2 @@ -1,5 +1,5 @@

- +

If the conditions in the "If" tab are respected, then the conditions in the "Then" tab should be respected. Otherwise, the conditions in the "Else" tab should be respected.

diff --git a/docs/docs_templates/templates/section_description.jinja2 b/docs/content/base/section_description.jinja2 similarity index 100% rename from docs/docs_templates/templates/section_description.jinja2 rename to docs/content/base/section_description.jinja2 diff --git a/docs/docs_templates/templates/section_examples.jinja2 b/docs/content/base/section_examples.jinja2 similarity index 60% rename from docs/docs_templates/templates/section_examples.jinja2 rename to docs/content/base/section_examples.jinja2 index 51675917..ffa40145 100644 --- a/docs/docs_templates/templates/section_examples.jinja2 +++ b/docs/content/base/section_examples.jinja2 @@ -2,17 +2,17 @@
Example{% if examples|length > 1 %}s{% endif %}:

-{%- for example in examples -%} - {%- set example_id = schema.html_id ~ "_ex" ~ loop.index -%} - {%- set example_is_long = example is not description_short -%} - {%- if example_is_long -%} +{% for example in examples %} + {% set example_id = schema.html_id ~ "_ex" ~ loop.index %} + {% set example_is_long = example is not description_short %} + {% if example_is_long %} - {%- endif -%} + {% endif %}
- {%- if not examples_as_yaml -%} + {% if not examples_as_yaml %} {{ example | highlight_json_example }} - {%- else -%} + {% else %} {{ example | highlight_yaml_example }} - {%- endif -%} + {% endif %}
-{%- endfor -%} +{% endfor %} diff --git a/docs/docs_templates/templates/section_not.jinja2 b/docs/content/base/section_not.jinja2 similarity index 100% rename from docs/docs_templates/templates/section_not.jinja2 rename to docs/content/base/section_not.jinja2 diff --git a/docs/docs_templates/templates/section_properties.jinja2 b/docs/content/base/section_properties.jinja2 similarity index 97% rename from docs/docs_templates/templates/section_properties.jinja2 rename to docs/content/base/section_properties.jinja2 index 268ad902..c9c8121f 100644 --- a/docs/docs_templates/templates/section_properties.jinja2 +++ b/docs/content/base/section_properties.jinja2 @@ -13,7 +13,7 @@ {% if sub_property.is_additional_properties %} {% endif %} - {{ sub_property.property_display_name | lowerfirst | escape }} + {{ sub_property.property_display_name | upper_first | escape }} {% if sub_property.is_additional_properties %} {% endif %} diff --git a/docs/content/base/section_undocumented_required_properties.jinja2 b/docs/content/base/section_undocumented_required_properties.jinja2 new file mode 100644 index 00000000..7a2bc74f --- /dev/null +++ b/docs/content/base/section_undocumented_required_properties.jinja2 @@ -0,0 +1,11 @@ +{% set undocumented_required_properties = schema | get_undocumented_required_properties %} +{% if undocumented_required_properties %} +
+

The following properties are required:

+
    + {% for required_property in undocumented_required_properties %} +
  • {{ required_property }}
  • + {% endfor %} +
+
+{% endif %} \ No newline at end of file diff --git a/docs/docs_templates/templates/tabbed_section.jinja2 b/docs/content/base/tabbed_section.jinja2 similarity index 54% rename from docs/docs_templates/templates/tabbed_section.jinja2 rename to docs/content/base/tabbed_section.jinja2 index 9cecf4c1..c4949ef4 100644 --- a/docs/docs_templates/templates/tabbed_section.jinja2 +++ b/docs/content/base/tabbed_section.jinja2 @@ -1,25 +1,25 @@

- +

-{%- set tab_label = "Option" -%} -{%- if operator == "allOf" -%} - {%- set tab_label = "Requirement" -%} -{%- endif -%} +{% set tab_label = "Option" %} +{% if operator == "allOf" %} + {% set tab_label = "Requirement" %} +{% endif %}
- {%- for node in current_node.array_items -%} -
{{ content(node) }}
- {%- endfor -%} + {% endfor %}
\ No newline at end of file diff --git a/docs/content/pages/home.md b/docs/content/pages/home.md new file mode 100644 index 00000000..1c617176 --- /dev/null +++ b/docs/content/pages/home.md @@ -0,0 +1,21 @@ +Title: Home +Out-File: index +Sort-Priority: 100 + +![New Horizons Logo]({{ 'images/home/home_logo.png'|static }}) + +# Welcome! + +This is the official documentation for [New Horizons](https://github.com/xen-42/outer-wilds-new-horizons) + +## Getting Started + +There is a template [here](https://github.com/xen-42/ow-new-horizons-config-template) if you want to release your own planet mod using configs. You can learn how the configs work by picking apart the [Real Solar System](https://github.com/xen-42/outer-wilds-real-solar-system) mod or the [New Horizons Examples](https://github.com/xen-42/ow-new-horizons-examples) mod. + +Planets are created using a JSON file format structure, and placed in a folder called planets (or in any subdirectory of it) in the location where New Horizons is installed (by default this folder doesn't exist, you have to create it within the xen.NewHorizons directory). + +To locate this directory, click the "⋮" symbol next to "New Horizons" in the Outer Wilds Mod Manager and then click "show in explorer" in the pop-up. + +![Click the three dots in the mod manager]({{ 'images/home/mod_manager_dots.png'|static }}) + +![Create a new folder named "planets"]({{ 'images/home/create_planets.png'|static }}) diff --git a/docs/static/images/home/create_planets.png b/docs/content/static/images/home/create_planets.png similarity index 100% rename from docs/static/images/home/create_planets.png rename to docs/content/static/images/home/create_planets.png diff --git a/docs/static/images/home/home_logo.png b/docs/content/static/images/home/home_logo.png similarity index 100% rename from docs/static/images/home/home_logo.png rename to docs/content/static/images/home/home_logo.png diff --git a/docs/static/images/home/mod_manager_dots.png b/docs/content/static/images/home/mod_manager_dots.png similarity index 100% rename from docs/static/images/home/mod_manager_dots.png rename to docs/content/static/images/home/mod_manager_dots.png diff --git a/docs/static/robots.txt b/docs/content/static/robots.txt similarity index 100% rename from docs/static/robots.txt rename to docs/content/static/robots.txt diff --git a/docs/docs_templates/templates/breadcrumbs.jinja2 b/docs/docs_templates/templates/breadcrumbs.jinja2 deleted file mode 100644 index 1f3e65e9..00000000 --- a/docs/docs_templates/templates/breadcrumbs.jinja2 +++ /dev/null @@ -1,17 +0,0 @@ - \ No newline at end of file diff --git a/docs/docs_templates/templates/home.jinja2 b/docs/docs_templates/templates/home.jinja2 deleted file mode 100644 index c9ee2282..00000000 --- a/docs/docs_templates/templates/home.jinja2 +++ /dev/null @@ -1,46 +0,0 @@ -{% extends "base.jinja2" %} - -{% block content %} -
-
- New Horizons Logo -
-
-
-
-

Welcome!

-
-
-
-
-

This is the official documentation for New Horizons

-
-
-
-
-

Getting Started

-
-
-
-
-

There is a template here if you want to release your own planet mod using configs. You can learn how the configs work by picking apart the Real Solar System mod or the New Horizons Examples mod.

-

Planets are created using a JSON file format structure, and placed in a folder called planets (or in any sub-directory of it) in the location where New Horizons is installed (by default this folder doesn't exist, you have to create it within the xen.NewHorizons directory).

-

To locate this directory, click the "⋮" symbol next to "New Horizons" in the Outer Wilds Mod Manager and then click "show in explorer" in the pop-up.

-
-
-
-
-
- Click the three dots in the mod manager -
Click the ⋮
-
-
-
-
- Create a new folder named "planets" -
Create a new folder named "planets"
-
-
-
-{% endblock %} - diff --git a/docs/docs_templates/templates/section_undocumented_required_properties.jinja2 b/docs/docs_templates/templates/section_undocumented_required_properties.jinja2 deleted file mode 100644 index 7e7ceaeb..00000000 --- a/docs/docs_templates/templates/section_undocumented_required_properties.jinja2 +++ /dev/null @@ -1,11 +0,0 @@ -{%- set undocumented_required_properties = schema | get_undocumented_required_properties -%} -{%- if undocumented_required_properties-%} -
-

The following properties are required:

-
    - {%- for required_property in undocumented_required_properties -%} -
  • {{ required_property }}
  • - {%- endfor -%} -
-
-{%- endif -%} \ No newline at end of file diff --git a/docs/generate.py b/docs/generate.py index fce37d29..123cfd45 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -1,88 +1,62 @@ import os -from dataclasses import dataclass from pathlib import Path -from shutil import copytree, rmtree -from jinja2 import Environment, PackageLoader, select_autoescape -from json_schema_for_humans.schema.schema_importer import get_schemas_to_render -from json_schema_for_humans.generate import generate_from_filename, GenerationConfiguration, generate_schemas_doc, \ - copy_additional_files_to_target -from json_schema_for_humans.template_renderer import TemplateRenderer, _minify +from jinja2 import Environment, select_autoescape, FileSystemLoader +from markupsafe import Markup +from json_schema_for_humans.generate import GenerationConfiguration +from markdown import Markdown + +from lib.Schema import Schema +from lib.Page import Page + +OUT_DIR = os.getenv("OUT_DIR", "/") env = Environment( - loader=PackageLoader('docs_templates', 'templates'), + loader=FileSystemLoader("content"), autoescape=select_autoescape(['jinja2']) ) -env.filters["lowerfirst"] = lambda x: x[0].lower() + x[1:] +markdown_settings = { + 'extensions': ['extra', 'meta'] +} -home = env.get_template("base.jinja2") +schema_settings = GenerationConfiguration(custom_template_path="content/base/schema_base.jinja2") +schema_settings.link_to_reused_ref = False +md = Markdown(**markdown_settings) -@dataclass -class Page: - in_name: str - out_name: str - title: str +env.filters["upper_first"] = lambda x: x[0].upper() + x[1:] +env.filters["markdown"] = lambda text: Markup(md.convert(text)) +env.filters["static"] = lambda path: OUT_DIR + "/" + path - def render(self, **options): - template = env.get_template(self.in_name + ".jinja2") - options.update({'page': self}) - rendered_string = template.render(**options) - with open("out/" + self.out_name + ".html", 'w+', encoding="utf-8") as file: - file.write(rendered_string) +pages_paths = Path("content/pages").glob("**/*.md") +schemas_paths = Path("content/schemas").glob("**/*.json") +router = {} -config = GenerationConfiguration(custom_template_path="docs_templates/templates/schema_base.jinja2") -config.link_to_reused_ref = False +env.filters['route'] = lambda title: router.get(title.lower(), "#") +pages = [] +schemas = [] -@dataclass -class Schema(Page): +for page_path in pages_paths: + new_page = Page(page_path, env, markdown_settings) + router[new_page.title.lower()] = OUT_DIR + str(new_page.out_path.relative_to('out/')) + pages.append(new_page) - def render(self, **options): - schemas = get_schemas_to_render("schemas/" + self.in_name + ".json", Path("out/schemas/" + self.out_name + ".html"), ".html") - template_renderer = TemplateRenderer(config) - template_renderer.render = lambda inter: template_override(template_renderer, inter, self) - generate_schemas_doc(schemas, template_renderer) - copy_additional_files_to_target(schemas, config) +for schema_path in schemas_paths: + new_schema = Schema(schema_path, env, schema_settings) + router[new_schema.title.lower()] = OUT_DIR + "schemas/" + str(new_schema.out_path.relative_to("out/schemas/")) + schemas.append(new_schema) +router['home'] = OUT_DIR -pages = ( - Page(in_name="home", out_name="index", title="Home"), - Schema(in_name="schema", out_name="body_schema", title="Body"), - Schema(in_name="star_system_schema", out_name="star_system_schema", title="Star System"), - Schema(in_name="translation_schema", out_name="translation_schema", title="Translation") -) - -schemas = [s for s in pages if s.__class__.__name__ == "Schema"] - - -def template_override(template, intermediate_schema, inter_page): - template.template.environment.filters["lowerfirst"] = env.filters["lowerfirst"] - rendered = template.template.render(schema=intermediate_schema, config=config, schemas=schemas, page=inter_page, title=inter_page.title + " Schema") - - if template.config.minify: - rendered = _minify(rendered, template.config.template_is_markdown, template.config.template_is_html) - - return rendered - - -print("Initializing") - - -if os.path.exists("out"): - rmtree("out") - -print("Copying Static") - -copytree("static", "out") - -os.makedirs("out/schemas") - -print("Rendering Pages") +pages.sort(key=lambda p: p.sort_priority, reverse=True) for page in pages: - page.render(schemas=schemas) + print(page.in_path, "->", page.out_path) + page.render(page=page, pages=pages, schemas=schemas) -print("Done") +for schema in schemas: + print(schema.in_path, "->", schema.out_path) + schema.render(page=schema, pages=pages, schemas=schemas) diff --git a/docs/lib/Page.py b/docs/lib/Page.py new file mode 100644 index 00000000..bdb79615 --- /dev/null +++ b/docs/lib/Page.py @@ -0,0 +1,40 @@ +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 + 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', '0')[0]) + self.title = md.Meta.get('title', (path.stem,))[0] + 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) diff --git a/docs/lib/Schema.py b/docs/lib/Schema.py new file mode 100644 index 00000000..7edbf676 --- /dev/null +++ b/docs/lib/Schema.py @@ -0,0 +1,42 @@ +import json +from dataclasses import dataclass +from pathlib import Path + +from json_schema_for_humans.generate import generate_schemas_doc, copy_additional_files_to_target +from json_schema_for_humans.schema.schema_importer import get_schemas_to_render +from json_schema_for_humans.template_renderer import TemplateRenderer, _minify +from json_schema_for_humans.generation_configuration import GenerationConfiguration + +# noinspection PyUnresolvedReferences +from lib.Page import Page + + +@dataclass +class Schema(Page): + + config: GenerationConfiguration + + def __init__(self, path, env, options): + self.sort_priority = 0 + self.in_path = path + self.config = options + self.env = env + with path.open() as file: + self.title = json.load(file).get('title', path.stem) + self.out_path = Path('out/schemas/', self.in_path.relative_to(Path("content/schemas/")).with_name(self.title.replace(" ", "_").lower()).with_suffix(".html")) + + def render(self, **options): + schemas = get_schemas_to_render(self.in_path, self.out_path, ".html") + template_renderer = TemplateRenderer(self.config) + template_renderer.render = lambda inter: self.template_override(template_renderer, inter, **options) + generate_schemas_doc(schemas, template_renderer) + copy_additional_files_to_target(schemas, self.config) + + def template_override(self, template, intermediate_schema, **options): + template.template.environment.filters.update(self.env.filters) + rendered = template.template.render(schema=intermediate_schema, dumb=True, config=self.config, title=self.title + " Schema", **options) + + if template.config.minify: + rendered = _minify(rendered, template.config.template_is_markdown, template.config.template_is_html) + + return rendered diff --git a/docs/docs_templates/__init__.py b/docs/lib/__init__.py similarity index 100% rename from docs/docs_templates/__init__.py rename to docs/lib/__init__.py From 8350cb3dcf847f4531605a09ba6b46f7cda1dbe6 Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 20:26:51 -0800 Subject: [PATCH 3/9] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 530549e3..af06cdbb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,7 @@ jobs: - name: Copy Schemas run: | - mkdir schemas/ + mkdir content/schemas/ cp NewHorizons/schema.json content/schemas/ cp NewHorizons/star_system_schema.json content/schemas/ cp NewHorizons/translation_schema.json content/schemas/ From d34313ac332529481ca8056589d733ddb8f76086 Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 23:32:13 -0500 Subject: [PATCH 4/9] Fix Image Paths In Docs --- docs/generate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/generate.py b/docs/generate.py index 123cfd45..342cb29b 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -27,7 +27,7 @@ md = Markdown(**markdown_settings) env.filters["upper_first"] = lambda x: x[0].upper() + x[1:] env.filters["markdown"] = lambda text: Markup(md.convert(text)) -env.filters["static"] = lambda path: OUT_DIR + "/" + path +env.filters["static"] = lambda path: str(Path(OUT_DIR, path).as_posix()) pages_paths = Path("content/pages").glob("**/*.md") schemas_paths = Path("content/schemas").glob("**/*.json") From 046f1eb14924838968b97d578af3e86009a0aa23 Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 23:41:15 -0500 Subject: [PATCH 5/9] Fixed copying static files in docs --- docs/generate.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/generate.py b/docs/generate.py index 342cb29b..a397bb6d 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -1,5 +1,6 @@ import os from pathlib import Path +from shutil import copytree, rmtree from jinja2 import Environment, select_autoescape, FileSystemLoader from markupsafe import Markup @@ -11,6 +12,11 @@ from lib.Page import Page OUT_DIR = os.getenv("OUT_DIR", "/") +if Path("out/").exists(): + rmtree("out/", ignore_errors=True) + +copytree("content/static", "out") + env = Environment( loader=FileSystemLoader("content"), autoescape=select_autoescape(['jinja2']) From 47f622d58c0b8593b46a1025a496e96eda1ef1b7 Mon Sep 17 00:00:00 2001 From: Ben C Date: Wed, 2 Mar 2022 23:45:40 -0500 Subject: [PATCH 6/9] Fixed copying static files in docs --- docs/generate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generate.py b/docs/generate.py index a397bb6d..95b569a2 100644 --- a/docs/generate.py +++ b/docs/generate.py @@ -16,6 +16,7 @@ if Path("out/").exists(): rmtree("out/", ignore_errors=True) copytree("content/static", "out") +os.makedirs("out/schemas", exist_ok=True) env = Environment( loader=FileSystemLoader("content"), From 677363f5fef8d977846c4fd21afefce291b48bc2 Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 3 Mar 2022 08:53:38 -0500 Subject: [PATCH 7/9] Artifact Upload For Docs Action --- .github/workflows/{main.yml => docs_build.yml} | 7 +++++++ 1 file changed, 7 insertions(+) rename .github/workflows/{main.yml => docs_build.yml} (84%) diff --git a/.github/workflows/main.yml b/.github/workflows/docs_build.yml similarity index 84% rename from .github/workflows/main.yml rename to .github/workflows/docs_build.yml index af06cdbb..31014ecb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/docs_build.yml @@ -40,7 +40,14 @@ jobs: with: command: run python generate.py + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: Built-Docs + path: out/ + - name: Deploy To Pages + if: success() && github.ref == 'refs/heads/master' uses: JamesIves/github-pages-deploy-action@4.1.5 with: branch: gh-pages From 61cdb1b9f5b2169bf40b70463e7f203c190a9225 Mon Sep 17 00:00:00 2001 From: Ben C Date: Thu, 3 Mar 2022 17:08:06 -0800 Subject: [PATCH 8/9] 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 --- .github/workflows/docs_build.yml | 9 +++ .gitignore | 12 ++-- docs/Setup.md | 47 ++++++++++++++ docs/content/base/base.jinja2 | 15 +++-- docs/content/base/meta.jinja2 | 61 ++++++++++++++++++ docs/content/browserconfig.jinja2 | 11 ++++ docs/content/robots.jinja2 | 4 ++ docs/content/sitemap.jinja2 | 11 ++++ .../static/fav/android-icon-144x144.png | Bin 0 -> 17175 bytes .../static/fav/android-icon-192x192.png | Bin 0 -> 24739 bytes .../content/static/fav/android-icon-36x36.png | Bin 0 -> 2664 bytes .../content/static/fav/android-icon-48x48.png | Bin 0 -> 3784 bytes .../content/static/fav/android-icon-72x72.png | Bin 0 -> 6475 bytes .../content/static/fav/android-icon-96x96.png | Bin 0 -> 9754 bytes .../content/static/fav/apple-icon-114x114.png | Bin 0 -> 12219 bytes .../content/static/fav/apple-icon-120x120.png | Bin 0 -> 13268 bytes .../content/static/fav/apple-icon-144x144.png | Bin 0 -> 17175 bytes .../content/static/fav/apple-icon-152x152.png | Bin 0 -> 18414 bytes .../content/static/fav/apple-icon-180x180.png | Bin 0 -> 23413 bytes docs/content/static/fav/apple-icon-57x57.png | Bin 0 -> 4731 bytes docs/content/static/fav/apple-icon-60x60.png | Bin 0 -> 5044 bytes docs/content/static/fav/apple-icon-72x72.png | Bin 0 -> 6475 bytes docs/content/static/fav/apple-icon-76x76.png | Bin 0 -> 7028 bytes .../static/fav/apple-icon-precomposed.png | Bin 0 -> 25279 bytes docs/content/static/fav/apple-icon.png | Bin 0 -> 25279 bytes docs/content/static/fav/favicon-16x16.png | Bin 0 -> 1373 bytes docs/content/static/fav/favicon-32x32.png | Bin 0 -> 2340 bytes docs/content/static/fav/favicon-96x96.png | Bin 0 -> 9754 bytes docs/content/static/fav/favicon.ico | Bin 0 -> 1150 bytes docs/content/static/fav/manifest.json | 49 ++++++++++++++ docs/content/static/fav/ms-icon-144x144.png | Bin 0 -> 17175 bytes docs/content/static/fav/ms-icon-150x150.png | Bin 0 -> 18099 bytes docs/content/static/fav/ms-icon-310x310.png | Bin 0 -> 50022 bytes docs/content/static/fav/ms-icon-70x70.png | Bin 0 -> 6287 bytes docs/content/static/robots.txt | 2 - docs/generate.py | 37 ++++++++--- docs/lib/BootstrapExtension.py | 33 ++++++++++ docs/lib/Page.py | 4 +- docs/lib/Schema.py | 3 +- 39 files changed, 274 insertions(+), 24 deletions(-) create mode 100644 docs/Setup.md create mode 100644 docs/content/base/meta.jinja2 create mode 100644 docs/content/browserconfig.jinja2 create mode 100644 docs/content/robots.jinja2 create mode 100644 docs/content/sitemap.jinja2 create mode 100644 docs/content/static/fav/android-icon-144x144.png create mode 100644 docs/content/static/fav/android-icon-192x192.png create mode 100644 docs/content/static/fav/android-icon-36x36.png create mode 100644 docs/content/static/fav/android-icon-48x48.png create mode 100644 docs/content/static/fav/android-icon-72x72.png create mode 100644 docs/content/static/fav/android-icon-96x96.png create mode 100644 docs/content/static/fav/apple-icon-114x114.png create mode 100644 docs/content/static/fav/apple-icon-120x120.png create mode 100644 docs/content/static/fav/apple-icon-144x144.png create mode 100644 docs/content/static/fav/apple-icon-152x152.png create mode 100644 docs/content/static/fav/apple-icon-180x180.png create mode 100644 docs/content/static/fav/apple-icon-57x57.png create mode 100644 docs/content/static/fav/apple-icon-60x60.png create mode 100644 docs/content/static/fav/apple-icon-72x72.png create mode 100644 docs/content/static/fav/apple-icon-76x76.png create mode 100644 docs/content/static/fav/apple-icon-precomposed.png create mode 100644 docs/content/static/fav/apple-icon.png create mode 100644 docs/content/static/fav/favicon-16x16.png create mode 100644 docs/content/static/fav/favicon-32x32.png create mode 100644 docs/content/static/fav/favicon-96x96.png create mode 100644 docs/content/static/fav/favicon.ico create mode 100644 docs/content/static/fav/manifest.json create mode 100644 docs/content/static/fav/ms-icon-144x144.png create mode 100644 docs/content/static/fav/ms-icon-150x150.png create mode 100644 docs/content/static/fav/ms-icon-310x310.png create mode 100644 docs/content/static/fav/ms-icon-70x70.png delete mode 100644 docs/content/static/robots.txt create mode 100644 docs/lib/BootstrapExtension.py diff --git a/.github/workflows/docs_build.yml b/.github/workflows/docs_build.yml index 31014ecb..43caf7fa 100644 --- a/.github/workflows/docs_build.yml +++ b/.github/workflows/docs_build.yml @@ -8,6 +8,15 @@ on: - NewHorizons/*schema*.json workflow_dispatch: + inputs: + relative_path: + description: "Path to set for relative files, set to a blank string for local builds" + required: false + default: "/" + +env: + OUT_DIR: ${{ github.events.inputs.relative_path }} + BASE_URL: https://nh.outerwildsmods.com/ jobs: build: diff --git a/.gitignore b/.gitignore index 737cea76..126ed01f 100644 --- a/.gitignore +++ b/.gitignore @@ -396,7 +396,7 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml -.idea +.idea/ packages .vs @@ -405,9 +405,9 @@ obj zip *.zip -*/Build/* -.idea/ -docs/out/* -docs/schemas/* +*/Build/** +NewHorizons/Properties/** -NewHorizons/Properties/* \ No newline at end of file +# Docs +docs/out/** +docs/content/schemas/** diff --git a/docs/Setup.md b/docs/Setup.md new file mode 100644 index 00000000..74d81e77 --- /dev/null +++ b/docs/Setup.md @@ -0,0 +1,47 @@ +# Setup to build docs + +## Requirements +- Python 3.10 + +## Clone the repo +Clone the entire repo and navigate to the docs folder +```shell +git clone https://github.com/xen-42/outer-wilds-new-horizons +cd outer-wilds-new-horizons/docs +``` + +## Setup Pipenv +Install pipenv if you haven't already +```shell +pip install --user pipenv +``` +Install dependencies +```shell +pipenv install +``` + +## Environment Variables +- OUT_DIR: Path to put before all links and static files, see below for recommended values + - Production: "/" + - Local Build: "" (set as empty string) + - PyCharm Development Server: "/outer-wilds-new-horizons/docs/out/" +- BASE_URL: Base url of the website we're hosting on + - Local: Leave blank + - Local (but wanting to test open-graph/twitter): "https://nh.outerwildsmods.com/" + - Production: "https://nh.outerwildsmods.com/" + + +## Copy Schemas +Create a folder called `schemas` in the content folder and copy all schemas to generate into it, make sure not to add this folder to git. +Production build automatically copies over schemas. + +## Generating +Run `generate.py` with pipenv +```shell +pipenv run python generate.py +``` + +## Opening +- Production: Go to the site +- Local: Open `out/index.html` +- PyCharm Development Server: Right click `out/index.html` -> Open In -> Browser -> Default diff --git a/docs/content/base/base.jinja2 b/docs/content/base/base.jinja2 index a0866c28..12d603c2 100644 --- a/docs/content/base/base.jinja2 +++ b/docs/content/base/base.jinja2 @@ -7,10 +7,11 @@ - - - - New Horizons Documentation | {{ page.title|title }} + {% if dumb %} + {% include "meta.jinja2" %} + {% else %} + {% include "base/meta.jinja2" %} + {% endif %} @@ -24,8 +25,10 @@