Skip to content

Commit 448e40d

Browse files
committed
Add local Pages preview workflow
1 parent 2eddaf8 commit 448e40d

File tree

5 files changed

+195
-35
lines changed

5 files changed

+195
-35
lines changed

.github/workflows/docs-pages.yml

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,46 +37,51 @@ jobs:
3737
- name: 检出代码
3838
uses: actions/checkout@v4
3939

40-
- name: 准备 Pages 站点目录
40+
- name: 配置 Pages
41+
uses: actions/configure-pages@v5
42+
43+
- name: 准备 Jekyll 源目录
4144
shell: bash
4245
run: |
43-
rm -rf _site
44-
mkdir -p _site/blog
45-
cp docs/_config.yml _site/_config.yml
46-
cp docs/index.md _site/index.md
47-
cp docs/index.en.md _site/index.en.md
48-
cp docs/navigation.md _site/navigation.md
49-
cp docs/navigation.en.md _site/navigation.en.md
50-
cp docs/ci-workflows.md _site/ci-workflows.md
51-
cp docs/ci-workflows.en.md _site/ci-workflows.en.md
52-
cp docs/WSL-Developer-Guide.md _site/WSL-Developer-Guide.md
53-
cp docs/WSL-Developer-Guide.en.md _site/WSL-Developer-Guide.en.md
54-
cp docs/blog-winforms-over-lvgl.md _site/blog-winforms-over-lvgl.md
55-
cp docs/blog-nativeaot-gui.md _site/blog-nativeaot-gui.md
56-
cp docs/blog-linux-hosts.md _site/blog-linux-hosts.md
57-
cp docs/blog-architecture.md _site/blog-architecture.md
58-
cp docs/blog/index.md _site/blog/index.md
59-
cp docs/blog/index.en.md _site/blog/index.en.md
60-
cp docs/blog-architecture.md _site/blog/architecture.md
61-
cp docs/blog-nativeaot-gui.md _site/blog/nativeaot-gui.md
62-
cp docs/blog-linux-hosts.md _site/blog/linux-hosts.md
63-
cp docs/blog-winforms-over-lvgl.md _site/blog/winforms-over-lvgl.md
64-
cp docs/blog/architecture.en.md _site/blog/architecture.en.md
65-
cp docs/blog/nativeaot-gui.en.md _site/blog/nativeaot-gui.en.md
66-
cp docs/blog/linux-hosts.en.md _site/blog/linux-hosts.en.md
67-
cp docs/blog/why-winforms-over-lvgl.en.md _site/blog/why-winforms-over-lvgl.en.md
68-
cp ROADMAP.md _site/ROADMAP.md
69-
cp CHANGELOG.md _site/CHANGELOG.md
70-
cp docs/CNAME _site/CNAME
46+
rm -rf pages-src _site
47+
mkdir -p pages-src/blog
48+
cp docs/_config.yml pages-src/_config.yml
49+
cp docs/index.md pages-src/index.md
50+
cp docs/index.en.md pages-src/index.en.md
51+
cp docs/navigation.md pages-src/navigation.md
52+
cp docs/navigation.en.md pages-src/navigation.en.md
53+
cp docs/ci-workflows.md pages-src/ci-workflows.md
54+
cp docs/ci-workflows.en.md pages-src/ci-workflows.en.md
55+
cp docs/WSL-Developer-Guide.md pages-src/WSL-Developer-Guide.md
56+
cp docs/WSL-Developer-Guide.en.md pages-src/WSL-Developer-Guide.en.md
57+
cp docs/blog-winforms-over-lvgl.md pages-src/blog-winforms-over-lvgl.md
58+
cp docs/blog-nativeaot-gui.md pages-src/blog-nativeaot-gui.md
59+
cp docs/blog-linux-hosts.md pages-src/blog-linux-hosts.md
60+
cp docs/blog-architecture.md pages-src/blog-architecture.md
61+
cp docs/blog/index.md pages-src/blog/index.md
62+
cp docs/blog/index.en.md pages-src/blog/index.en.md
63+
cp docs/blog-architecture.md pages-src/blog/architecture.md
64+
cp docs/blog-nativeaot-gui.md pages-src/blog/nativeaot-gui.md
65+
cp docs/blog-linux-hosts.md pages-src/blog/linux-hosts.md
66+
cp docs/blog-winforms-over-lvgl.md pages-src/blog/winforms-over-lvgl.md
67+
cp docs/blog/architecture.en.md pages-src/blog/architecture.en.md
68+
cp docs/blog/nativeaot-gui.en.md pages-src/blog/nativeaot-gui.en.md
69+
cp docs/blog/linux-hosts.en.md pages-src/blog/linux-hosts.en.md
70+
cp docs/blog/why-winforms-over-lvgl.en.md pages-src/blog/why-winforms-over-lvgl.en.md
71+
cp ROADMAP.md pages-src/ROADMAP.md
72+
cp CHANGELOG.md pages-src/CHANGELOG.md
73+
cp docs/CNAME pages-src/CNAME
7174
7275
if [ -d docs/images ]; then
73-
mkdir -p _site/images
74-
cp -R docs/images/. _site/images/
76+
mkdir -p pages-src/images
77+
cp -R docs/images/. pages-src/images/
7578
fi
7679
77-
cat > _site/.nojekyll <<'EOF'
78-
79-
EOF
80+
- name: 构建 Jekyll 站点
81+
uses: actions/jekyll-build-pages@v1
82+
with:
83+
source: pages-src
84+
destination: _site
8085

