add github CI to deploy a markdown page Signed-off-by: Pau Escrich <p4u@dabax.net>
Pau Escrich p4u@dabax.net
Fri, 27 Feb 2026 10:29:23 +0100
3 files changed,
191 insertions(+),
0 deletions(-)
A
.github/workflows/build-and-deploy.yml
@@ -0,0 +1,126 @@
+name: Build & Deploy Paper + +on: + push: + branches: ["main"] + +jobs: + build_and_deploy: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Install tools + run: | + sudo apt-get update + sudo apt-get install -y pandoc texlive-latex-recommended texlive-bibtex-extra texlive-extra-utils + + - name: Convert LaTeX to Markdown + run: | + ./scripts/convert-paper.sh + + - name: Build Markdown preview page + run: | + touch docs/.nojekyll + cat << 'EOF' > docs/index.html + <!DOCTYPE html> + <html lang="en"> + <head> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>DaVinci Paper (Markdown)</title> + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@5.8.1/github-markdown.min.css"> + <style> + :root { color-scheme: light; } + body { + margin: 0; + background: #f6f8fa; + color: #24292f; + } + .topbar { + position: sticky; + top: 0; + z-index: 2; + display: flex; + gap: 12px; + align-items: center; + padding: 12px 16px; + border-bottom: 1px solid #d0d7de; + background: #ffffff; + } + .topbar a { + text-decoration: none; + border: 1px solid #d0d7de; + border-radius: 6px; + padding: 6px 10px; + color: #24292f; + background: #f6f8fa; + font: 600 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; + } + .markdown-body { + box-sizing: border-box; + min-width: 200px; + max-width: 980px; + margin: 0 auto; + padding: 28px 20px 40px; + background: #fff; + } + #status { + margin-left: auto; + font: 500 13px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; + color: #57606a; + } + @media (max-width: 767px) { + .markdown-body { padding: 20px 16px 28px; } + } + </style> + </head> + <body> + <div class="topbar"> + <a href="paper.md" download>Download paper.md</a> + <a href="paper.md" target="_blank" rel="noopener noreferrer">Open raw markdown</a> + <span id="status">Loading markdown...</span> + </div> + <article id="content" class="markdown-body"></article> + <script src="https://cdn.jsdelivr.net/npm/marked@15.0.12/lib/marked.umd.min.js"></script> + <script src="https://cdn.jsdelivr.net/npm/dompurify@3.1.7/dist/purify.min.js"></script> + <script> + (async () => { + const status = document.getElementById('status'); + const content = document.getElementById('content'); + try { + const response = await fetch('paper.md', { cache: 'no-store' }); + if (!response.ok) { + throw new Error('HTTP ' + response.status); + } + const md = await response.text(); + marked.setOptions({ gfm: true, breaks: false }); + const html = marked.parse(md); + content.innerHTML = DOMPurify.sanitize(html); + status.textContent = 'Loaded'; + } catch (err) { + status.textContent = 'Failed to load markdown'; + content.innerHTML = '<p>Unable to render <code>paper.md</code>.</p><p>' + err.message + '</p>'; + } + })(); + </script> + </body> + </html> + EOF + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs + + - name: Upload paper.md artifact + uses: actions/upload-artifact@v4 + with: + name: paper-markdown + path: docs/paper.md + if-no-files-found: error
A
docker/pandoc-test/Dockerfile
@@ -0,0 +1,13 @@
+FROM ubuntu:24.04 + +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + pandoc \ + texlive-latex-recommended \ + texlive-bibtex-extra \ + texlive-extra-utils \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /workspace + +CMD ["bash"]
A
scripts/convert-paper.sh
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +cd "$ROOT_DIR" + +mkdir -p build/flat docs + +TMP_TEX_ROOT="build/flat/texsrc" +rm -rf "$TMP_TEX_ROOT" +cp -R v2 "$TMP_TEX_ROOT" + +# latexpand does not resolve macro-based include prefixes like \secs/, so +# normalize them to explicit relative paths in a temporary conversion tree. +while IFS= read -r -d '' tex_file; do + sed -E \ + -e 's#\\input\{\\secs/#\\input{../sections/#g' \ + -e 's#\\input\{\\figs/#\\input{../figures/#g' \ + -e 's#\\includegraphics(\[[^]]*\])?\{\\figs/#\\includegraphics\1{../figures/#g' \ + -e 's#\\bibliography\{\\bib/#\\bibliography{../bibliography/#g' \ + "$tex_file" > "${tex_file}.tmp" + mv "${tex_file}.tmp" "$tex_file" +done < <(find "$TMP_TEX_ROOT" -type f -name '*.tex' -print0) + +# Support extensionless \includegraphics{...} paths by adding symlink aliases. +if [[ -d "$TMP_TEX_ROOT/figures" ]]; then + while IFS= read -r -d '' figure_file; do + figure_base="${figure_file%.*}" + if [[ "$figure_file" != "$figure_base" && ! -e "$figure_base" ]]; then + ln -s "$(basename "$figure_file")" "$figure_base" + fi + done < <(find "$TMP_TEX_ROOT/figures" -maxdepth 1 -type f -print0) +fi + +( + cd "$TMP_TEX_ROOT/build" + latexpand main.tex > "$ROOT_DIR/build/flat/flattened.tex" +) + +pandoc build/flat/flattened.tex \ + --from=latex+raw_tex \ + --to=gfm+tex_math_dollars \ + --wrap=none \ + --markdown-headings=atx \ + --resource-path=build/flat:build/flat/texsrc/build:build/flat/texsrc/sections:build/flat/texsrc/figures:v2/build:v2/sections:v2/figures:v2/bibliography \ + --citeproc \ + --bibliography=v2/bibliography/bibtex.bib \ + --extract-media=docs/media \ + --strip-comments \ + -o docs/paper.md + +test -s docs/paper.md