-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-platform-specific.sh
executable file
·124 lines (100 loc) · 2.78 KB
/
build-platform-specific.sh
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
#!/bin/sh
# === Build for copying to other platform only ===
#
# It looks like gitee no longer support external access with refer
# --repo [email protected]:drdrxp/bed.git@openacid-$platform-import-assets \
set -o errexit
# for example:
# https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev/2023-12-17-openraft-read.html
url_base="https://pub-e254240c5c35410cb21a0cf4fb58f73e.r2.dev"
# Call xp-md2html to convert md to html, using github-markdown.css
# xp-md2html is a personal repo
md2html()
{
local src_path="$1"
local output_path="$2"
# TODO: add original link
{
cat <<-END
<!doctype html>
<html>
<head>
<meta charset='UTF-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="github-markdown.css">
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</style>
</head>
<body>
<article class="markdown-body">
END
cat "$src_path" | xp-md2html
cat <<-END
<img src="qrcode-hori.jpg" />
</article>
</body>
</html>
END
} > "$output_path"
}
build()
{
local platform="$1"
local fn="$2"
local name_suffix=${fn##*/}
local name=${name_suffix%.md}
# remove date
local title=${name#20??-??-??-}
echo ""
echo "fn: $fn"
echo "name: $name"
echo "title: $title"
echo ""
# Build local markdown
mkdir -p md2-local
# reference local resource
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name-$platform.md \
$fn
# reference remote resource
md2zhihu \
--platform $platform \
--code-width 600 \
--refs _data/refs.yml \
--output-dir ./md2-local \
--asset-output-dir ./md2-local/ \
--md-output ./md2-local/$name-$platform-remote.md \
--rewrite "^$title/" "$url_base/$title/" \
$fn
cp assets/images/qrcode-hori.jpg ./md2-local/
cp assets/css/github-markdown.css ./md2-local/
# Build html
md2html "./md2-local/$name-$platform.md" "./md2-local/$name-$platform.html"
md2html "./md2-local/$name-$platform-remote.md" "./md2-local/$name-$platform-remote.html"
# Upload
aws s3 sync ./md2-local/ s3://bed/
echo "Built online md:"
echo ""
echo " $url_base/$name-$platform.html"
echo " $url_base/$name-$platform-remote.html"
echo ""
}
build "wechat" _src/openraft-read/2023-12-17-openraft-read.md
build "wechat" _src/openraft-read/raft-read-proof.md