Skip to content

Commit 00483e5

Browse files
committed
add easypage support
1 parent faad436 commit 00483e5

File tree

14 files changed

+608
-121
lines changed

14 files changed

+608
-121
lines changed

.github/workflows/check-build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on: pull_request
33

44
env:
55
PYTHON_VERSION: 3.10.1
6+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
67

78
jobs:
89
check_build:
@@ -37,11 +38,14 @@ jobs:
3738
run: poetry install --no-interaction --no-root
3839

3940
- name: Install Python dependencies
40-
run: poetry install --no-interaction
41+
run: |
42+
poetry install --no-interaction
43+
poetry run pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
4144
4245
- name: Check docs build
4346
run: poetry run mkdocs build -s
4447

48+
# TODO: wanted to have rendered pages uploaded but those are over 60MB os will not fit in the free GH plan
4549
# - name: Archive docs artifacts
4650
# uses: actions/upload-artifact@v2
4751
# with:

.github/workflows/documentation.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66

77
env:
88
PYTHON_VERSION: 3.10.1
9+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
910

1011
jobs:
1112
documentation:
@@ -40,7 +41,9 @@ jobs:
4041
run: poetry install --no-interaction --no-root
4142

4243
- name: Install Python dependencies
43-
run: poetry install --no-interaction
44+
run: |
45+
poetry install --no-interaction
46+
poetry run pip install git+https://${GH_TOKEN}@github.com/squidfunk/mkdocs-material-insiders.git
4447
4548
- name: Deploy documentation
4649
run: |

docs/.pages

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nav:
2+
- manual.md
3+
- ...

docs/assets/fake_stl.stl

Whitespace-only changes.

