-
Notifications
You must be signed in to change notification settings - Fork 98
286 lines (262 loc) · 15 KB
/
Copy pathci.yml
File metadata and controls
286 lines (262 loc) · 15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: Build and Deploy
on:
push:
branches:
- master
jobs:
build-and-deploy:
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
steps:
# https://github.com/actions/setup-node
- name: Setup Node.js 🕸
uses: actions/setup-node@v4
with:
# https://github.com/nvm-sh/nvm#long-term-support
node-version: 'lts/*'
# https://github.com/actions/checkout
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
persist-credentials: false
# https://github.com/actions/setup-java
- name: Set up JDK ☕️
uses: actions/setup-java@v4
with:
java-version: '25'
distribution: 'corretto'
cache: 'maven'
# https://github.com/marketplace/actions/docker-setup-docker
- name: Setup Docker 🐳
uses: docker/setup-docker-action@v4
- name: Add Watermark to Images 🎖
run: |
docker pull dpokidov/imagemagick
cd docs
wget https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-Semibold.otf
BASEDIR=$( pwd )/
# 异步加水印
# JPG
echo " "
echo -e "\n\n$(date +%T) start to add watermark to JPG"
find . -type f -name "*.jpg" | grep -v "wx-jikerizhi-qrcode.jpg\|wx-jikerizhi.jpg\|wxpay.jpg" | sed "s/.jpg$//g" | xargs -I {} docker run --rm -v ${BASEDIR}:/imgs dpokidov/imagemagick -compress JPEG2000 -strip -thumbnail "1200x>" -quality 75 -font /imgs/SourceCodePro-Semibold.otf -pointsize 30 -gravity southeast -fill "#DE282A" -draw 'text 15,18 "https://www.diguage.com"' /imgs/{}.jpg /imgs/{}-mark.jpg 1>/dev/null 2>&1 &
wait
echo -e "$(date +%T) finish adding watermark to JPG...\n\n"
echo " "
find . -type f -name "*.jpg" | xargs ls -l -h
echo " "
echo -e "\n\n$(date +%T) --start to replace JPG----------------------"
for f in `find . -type f -name "*-mark.jpg"`;
do
name=`echo $f | sed "s/-mark.jpg//g"`
echo "replace ${f} to ${name}.jpeg"
rm -rf "${name}.jpg"
mv "${f}" "${name}.jpg"
done
echo -e "$(date +%T) --finish replacing JPG----------------------\n\n"
echo " "
find . -type f -name "*.jpg" | xargs ls -l -h
# JPEG
echo " "
echo -e "\n\n$(date +%T) start to add watermark to JPEG"
find . -type f -name "*.jpeg" | sed "s/.jpeg$//g" | xargs -I {} docker run --rm -v ${BASEDIR}:/imgs dpokidov/imagemagick -compress JPEG2000 -strip -thumbnail "1200x>" -quality 75 -font /imgs/SourceCodePro-Semibold.otf -pointsize 30 -gravity southeast -fill "#DE282A" -draw 'text 15,18 "https://www.diguage.com"' /imgs/{}.jpeg /imgs/{}-mark.jpeg 1>/dev/null 2>&1 &
wait
echo -e "$(date +%T) finish adding watermark to JPEG...\n\n"
echo " "
find . -type f -name "*.jpeg" | xargs ls -l -h
echo " "
echo -e "\n\n$(date +%T) --start to replace JPEG----------------------"
for f in `find . -type f -name "*-mark.jpeg"`;
do
name=`echo $f | sed "s/-mark.jpeg//g"`
echo "replace ${f} to ${name}.jpeg"
rm -rf "${name}.jpeg"
mv "${f}" "${name}.jpeg"
done
echo -e "$(date +%T) --finish replacing JPEG----------------------\n\n"
echo " "
find . -type f -name "*.jpeg" | xargs ls -l -h
# # PNG
# echo " "
# echo -e "\n\n$(date +%T) start to add watermark to PNG"
# find . -type f -name "*.png" | grep -v "alipay.png\|wxpay.png" | sed "s/.png$//g" | xargs -I {} docker run --rm -v ${BASEDIR}:/imgs dpokidov/imagemagick -strip -resize 1200x -define png:compression-level=9 -define png:exclude-chunk=all -define png:filter-type=1 -font /imgs/SourceCodePro-Semibold.otf -pointsize 30 -gravity southeast -fill "#DE282A" -draw 'text 15,18 "https://www.diguage.com"' /imgs/{}.png /imgs/{}-mark.png 1>/dev/null 2>&1 &
#
# wait
# echo -e "$(date +%T) finish adding watermark to PNG...\n\n"
# echo " "
# find . -type f -name "*.png" | xargs ls -l -h
# echo " "
# echo -e "\n\n$(date +%T) --start to replace PNG----------------------"
# for f in `find . -type f -name "*-mark.png"`;
# do
# name=`echo $f | sed "s/-mark.png//g"`
# echo "replace ${f} to ${name}.png"
# rm -rf "${name}.png"
# mv "${f}" "${name}.png"
# done
# echo -e "$(date +%T) --finish replacing PNG----------------------\n\n"
# echo " "
# find . -type f -name "*.png" | xargs ls -l -h
- name: Install font 🎃
run: |
mkdir $HOME/.fonts
cd $HOME/.fonts
declare -a fonts=('https://github.com/diguage/open-fonts/releases/download/latest/NotoEmoji-Regular.ttf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-Regular.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-Semibold.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-It.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-Bold.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceCodePro-BoldIt.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/JetBrainsMono-Regular.ttf' \
'https://github.com/diguage/open-fonts/releases/download/latest/JetBrainsMono-SemiBold.ttf' \
'https://github.com/diguage/open-fonts/releases/download/latest/JetBrainsMono-Bold.ttf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSerifSC-Regular.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSerifSC-Bold.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSerifSC-Medium.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSerifSC-SemiBold.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSansSC-Regular.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSansSC-Bold.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSansSC-Medium.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/SourceHanSansSC-Heavy.otf' \
'https://github.com/diguage/open-fonts/releases/download/latest/Symbola.ttf')
echo -e "$(date +%T) start to download fonts...\n"
for font in "${fonts[@]}"
do
name=`echo $font | awk -F'/' '{print $NF}'`
if [ -f "$name" ]; then
echo "$name exists."
else
wget -c --tries=5 --retry-connrefused --waitretry=5 --timeout=10 $font 1>/dev/null 2>&1 &
fi
done
wait
echo -e "$(date +%T) finish downloading fonts...\n"
ls -lh
# # 使用 Kroki 处理,就不需要配置字体了
# - name: Check font 🔍
# run: |
# echo -e "[seqdiag]\nfontpath = $HOME/.fonts/SourceHanSerifSC-Regular.otf" > $HOME/.blockdiagrc
# echo -e "\n[blockdiag]\nfontpath = $HOME/.fonts/SourceHanSerifSC-Regular.otf" >> $HOME/.blockdiagrc
# echo -e "\n[actdiag]\nfontpath = $HOME/.fonts/SourceHanSerifSC-Regular.otf" >> $HOME/.blockdiagrc
# echo -e "\n[nwdiag]\nfontpath = $HOME/.fonts/SourceHanSerifSC-Regular.otf" >> $HOME/.blockdiagrc
# ls -lh $HOME/.fonts
# fc-list
# cat $HOME/.blockdiagrc
- name: Improve Document 📝
run: |
cd docs
sed -i 's@xref:\([^\.]*\).adoc\[[^:]*\]@<<\1>>@g' *.adoc
cd ..
# 处理 sed 不支持非贪婪模式
# https://stackoverflow.com/a/46719361
# https://stackoverflow.com/a/1103159
- name: Build 🏗
run: mvn clean package -Pasciidoc
- name: Add Reward Qrcode 💰
run: |
cd target/docs/multipage/
find . -name "*.html" | grep -v 'preface.html' | xargs -I {} sed -i 's@\(<div id="content">\)@\1<div class="sect2"><h3 id="_友情支持">友情支持</h3><div class="paragraph"><p>如果您觉得这个笔记对您有所帮助,看在D瓜哥码这么多字的辛苦上,请友情支持一下,D瓜哥感激不尽,😜</p></div><table class="tableblock frame-none grid-all stretch"><colgroup><col style="width: 50%;"><col style="width: 50%;"></colgroup><tbody><tr><td class="tableblock halign-center valign-top"><p class="tableblock"><span class="image"><img src="assets/images/alipay.png" alt="支付宝" width="85%" title="支付宝"></span></p></td><td class="tableblock halign-center valign-top"><p class="tableblock"><span class="image"><img src="assets/images/wxpay.jpg" alt="微信" width="85%" title="微信"></span></p></td></tr></tbody></table><div class="paragraph"><p>有些打赏的朋友希望可以加个好友,欢迎关注D 瓜哥的微信公众号,这样就可以通过公众号的回复直接给我发信息。</p></div><div class="paragraph"><p><span class="image"><img src="assets/images/wx-jikerizhi.png" alt="wx jikerizhi" width="98%"></span></p></div><div class="admonitionblock tip"><table><tbody><tr><td class="icon"><i class="fa icon-tip" title="Tip"></i></td><td class="content"><strong>公众号的微信号是: <code>jikerizhi</code></strong>。<em>因为众所周知的原因,有时图片加载不出来。 如果图片加载不出来可以直接通过搜索微信号来查找我的公众号。</em></td></tr></tbody></table></div></div>@' {}
- name: Add Giscus 🗣️
run: |
cd target/docs/multipage/
# 📢 注意,有几个地方需要修改:
# 1. 仓库地址
# 2. 仓库 ID
# 3. 数据分类名称
# 4. 数据分类 ID
dataRepo='diguage/jdk-source-analysis'
dataRepoId='MDEwOlJlcG9zaXRvcnk3MjM5MzE5Mw=='
dataCategory='General'
dataCategoryId='MDE4OkRpc2N1c3Npb25DYXRlZ29yeTMyMDM2MDQx'
# 📢 注意,现在是提取文件名作为 Giscus 参数!请根据需要自定义 Giscus 参数。
for file in `find . -name "*.html"`;
do
#fileBaseName=$(basename -- "$file")
#fileName="${fileBaseName%.*}"
fileName=$(echo $file | sed 's|^\./||; s/\.html$//')
echo "$file → $fileName"
sed -i "s@\(<title>\)@<meta property=\"og:title\" content=\"${fileName}\">\n\1@" $file
sed -i -z "s@\(</div>\n<div id=\"footer\">\)@<script src=\"https://giscus.app/client.js\" data-repo=\"${dataRepo}\" data-repo-id=\"${dataRepoId}\" data-category=\"${dataCategory}\" data-category-id=\"${dataCategoryId}\" data-mapping=\"og:title\" data-strict=\"0\" data-reactions-enabled=\"1\" data-emit-metadata=\"1\" data-input-position=\"top\" data-theme=\"preferred_color_scheme\" data-lang=\"zh-CN\" data-loading=\"lazy\" crossorigin=\"anonymous\" async></script>\n\1@" $file
done
- name: Add Tab Resource 🌗
run: |
cp -R docs/assets target/docs/multipage/
cd target/docs/
find . -name "*.html" | xargs -I {} sed -i 's@src="asciidoctor-tabs.js"@src="assets/scripts/asciidoctor-tabs.js"@g' {}
- name: Add Scroll TOC JS 🐌
run: |
mkdir -p target/docs/multipage/assets/scripts/
touch target/docs/multipage/assets/scripts/scroll-toc.js
cat > target/docs/multipage/assets/scripts/scroll-toc.js <<- EOF
document.querySelector('#toc li a span.toc-current')
.scrollIntoView({ behavior: "smooth", block: "center", inline: "nearest" });
EOF
cd target/docs/multipage/
sed -i 's@</body>@<script src="assets/scripts/scroll-toc.js"></script></body>@g' *.html
sed -i 's@\(.toc-current{\)@\1color:#d14;font-size:130%;@g' *.html
- name: Rename Title 🤡
run: |
cd target/docs/multipage/
for file in ./*.html;
do
# https://ioflood.com/blog/bash-not-equal/
if [ "${file}" != "./index.html" ]; then
subtitle=$(grep '<h2.*></a>' $file | awk -F'>' '{print $4}' | awk -F'<' '{print $1}')
echo "$file -- $subtitle"
if [ "${subtitle}" != "" ]; then
# 将变量中的 & 替换为 \&
escaped_title=$(sed 's/&/\\&/g' <<< "${subtitle}")
sed -i "s@</h1>@: ${escaped_title}</h1>@g" $file
sed -i "s@</title>@: ${escaped_title}</title>@g" $file
fi
fi
done
# https://goalsmashers.github.io/css-minification-benchmark/
- name: Compress CSS 🍭
run: |
# https://github.com/parcel-bundler/lightningcss
npm install -g lightningcss-cli
# Multiple HTML page
cd target/docs/
for f in `find . -name "*.css"`;
do
if [[ $f == *asciidoctor.css ]]; then
# TODO 这里需要添加的 code 选择器可能更多
echo -e '\na{text-decoration:none;}p>code,strong>code{color: #d14 !important;background-color: #f5f5f5 !important;border: 1px solid #e1e1e8;}' >> $f
fi
fn="${f%.*}.min.css";
echo "compress $f"
lightningcss --minify --error-recovery --output-file $fn $f
rm -rf $f
mv $fn $f
done
# https://github.com/privatenumber/minification-benchmarks
- name: Compress JS 🐢
run: |
# https://github.com/mishoo/UglifyJS
npm install uglify-js -g
# Multiple HTML page
cd target/docs/
for f in `find . -name "*.js"`;
do
fn="${f%.*}.min.css";
echo "compress $f"
uglifyjs $f --compress --rename -o $fn
rm -rf $f;
mv $fn $f
done
- name: Add links for comments 🔗
run: |
cd target/docs/
for file in `find . -name "*.html"`;
do
sed -i 's@\(D瓜哥 · https://www.diguage.com\)@<a href="https://www.diguage.com" class="cmt-link" target="_blank">\1</a>@g' $file
done
# https://github.com/JamesIves/github-pages-deploy-action
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
# GITHUB_TOKEN: ${{ secrets.CI_TOKEN }}
branch: gh-pages # The branch the action should deploy to.
folder: target/docs/multipage # The folder the action should deploy.
single-commit: true