8186
- name: 上传 Pages 产物
8287
uses: actions/upload-pages-artifact@v3

.vscode/launch.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch Pages Preview",
6+
"type": "node",
7+
"request": "launch",
8+
"cwd": "${workspaceFolder}",
9+
"runtimeExecutable": "powershell",
10+
"runtimeArgs": [
11+
"-ExecutionPolicy",
12+
"Bypass",
13+
"-Command",
14+
"Start-Process",
15+
"http://127.0.0.1:4000/"
16+
],
17+
"preLaunchTask": "Preview Pages HTML",
18+
"console": "integratedTerminal",
19+
"internalConsoleOptions": "neverOpen"
20+
}
21+
]
22+
}

.vscode/tasks.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Preview Pages HTML",
6+
"type": "shell",
7+
"command": "powershell",
8+
"args": [
9+
"-ExecutionPolicy",
10+
"Bypass",
11+
"-File",
12+
"${workspaceFolder}/preview/preview-pages.ps1"
13+
],
14+
"group": "build",
15+
"isBackground": true,
16+
"problemMatcher": []
17+
},
18+
{
19+
"label": "Build Pages HTML Only",
20+
"type": "shell",
21+
"command": "powershell",
22+
"args": [
23+
"-ExecutionPolicy",
24+
"Bypass",
25+
"-File",
26+
"${workspaceFolder}/preview/preview-pages.ps1",
27+
"-NoServe"
28+
],
29+
"group": "build",
30+
"isBackground": false,
31+
"problemMatcher": []
32+
}
33+
]
34+
}

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- CI 文档:`docs/ci-workflows.md`
1616
- 英文 CI 文档:`docs/ci-workflows.en.md`
1717
- 中文导航:`docs/navigation.md`
18-
- 英文导航:`docs/navigation.en.md`
18+
- 英文导航:`docs/navigation.en.md`
1919
- 中文博客索引:`docs/blog/index.md`
2020
- 英文博客索引:`docs/blog/index.en.md`
2121

@@ -24,6 +24,13 @@
2424
- 中文首页:<https://lvglsharp.net/>
2525
- 英文首页:<https://lvglsharp.net/index.en.html>
2626

27+
本地预览建议:
28+
29+
- 可运行 `preview/preview-pages.ps1` 在本地生成并预览 Pages HTML。
30+
- 默认地址为 `http://127.0.0.1:4000/`
31+
- 如只想生成 `_site` 而不启动预览,可使用 `preview/preview-pages.ps1 -NoServe`
32+
- 在 VS Code 中可直接运行任务:`Preview Pages HTML``Build Pages HTML Only`
33+
2734
> ⚠️ 项目目前处于试验阶段,尚不可用于生产环境。
2835
2936
---

