Add web interface (#49) #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Document Generation | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
convert: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
# Setup Python for notebook conversion | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
# Install dependencies | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install jupytext nbconvert WeasyPrint markdown | |
# Convert Markdown to Notebook | |
- name: Convert to Notebook | |
run: | | |
for f in _pages/*.md; do | |
jupytext --to notebook "${f}" -o "${f%.md}.ipynb" | |
done | |
# Generate PDF | |
- name: Create conversion script | |
run: | | |
cat > convert.py << 'EOF' | |
import os | |
import markdown | |
import weasyprint | |
for filename in os.listdir('_pages'): | |
if filename.endswith('.md'): | |
md_path = os.path.join('_pages', filename) | |
pdf_path = md_path.replace('.md', '.pdf') | |
with open(md_path, 'r', encoding='utf-8') as md_file: | |
html = markdown.markdown(md_file.read()) | |
weasyprint.HTML(string=html).write_pdf(pdf_path) | |
EOF | |
- name: Generate PDF | |
run: python convert.py | |
# Upload artifacts | |
- name: Upload PDF artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: pdfs | |
path: _pages/*.pdf | |
- name: Upload Notebook artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: notebooks | |
path: _pages/*.ipynb |