1- name : Build GitBook & Deploy to Pages
1+ name : Build Docs Preview & Deploy to Pages
22
33on :
44 push :
@@ -22,59 +22,130 @@ jobs:
2222
2323 - uses : actions/setup-node@v4
2424 with :
25- node-version : ' 12 '
25+ node-version : ' 20 '
2626
27- - name : Install gitbook-cli and patch graceful-fs
27+ - name : Preprocess GitBook tags to HTML
2828 run : |
29- npm install -g gitbook-cli
30- # Patch the known graceful-fs callback bug in gitbook-cli
31- GLOBAL_ROOT=$(npm root -g)
32- for f in $(find "$GLOBAL_ROOT/gitbook-cli" -name "polyfills.js" -path "*/graceful-fs/*" 2>/dev/null); do
33- echo "Patching $f"
34- sed -i 's/fs.stat = statFix(fs.stat)/\/\/fs.stat = statFix(fs.stat)/' "$f"
35- sed -i 's/fs.fstat = statFix(fs.fstat)/\/\/fs.fstat = statFix(fs.fstat)/' "$f"
36- sed -i 's/fs.lstat = statFix(fs.lstat)/\/\/fs.lstat = statFix(fs.lstat)/' "$f"
37- done
38- gitbook fetch 3.2.3
39- # Patch graceful-fs inside the installed gitbook version too
40- for f in $(find ~/.gitbook -name "polyfills.js" -path "*/graceful-fs/*" 2>/dev/null); do
41- echo "Patching $f"
42- sed -i 's/fs.stat = statFix(fs.stat)/\/\/fs.stat = statFix(fs.stat)/' "$f"
43- sed -i 's/fs.fstat = statFix(fs.fstat)/\/\/fs.fstat = statFix(fs.fstat)/' "$f"
44- sed -i 's/fs.lstat = statFix(fs.lstat)/\/\/fs.lstat = statFix(fs.lstat)/' "$f"
29+ # Convert GitBook-specific template tags to HTML equivalents
30+ find docs -name '*.md' -type f | while read -r file; do
31+ python3 - "$file" << 'PYEOF'
32+ import re, sys
33+
34+ f = sys.argv[1]
35+ with open(f, 'r') as fh:
36+ text = fh.read()
37+
38+ # {% hint style="..." %} ... {% endhint %}
39+ text = re.sub(
40+ r'\{%\s*hint\s+style="(\w+)"\s*%\}',
41+ r'> **\1:**',
42+ text
43+ )
44+ text = re.sub(r'\{%\s*endhint\s*%\}', '', text)
45+
46+ # {% code title="..." %} ... {% endcode %}
47+ text = re.sub(r'\{%\s*code\s+title="([^"]+)"\s*%\}', r'**\1**', text)
48+ text = re.sub(r'\{%\s*endcode\s*%\}', '', text)
49+
50+ # {% tabs %} {% tab title="..." %} ... {% endtab %} {% endtabs %}
51+ text = re.sub(r'\{%\s*tabs\s*%\}', '', text)
52+ text = re.sub(r'\{%\s*endtabs\s*%\}', '', text)
53+ text = re.sub(r'\{%\s*tab\s+title="([^"]+)"\s*%\}', r'#### \1', text)
54+ text = re.sub(r'\{%\s*endtab\s*%\}', '', text)
55+
56+ # {% stepper %} {% step %} ... {% endstep %} {% endstepper %}
57+ text = re.sub(r'\{%\s*stepper\s*%\}', '', text)
58+ text = re.sub(r'\{%\s*endstepper\s*%\}', '', text)
59+ text = re.sub(r'\{%\s*step\s*%\}', '---\n**Step:**', text)
60+ text = re.sub(r'\{%\s*endstep\s*%\}', '', text)
61+
62+ # {% embed url="..." %} -> markdown link
63+ text = re.sub(r'\{%\s*embed\s+url="([^"]+)"\s*%\}', r'[\1](\1)', text)
64+
65+ # {% file src="..." %} -> markdown link
66+ text = re.sub(r'\{%\s*file\s+src="([^"]+)"[^%]*%\}', r'[Download](\1)', text)
67+
68+ # {% content-ref url="..." %} ... {% endcontent-ref %}
69+ text = re.sub(r'\{%\s*content-ref\s+url="([^"]+)"\s*%\}', r'[\1](\1)', text)
70+ text = re.sub(r'\{%\s*endcontent-ref\s*%\}', '', text)
71+
72+ # Catch any remaining {% ... %} tags
73+ text = re.sub(r'\{%[^%]*%\}', '', text)
74+
75+ with open(f, 'w') as fh:
76+ fh.write(text)
77+ PYEOF
4578 done
4679
47- - name : Build all sections
80+ - name : Build site with docsify
4881 run : |
4982 mkdir -p _site
50- for section in build learn operate press-and-reports reference tutorials; do
51- echo "Building $section..."
52- cd docs/$section
53- gitbook build . ../../_site/$section
54- cd ../..
83+ SECTIONS="build learn operate press-and-reports reference tutorials"
84+ for section in $SECTIONS; do
85+ mkdir -p _site/$section
86+ cp -r docs/$section/* _site/$section/
87+ # Create docsify index for each section
88+ SUMMARY_FILE="docs/$section/SUMMARY.md"
89+ cat > _site/$section/index.html << HTMLEOF
90+ <!DOCTYPE html>
91+ <html>
92+ <head>
93+ <meta charset="UTF-8">
94+ <title>Stacks Docs - $section</title>
95+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
96+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsify-themeable@0/dist/css/theme-simple.css">
97+ <style>
98+ .sidebar-nav { font-size: 14px; }
99+ .markdown-section { max-width: 900px; }
100+ </style>
101+ </head>
102+ <body>
103+ <div id="app"></div>
104+ <script>
105+ window.\$docsify = {
106+ name: 'Stacks Docs - $section',
107+ loadSidebar: 'SUMMARY.md',
108+ subMaxLevel: 3,
109+ homepage: 'README.md',
110+ search: 'auto',
111+ auto2top: true
112+ }
113+ </script>
114+ <script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/docsify.min.js"></script>
115+ <script src="https://cdn.jsdelivr.net/npm/docsify@4/lib/plugins/search.min.js"></script>
116+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
117+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-toml.min.js"></script>
118+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-json.min.js"></script>
119+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-yaml.min.js"></script>
120+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-javascript.min.js"></script>
121+ <script src="https://cdn.jsdelivr.net/npm/prismjs@1/components/prism-typescript.min.js"></script>
122+ </body>
123+ </html>
124+ HTMLEOF
55125 done
56126
57- - name : Create index page
58- run : |
127+ # Create root index linking to all sections
59128 cat > _site/index.html << 'HTMLEOF'
60129 <!DOCTYPE html>
61130 <html>
62131 <head>
63132 <title>Stacks Docs Preview</title>
64133 <style>
65- body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; max-width: 600px; margin: 80px auto; padding: 0 20px; }
134+ body { font-family: -apple-system, BlinkMacSystemFont, sans-serif; max-width: 600px; margin: 80px auto; padding: 0 20px; color: #333; }
66135 h1 { border-bottom: 2px solid #5546ff; padding-bottom: 10px; }
67136 a { color: #5546ff; text-decoration: none; }
68137 a:hover { text-decoration: underline; }
69138 li { margin: 10px 0; font-size: 18px; }
139+ .badge { background: #e8e5ff; color: #5546ff; padding: 2px 8px; border-radius: 4px; font-size: 12px; margin-left: 8px; }
70140 </style>
71141 </head>
72142 <body>
73143 <h1>Stacks Docs Preview</h1>
144+ <p>Preview deployment from branch <code>feat/node-proxy-preview</code></p>
74145 <ul>
75146 <li><a href="build/">Build</a></li>
76147 <li><a href="learn/">Learn</a></li>
77- <li><a href="operate/">Operate</a></li>
148+ <li><a href="operate/">Operate</a> <span class="badge">new page</span> </li>
78149 <li><a href="press-and-reports/">Press & Reports</a></li>
79150 <li><a href="reference/">Reference</a></li>
80151 <li><a href="tutorials/">Tutorials</a></li>
0 commit comments