preview/preview-pages.ps1

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
param(
2+
[int]$Port = 4000,
3+
[switch]$NoServe
4+
)
5+
6+
$ErrorActionPreference = 'Stop'
7+
8+
$repoRoot = Split-Path -Parent $PSScriptRoot
9+
$pagesSrc = Join-Path $repoRoot 'pages-src'
10+
$siteDir = Join-Path $repoRoot '_site'
11+
12+
Write-Host 'Preparing local Pages preview source...' -ForegroundColor Cyan
13+
14+
if (Test-Path $pagesSrc) {
15+
Remove-Item $pagesSrc -Recurse -Force
16+
}
17+
18+
if (Test-Path $siteDir) {
19+
Remove-Item $siteDir -Recurse -Force
20+
}
21+
22+
New-Item -ItemType Directory -Path (Join-Path $pagesSrc 'blog') -Force | Out-Null
23+
24+
Copy-Item (Join-Path $repoRoot 'docs\_config.yml') (Join-Path $pagesSrc '_config.yml')
25+
Copy-Item (Join-Path $repoRoot 'docs\index.md') (Join-Path $pagesSrc 'index.md')
26+
Copy-Item (Join-Path $repoRoot 'docs\index.en.md') (Join-Path $pagesSrc 'index.en.md')
27+
Copy-Item (Join-Path $repoRoot 'docs\navigation.md') (Join-Path $pagesSrc 'navigation.md')
28+
Copy-Item (Join-Path $repoRoot 'docs\navigation.en.md') (Join-Path $pagesSrc 'navigation.en.md')
29+
Copy-Item (Join-Path $repoRoot 'docs\ci-workflows.md') (Join-Path $pagesSrc 'ci-workflows.md')
30+
Copy-Item (Join-Path $repoRoot 'docs\ci-workflows.en.md') (Join-Path $pagesSrc 'ci-workflows.en.md')
31+
Copy-Item (Join-Path $repoRoot 'docs\WSL-Developer-Guide.md') (Join-Path $pagesSrc 'WSL-Developer-Guide.md')
32+
Copy-Item (Join-Path $repoRoot 'docs\WSL-Developer-Guide.en.md') (Join-Path $pagesSrc 'WSL-Developer-Guide.en.md')
33+
Copy-Item (Join-Path $repoRoot 'docs\blog-winforms-over-lvgl.md') (Join-Path $pagesSrc 'blog-winforms-over-lvgl.md')
34+
Copy-Item (Join-Path $repoRoot 'docs\blog-nativeaot-gui.md') (Join-Path $pagesSrc 'blog-nativeaot-gui.md')
35+
Copy-Item (Join-Path $repoRoot 'docs\blog-linux-hosts.md') (Join-Path $pagesSrc 'blog-linux-hosts.md')
36+
Copy-Item (Join-Path $repoRoot 'docs\blog-architecture.md') (Join-Path $pagesSrc 'blog-architecture.md')
37+
Copy-Item (Join-Path $repoRoot 'docs\blog\index.md') (Join-Path $pagesSrc 'blog\index.md')
38+
Copy-Item (Join-Path $repoRoot 'docs\blog\index.en.md') (Join-Path $pagesSrc 'blog\index.en.md')
39+
Copy-Item (Join-Path $repoRoot 'docs\blog-architecture.md') (Join-Path $pagesSrc 'blog\architecture.md')
40+
Copy-Item (Join-Path $repoRoot 'docs\blog-nativeaot-gui.md') (Join-Path $pagesSrc 'blog\nativeaot-gui.md')
41+
Copy-Item (Join-Path $repoRoot 'docs\blog-linux-hosts.md') (Join-Path $pagesSrc 'blog\linux-hosts.md')
42+
Copy-Item (Join-Path $repoRoot 'docs\blog-winforms-over-lvgl.md') (Join-Path $pagesSrc 'blog\winforms-over-lvgl.md')
43+
Copy-Item (Join-Path $repoRoot 'docs\blog\architecture.en.md') (Join-Path $pagesSrc 'blog\architecture.en.md')
44+
Copy-Item (Join-Path $repoRoot 'docs\blog\nativeaot-gui.en.md') (Join-Path $pagesSrc 'blog\nativeaot-gui.en.md')
45+
Copy-Item (Join-Path $repoRoot 'docs\blog\linux-hosts.en.md') (Join-Path $pagesSrc 'blog\linux-hosts.en.md')
46+
Copy-Item (Join-Path $repoRoot 'docs\blog\why-winforms-over-lvgl.en.md') (Join-Path $pagesSrc 'blog\why-winforms-over-lvgl.en.md')
47+
Copy-Item (Join-Path $repoRoot 'ROADMAP.md') (Join-Path $pagesSrc 'ROADMAP.md')
48+
Copy-Item (Join-Path $repoRoot 'CHANGELOG.md') (Join-Path $pagesSrc 'CHANGELOG.md')
49+
50+
if (Test-Path (Join-Path $repoRoot 'docs\CNAME')) {
51+
Copy-Item (Join-Path $repoRoot 'docs\CNAME') (Join-Path $pagesSrc 'CNAME')
52+
}
53+
54+
if (Test-Path (Join-Path $repoRoot 'docs\images')) {
55+
Copy-Item (Join-Path $repoRoot 'docs\images') (Join-Path $pagesSrc 'images') -Recurse -Force
56+
}
57+
58+
Push-Location $repoRoot
59+
try {
60+
$bundle = Get-Command bundle -ErrorAction SilentlyContinue
61+
if ($bundle) {
62+
Write-Host 'Building site with Jekyll (bundle exec jekyll build)...' -ForegroundColor Cyan
63+
& bundle exec jekyll build --source $pagesSrc --destination $siteDir
64+
}
65+
else {
66+
Write-Warning 'Ruby/Bundler 未安装,改用 GitHub Pages 等效的静态预览方式:直接复制 Markdown 源到 _site。此模式仅用于快速查看文件结构,不会生成最终 HTML。'
67+
Copy-Item (Join-Path $pagesSrc '*') $siteDir -Recurse -Force
68+
}
69+
70+
if ($NoServe) {
71+
Write-Host "Site prepared at: $siteDir" -ForegroundColor Green
72+
exit 0
73+
}
74+
75+
Write-Host "Starting local preview at http://127.0.0.1:$Port/" -ForegroundColor Green
76+
$python = Get-Command python -ErrorAction SilentlyContinue
77+
if ($python) {
78+
Push-Location $siteDir
79+
try {
80+
& python -m http.server $Port
81+
}
82+
finally {
83+
Pop-Location
84+
}
85+
}
86+
else {
87+
Write-Warning '未找到 python,无法自动启动本地 HTTP 预览。HTML 已生成到 _site,可用任意静态服务器打开。'
88+
}
89+
}
90+
finally {
91+
Pop-Location
92+
}

0 commit comments

Comments
 (0)