docs/js/extra.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
app.document$.subscribe(function() {
2-
window.CI360.init();
3-
var tables = document.querySelectorAll("article table")
4-
tables.forEach(function(table) {
5-
new Tablesort(table)
1+
document$.subscribe(function() {
2+
var tables = document.querySelectorAll("article table:not([class])")
3+
tables.forEach(function(table) {
4+
new Tablesort(table)
65
})
6+
window.CI360.init();
77
})

docs/manual.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
title: Example page
3+
icon: material/head-question
4+
eva:
5+
author:
6+
display_name: Paweł Kucmus
7+
url: https://github.com/pkucmus
8+
description: |
9+
If you put a pipe `|` followed by a line break you can do a multiline description.
10+
This supports markdown so you can put a:
11+
12+
- list
13+
- image
14+
- many other
15+
16+
Go to the [:material-github: source of this file](https://github.com/EVA-3D/contrib-extras/edit/main/docs/index.md) to see how it works.
17+
18+
Have fun: ![](assets/candy_bowl.png)
19+
bom:
20+
- name: my_custom_part
21+
qty: 1
22+
is_printable: true
23+
url: assets/fake_stl.stl
24+
- name: some screw
25+
qty: 12
26+
is_printable: false
27+
eva_version: "2.0.0 and up"
28+
print_instructions: |
29+
There are none, this is an example page
30+
step_files: |
31+
None
32+
---
33+
34+
{% extends "easy_page.html" %}

eva_contrib_builder/__init__.py

Whitespace-only changes.

eva_contrib_builder/plugin.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import logging
2+
3+
from mkdocs.plugins import BasePlugin
4+
from mkdocs.exceptions import BuildError
5+
from mkdocs.utils.meta import YAML_RE
6+
import yaml
7+
try:
8+
from yaml import CSafeLoader as SafeLoader
9+
except ImportError: # pragma: no cover
10+
from yaml import SafeLoader
11+
12+
from eva_contrib_builder.schemas import EasyPageMeta
13+
14+
15+
log = logging.getLogger(__name__)
16+
17+
18+
19+
# TODO: Decide if it's even helpful
20+
# import click
21+
# from mkdocs.__main__ import ColorFormatter
22+
# mkdocs_logger = logging.getLogger("mkdocs")
23+
# class GHActionsColorFormatter(ColorFormatter):
24+
25+
# PREFIX_LEVELS = {
26+
# "WARNING": "::error::",
27+
# "ERROR": "::error::",
28+
# }
29+
30+
# def format(self, record):
31+
# message = super().format(record)
32+
# prefix = ""
33+
# if record.levelname in self.PREFIX_LEVELS:
34+
# prefix = self.PREFIX_LEVELS[record.levelname]
35+
# return prefix + message
36+
# mkdocs_logger.handlers[0].setFormatter(GHActionsColorFormatter())
37+
38+
class EVAContribPlugin(BasePlugin):
39+
40+
def on_config(self, config):
41+
self.env = config['theme'].get_env()
42+
self.env.filters["yes_no"] = self.yes_no
43+
44+
@staticmethod
45+
def yes_no(value: bool):
46+
return "yes" if value else "no"
47+
48+
def _get_markdown_context(self, page, config):
49+
page.eva = None
50+
if "eva" in page.meta:
51+
page.eva = EasyPageMeta(**page.meta["eva"])
52+
53+
return {
54+
"eva": page.eva,
55+
}
56+
57+
def on_page_context(self, context, page, config, nav):
58+
context = {**self._get_markdown_context(page, config), **context}
59+
return context
60+
61+
def on_page_read_source(self, page, config):
62+
# Mkdocs hides YAML parsing errors, to access those I need to load the
63+
# source and do an initial YAML load on my own, it get properly loded
64+
# again by mkdocs
65+
try:
66+
with open(page.file.abs_src_path, 'r', encoding='utf-8-sig', errors='strict') as f:
67+
source = f.read()
68+
except OSError:
69+
mkdocs_logger.error(f'File not found: {page.file.src_path}')
70+
raise
71+
except ValueError:
72+
mkdocs_logger.error(f'Encoding error reading file: {page.file.src_path}')
73+
raise
74+
75+
m = YAML_RE.match(source)
76+
if m:
77+
try:
78+
data = yaml.load(m.group(1), SafeLoader)
79+
if not isinstance(data, dict):
80+
data = {}
81+
except Exception as exc:
82+
raise BuildError(f"Page's YAML metadata is malformed: {exc}")
83+
page.meta = data
84+
return source
85+
86+
def on_page_markdown(self, markdown, page, config, files):
87+
md_template = self.env.from_string(markdown)
88+
return md_template.render(**self._get_markdown_context(page, config))

eva_contrib_builder/schemas.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import List, Optional
2+
from pydantic import BaseModel, Extra
3+
from pydantic.networks import HttpUrl
4+
5+
6+
class Author(BaseModel):
7+
display_name: str
8+
url: Optional[HttpUrl]
9+
10+
11+
class BOMItem(BaseModel):
12+
name: str
13+
qty: int
14+
is_printable: bool
15+
url: Optional[str]
16+
17+
18+
class EasyPageMeta(BaseModel):
19+
author: Author
20+
description: str
21+
bom: List[BOMItem]
22+
eva_version: str
23+
print_instructions: str
24+
step_files: Optional[str]
25+
26+
class Config:
27+
extra = Extra.allow

mkdocs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ site_author: "Paweł Kucmus"
44
site_description: "EVA 2 repository for the community to share their parts"
55
edit_uri: ""
66

7-
copyright: Copyright © 2020 Paweł Kucmus
7+
copyright: Copyright © 2022 Paweł Kucmus
88

99
repo_name: EVA-3D / contrib-extras
1010
repo_url: https://github.com/EVA-3D/contrib-extras
@@ -30,6 +30,7 @@ plugins:
3030
- search
3131
- minify:
3232
minify_html: true
33+
- eva-contrib-plugin
3334

3435
extra_css:
3536
- css/extra.css

0 commit comments

Comments
 (0)