Skip to content

Commit e72f408

Browse files
committed
chore(ci): enable github pages deployment
1 parent 9ab5f6b commit e72f408

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

.github/workflows/jekyll-gh-pages.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
2-
name: Deploy Jekyll with GitHub Pages dependencies preinstalled
1+
name: Deploy Vite app to GitHub Pages
32

43
on:
5-
# Runs on pushes targeting the default branch
64
push:
75
branches: ["main"]
8-
9-
# Allows you to run this workflow manually from the Actions tab
106
workflow_dispatch:
117

12-
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
138
permissions:
149
contents: read
1510
pages: write
1611
id-token: write
1712

18-
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
19-
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
2013
concurrency:
2114
group: "pages"
2215
cancel-in-progress: false
2316

2417
jobs:
25-
# Build job
2618
build:
2719
runs-on: ubuntu-latest
2820
steps:
2921
- name: Checkout
3022
uses: actions/checkout@v4
3123
- name: Setup Pages
3224
uses: actions/configure-pages@v5
33-
- name: Build with Jekyll
34-
uses: actions/jekyll-build-pages@v1
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
3527
with:
36-
source: ./
37-
destination: ./_site
28+
node-version: 22
29+
cache: npm
30+
- name: Install dependencies
31+
run: npm ci
32+
- name: Build static site
33+
run: npm run build -- --mode github-pages
34+
- name: Disable Jekyll on Pages
35+
run: touch dist/.nojekyll
3836
- name: Upload artifact
3937
uses: actions/upload-pages-artifact@v3
38+
with:
39+
path: dist
4040

41-
# Deployment job
4241
deploy:
4342
environment:
4443
name: github-pages

vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@ const buildPlugins = (mode: string): PluginOption[] => {
2424
)
2525
}
2626

27+
type DeployBase = '/' | `/${string}/`
28+
const GITHUB_PAGES_BASE: DeployBase = '/gitmeta/'
29+
30+
// CHANGE: выбираем префикс путей сборки в зависимости от среды деплоя
31+
// WHY: GitHub Pages публикует проект под /gitmeta/, поэтому абсолютные ссылки должны быть префиксованы
32+
// QUOTE(ТЗ): "а как сделать что бы всё работало в github pages?"
33+
// REF: user request about GitHub Pages assets returning 404
34+
// SOURCE: https://vite.dev/guide/static-deploy.html#github-pages
35+
// FORMAT THEOREM: ∀mode ∈ {"github-pages", dev}: mode = "github-pages" → base = "/gitmeta/"
36+
// PURITY: CORE
37+
// INVARIANT: mode === "github-pages" ⇒ resolvedBase === "/gitmeta/"
38+
// COMPLEXITY: O(1)/O(1)
39+
const resolveBase = (mode: string): DeployBase =>
40+
mode === 'github-pages' ? GITHUB_PAGES_BASE : '/'
41+
2742
// https://vite.dev/config/
2843
export default defineConfig(({ mode }) => ({
44+
base: resolveBase(mode),
2945
plugins: buildPlugins(mode),
3046
}))

0 commit comments

Comments
 (0)