Skip to content

Commit

Permalink
chore(docs): Generate previews
Browse files Browse the repository at this point in the history
  • Loading branch information
reemo3dp committed Mar 13, 2024
1 parent ac5baba commit 2e41870
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions .github/workflows/update_previews.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Update Previews
on:
workflow_dispatch:
push:
paths:
- '*.md'
- 'docs/*.md'
- 'docs/**/*.md'
branches:
- main

jobs:
update_previews:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install dependencies
working-directory: ./packages/preview_generator
run: poetry install
- name: Update all previews
working-directory: ./packages/preview_generator
run: |
set -x
for i in $(ls $GITHUB_WORKSPACE/*.md $GITHUB_WORKSPACE/docs/**/*.md $GITHUB_WORKSPACE/docs/*.md); do
poetry run python markdown_generator.py "$i"
done
- name: Commit changes
working-directory: .
run: |
set -euxo pipefail
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add *.md docs/**/*.md docs/*.md || true
git diff --staged --quiet && exit 0 || true
git commit -m "chore(docs): Update previews"
git push origin HEAD:${GITHUB_REF}
2 changes: 1 addition & 1 deletion packages/preview_generator/markdown_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def replace_with_preview(match):
content = match.group('block')
layers = match.group('layers')
output_dir = os.path.dirname(args.markdown.name)
filename = os.path.join(output_dir, args.directory, "preview_" + str(zlib.crc32(layers.encode('utf-8')))+".gif")
filename = os.path.join(output_dir, args.directory, "preview_" + str(zlib.crc32(repr([layers, args]).encode('utf-8')))+".gif")
relative_filename = "./"+os.path.relpath(filename, os.path.dirname(args.markdown.name))
# If file doesn't exist
if not os.path.exists(filename):
Expand Down

0 comments on commit 2e41870

Please sign in to comment.