Skip to content

Commit dd7c1c0

Browse files
committed
feat: Add GitHub Actions workflow for deployment to GitHub Pages and implement content copying script
1 parent 04ea6fc commit dd7c1c0

4 files changed

Lines changed: 86 additions & 0 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: pages
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: 20
28+
cache: npm
29+
30+
- name: Install deps
31+
run: npm ci
32+
33+
- name: Summarize PDFs (optional)
34+
run: npm run summarize || echo "summarize skipped"
35+
36+
- name: Build with Vite (set base to repo name)
37+
env:
38+
BASE_PATH: "/${{ github.event.repository.name }}/"
39+
run: |
40+
npm run build -- --base="$BASE_PATH"
41+
cp dist/index.html dist/404.html
42+
43+
- name: Upload artifact
44+
uses: actions/upload-pages-artifact@v3
45+
with:
46+
path: ./dist
47+
48+
deploy:
49+
environment:
50+
name: github-pages
51+
url: ${{ steps.deployment.outputs.page_url }}
52+
runs-on: ubuntu-latest
53+
needs: build
54+
steps:
55+
- name: Deploy to GitHub Pages
56+
id: deployment
57+
uses: actions/deploy-pages@v4
58+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"dev": "vite",
8+
"prebuild": "node scripts/copy-content.js",
89
"build": "tsc -b && vite build",
910
"preview": "vite preview",
1011
"summarize": "node scripts/summarize.js"

public/.gitkeep

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

scripts/copy-content.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/* eslint-disable no-console */
2+
// Copies content/ into public/ so static assets are available in build
3+
import fs from 'node:fs';
4+
import path from 'node:path';
5+
6+
const ROOT = process.cwd();
7+
const SRC = path.join(ROOT, 'content');
8+
const DEST = path.join(ROOT, 'public', 'content');
9+
10+
try {
11+
if (!fs.existsSync(SRC)) {
12+
console.log('No content/ directory to copy. Skipping.');
13+
process.exit(0);
14+
}
15+
fs.mkdirSync(DEST, { recursive: true });
16+
for (const f of fs.readdirSync(SRC)) {
17+
const from = path.join(SRC, f);
18+
const to = path.join(DEST, f);
19+
if (fs.statSync(from).isFile()) fs.copyFileSync(from, to);
20+
}
21+
console.log('Copied content/ to public/content');
22+
} catch (e) {
23+
console.error('Failed to copy content:', e);
24+
process.exit(1);
25+
}
26+

0 commit comments

Comments
 (0)