Skip to content

Commit 95338f6

Browse files
committed
update
update
1 parent c022dbd commit 95338f6

File tree

4 files changed

+233
-0
lines changed

4 files changed

+233
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env perl
2+
# 后处理:将 span 占位符改回 img 标签(完全保留原始属性,不做任何修改)
3+
open M, "<", $ARGV[1] or die $!;
4+
my %map = map { chomp; my ($k, $v) = split /\t/, $_, 2; ($k, $v) } <M>;
5+
close M;
6+
open F, "<", $ARGV[0] or die $!;
7+
undef $/;
8+
my $md = <F>;
9+
close F;
10+
$md =~ s/<span data-img-replace="(\d+)"><\/span>/exists $map{$1} ? $map{$1} : ""/ge;
11+
# figure.app-icon 内的图标设为 64x64
12+
$md =~ s/(<figure class="app-icon">\s*)<img\s/$1<img width="64" height="64" /g;
13+
# figure.topicIcon 内的图标设为 48x48(移除原有的 30x30)
14+
$md =~ s/(<figure class="topicIcon">\s*)<img\s/$1<img width="48" height="48" /g;
15+
$md =~ s/(<figure class="topicIcon">[^<]*<img[^>]*)\s+(?:height="30"\s+width="30"|width="30"\s+height="30")([^>]*>)/$1$2/g;
16+
open F, ">", $ARGV[0] or die $!;
17+
print F $md;
18+
close F;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env perl
2+
# 预处理:用 span 占位符替换 img,保存映射
3+
undef $/;
4+
open F, "<", $ARGV[0] or die $!;
5+
my $html = <F>;
6+
close F;
7+
my @imgs;
8+
my $n = 0;
9+
sub make_placeholder {
10+
my ($attrs, $idx) = @_;
11+
push @imgs, "<img$attrs>";
12+
return "<span data-img-replace=\"$idx\"></span>";
13+
}
14+
$html =~ s/<img(\s[^>]*?)>/make_placeholder($1, $n++)/ge;
15+
open O, ">", $ARGV[1] or die $!;
16+
print O $html;
17+
close O;
18+
open M, ">", $ARGV[2] or die $!;
19+
my $tab = chr(9);
20+
my $nl = chr(10);
21+
for my $i (0..scalar(@imgs)-1) {
22+
print M $i . $tab . $imgs[$i] . $nl;
23+
}
24+
close M;

