Skip to content

Commit

Permalink
update renderer so that <tmpl> converts to <pre class="z-tmpl">
Browse files Browse the repository at this point in the history
  • Loading branch information
shankerwangmiao committed Oct 31, 2023
1 parent e1e308e commit 1b8d853
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ jobs:
- name: Build all documentation
run: |
export TUNA_TEMP_DIR=$(mktemp -d)
git worktree add --no-checkout --detach "$TUNA_TEMP_DIR" origin/transpiled
cat enabled.txt | xargs python global/compile.py -v --lang zh -C dom -C tuna
git checkout transpiled
mv $TUNA_TEMP_DIR/* .
- name: Commit changes
run: |
git config --local user.name "GitHub Actions"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add *.md
git commit -am "Auto build for $GITHUB_REPOSITORY@${GITHUB_SHA::7}" && git push || echo "No changes to commit"
git -C "$TUNA_TEMP_DIR" add --all --verbose
if git -C "$TUNA_TEMP_DIR" diff --exit-code --quiet --cached; then
echo "No changes to commit."
exit 0
fi
git -C "$TUNA_TEMP_DIR" \
-c user.name="GitHub Actions" \
-c user.email="github-actions[bot]@users.noreply.github.com" \
commit -m "Auto build for $GITHUB_REPOSITORY@${GITHUB_SHA::7}"
git -C "$TUNA_TEMP_DIR" push --force origin HEAD:transpiled
21 changes: 12 additions & 9 deletions tuna.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import os
from pathlib import Path
import bs4


outdir = Path(os.environ.get('TUNA_TEMP_DIR', './tuna/'))
os.makedirs(outdir, exist_ok=True)


def process(html, config, project, *_):
doc = bs4.BeautifulSoup(html, 'html.parser')
for tmpl in doc.find_all('tmpl'):
tmpl.name = "pre"
tmpl.attrs["class"] = tmpl.attrs.get("class", []) + ["z-tmpl"]
html = str(doc)
md = f"""---
category: help
layout: help
mirrorid: {config.get('mirrorid', project)}
---
""" + """
<!-- 本 markdown 从 tuna/mirrorz-help-ng 自动生成,如需修改请参阅该仓库 -->
<style>.z-help tmpl { display: none }</style>
<!-- 本页面从 tuna/mirrorz-help-ng 自动生成,如需修改请参阅该仓库 -->
<div class="z-wrap">
<form class="z-form z-global" onchange="form_update(null)" onsubmit="return false">
<div>
Expand All @@ -28,12 +31,12 @@ def process(html, config, project, *_):
</select>
</div>
<div>
<input id="144d763c" name="_scheme" type="checkbox" checked>
<label for="144d763c">是否使用 HTTPS</label>
<input id="a44d763c" name="_scheme" type="checkbox" checked>
<label for="a44d763c">是否使用 HTTPS</label>
</div>
<div>
<input id="4659e7da" name="_sudo" type="checkbox">
<label for="4659e7da">是否使用 sudo</label>
<input id="a659e7da" name="_sudo" type="checkbox">
<label for="a659e7da">是否使用 sudo</label>
</div>
</form>
</div>
Expand All @@ -44,6 +47,6 @@ def process(html, config, project, *_):
<script src="/static/js/mustache.min.js?{{ site.data['hash'] }}"></script>
<script src="/static/js/zdocs.js?{{ site.data['hash'] }}"></script>
"""
with open(outdir/f'1970-01-01-{config.get("permalink", project)}.md', 'w') as f:
with open(outdir/f'1970-01-01-{config.get("permalink", project)}.html', 'w') as f:
f.write(md)
return html

0 comments on commit 1b8d853

Please sign in to comment.