.github/scripts/help-to-md.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env bash
2+
# 本地将 Help HTML 转为 Markdown(图片保留为 HTML 标签)
3+
# 用法: ./.github/scripts/help-to-md.sh
4+
5+
set -euo pipefail
6+
7+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
cd "$REPO_ROOT"
10+
11+
SRC_DIR="help/SwiftCraftLauncher.help/Contents/Resources/en.lproj"
12+
OUT_DIR="_wiki_help"
13+
14+
if [[ ! -d "$SRC_DIR" ]]; then
15+
echo "错误: 源目录不存在: $SRC_DIR"
16+
exit 1
17+
fi
18+
19+
command -v pandoc >/dev/null 2>&1 || {
20+
echo "错误: 需要安装 pandoc。macOS: brew install pandoc"
21+
exit 1
22+
}
23+
24+
command -v perl >/dev/null 2>&1 || {
25+
echo "错误: 需要 perl(系统通常已自带)"
26+
exit 1
27+
}
28+
29+
mkdir -p "$OUT_DIR"
30+
31+
shopt -s nullglob 2>/dev/null || true
32+
for f in "$SRC_DIR"/*.html; do
33+
[[ -e "$f" ]] || continue
34+
base="$(basename "$f" .html)"
35+
36+
out_name="$base.md"
37+
if [[ "$base" == "index" ]]; then
38+
out_name="home.md"
39+
fi
40+
41+
out="$OUT_DIR/$out_name"
42+
tmp_preprocessed="$OUT_DIR/pre_${base}.html"
43+
map_file="$OUT_DIR/.img_${base}.map"
44+
45+
echo "转换: $base.html -> $out_name"
46+
47+
# 1. 预处理:用 <span data-img-replace="n"> 替换 <img...>,pandoc 会保留此 span
48+
perl "$SCRIPT_DIR/help-to-md-preprocess.pl" "$f" "$tmp_preprocessed" "$map_file"
49+
50+
# 2. pandoc 转换
51+
pandoc "$tmp_preprocessed" \
52+
--from=html \
53+
--to=gfm+raw_html \
54+
--wrap=none \
55+
-o "$out"
56+
57+
# 3. 后处理:将 <span data-img-replace="n"> 改回原始 <img> 标签
58+
perl "$SCRIPT_DIR/help-to-md-postprocess.pl" "$out" "$map_file"
59+
rm -f "$map_file" "$tmp_preprocessed" 2>/dev/null
60+
61+
# 4. 调整内部链接以适配 GitHub Wiki
62+
perl -pi -e '
63+
s/\]\(((?!https?:\/\/)[^)]*?)index\.html(\))/\]\(\1home\2/g;
64+
s/\]\(((?!https?:\/\/)[^)]*?)index\.html(#)/\]\(\1home\2/g;
65+
s/\]\(((?!https?:\/\/)[^)]*?)\.html(\))/\]\(\1\2/g;
66+
s/\]\(((?!https?:\/\/)[^)]*?)\.html(#)/\]\(\1\2/g;
67+
s/\]\(home(\#[^)]*)\)/\](home.md$1)/g;
68+
s/\]\(home\)/\](home.md)/g;
69+
s/href="index\.html"/href="home"/g;
70+
s/href="index\.html#/href="home#/g;
71+
' "$out" 2>/dev/null || true
72+
done
73+
74+
echo ""
75+
echo "完成。输出目录: $OUT_DIR/"

.github/workflows/help-to-wiki.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: Publish Help (HTML → Wiki Markdown)
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- "help/SwiftCraftLauncher.help/Contents/Resources/en.lproj/**"
8+
- ".github/scripts/**"
9+
10+
permissions:
11+
contents: read
12+
13+
concurrency:
14+
group: publish-help-to-wiki
15+
cancel-in-progress: true
16+
17+
jobs:
18+
publish:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout assets repo
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 1
25+
26+
- name: Install pandoc
27+
run: |
28+
sudo apt-get update
29+
sudo apt-get install -y pandoc
30+
31+
- name: Convert HTML to Markdown (GFM)
32+
shell: bash
33+
run: |
34+
set -euo pipefail
35+
36+
SRC_DIR="help/SwiftCraftLauncher.help/Contents/Resources/en.lproj"
37+
OUT_DIR="_wiki_help"
38+
SCRIPT_DIR=".github/scripts"
39+
mkdir -p "$OUT_DIR"
40+
41+
shopt -s nullglob
42+
for f in "$SRC_DIR"/*.html; do
43+
[[ -e "$f" ]] || continue
44+
base="$(basename "$f" .html)"
45+
46+
out_name="$base.md"
47+
if [[ "$base" == "index" ]]; then
48+
out_name="home.md"
49+
fi
50+
51+
out="$OUT_DIR/$out_name"
52+
tmp_preprocessed="$OUT_DIR/pre_${base}.html"
53+
map_file="$OUT_DIR/.img_${base}.map"
54+
55+
echo "转换: $base.html -> $out_name"
56+
57+
# 1. 预处理:用 span 占位符替换 img,pandoc 会保留 span
58+
perl "$SCRIPT_DIR/help-to-md-preprocess.pl" "$f" "$tmp_preprocessed" "$map_file"
59+
60+
# 2. pandoc 转换
61+
pandoc "$tmp_preprocessed" \
62+
--from=html \
63+
--to=gfm+raw_html \
64+
--wrap=none \
65+
-o "$out"
66+
67+
# 3. 后处理:恢复 img 标签,app-icon 64x64,topicIcon 48x48
68+
perl "$SCRIPT_DIR/help-to-md-postprocess.pl" "$out" "$map_file"
69+
rm -f "$map_file" "$tmp_preprocessed" 2>/dev/null || true
70+
71+
# 4. 调整内部链接以适配 GitHub Wiki
72+
perl -pi -e '
73+
s/\]\(((?!https?:\/\/)[^)]*?)index\.html(\))/\]\(\1home\2/g;
74+
s/\]\(((?!https?:\/\/)[^)]*?)index\.html(#)/\]\(\1home\2/g;
75+
s/\]\(((?!https?:\/\/)[^)]*?)\.html(\))/\]\(\1\2/g;
76+
s/\]\(((?!https?:\/\/)[^)]*?)\.html(#)/\]\(\1\2/g;
77+
s/\]\(home(\#[^)]*)\)/\](home.md$1)/g;
78+
s/\]\(home\)/\](home.md)/g;
79+
s/href="index\.html"/href="home"/g;
80+
s/href="index\.html#/href="home#/g;
81+
' "$out" 2>/dev/null || true
82+
done
83+
84+
- name: Publish to GitHub Wiki repo
85+
env:
86+
WIKI_REPO: suhang12332/Swift-Craft-Launcher.wiki
87+
WIKI_PAT: ${{ secrets.WIKI_PAT }}
88+
shell: bash
89+
run: |
90+
set -euo pipefail
91+
92+
if [[ -z "${WIKI_PAT:-}" ]]; then
93+
echo "Missing secret WIKI_PAT. Add your existing PAT as a repository secret named WIKI_PAT."
94+
exit 1
95+
fi
96+
97+
# 为当前 runner 设置全局 git 身份,避免 Author identity unknown
98+
git config --global user.name "github-actions[bot]"
99+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
100+
101+
git clone "https://x-access-token:${WIKI_PAT}@github.com/${WIKI_REPO}.git" wiki
102+
103+
# 覆盖 wiki 主仓库根目录(不再使用子目录)
104+
cp -R "_wiki_help/." "wiki/"
105+
106+
cd wiki
107+
git config user.name "github-actions[bot]"
108+
git config user.email "github-actions[bot]@users.noreply.github.com"
109+
git add -A
110+
if git diff --cached --quiet; then
111+
echo "No wiki changes to publish."
112+
exit 0
113+
fi
114+
git commit -m "Update help docs (HTML → Markdown)"
115+
git push
116+

0 commit comments

Comments
 (0)