|
1 |
| -#!/bin/bash |
2 |
| -for i in "$@" |
3 |
| -do |
4 |
| - case $i in |
5 |
| - _7Z=*) |
6 |
| - _7Z="${i#*=}" |
7 |
| - shift # past argument=value |
8 |
| - ;; |
9 |
| - VERSION=*) |
10 |
| - VERSION="${i#*=}" |
11 |
| - shift # past argument=value |
12 |
| - ;; |
13 |
| - UPSTREAM=*) |
14 |
| - UPSTREAM="${i#*=}" |
15 |
| - shift # past argument=value |
16 |
| - ;; |
17 |
| - *) |
18 |
| - # unknown option |
19 |
| - ;; |
20 |
| - esac |
21 |
| -done |
22 |
| - |
23 |
| -set -e |
24 |
| - |
25 |
| -if [[ "${UPSTREAM}" = "p12tic" ]]; then |
26 |
| - git clone https://github.com/p12tic/cppreference-doc.git --depth=1 |
27 |
| - cd cppreference-doc |
28 |
| - git apply -3 ../zh-p12tic.diff |
29 |
| -else |
30 |
| - git clone https://github.com/PeterFeicht/cppreference-doc.git --depth=1 |
31 |
| - cd cppreference-doc |
32 |
| - git apply -3 ../zh.diff |
33 |
| -fi |
34 |
| - |
35 |
| -git apply -3 ../preprocess_cssless.diff |
36 |
| - |
37 |
| -VERSION="${VERSION:-$(date +%Y%m%d)}" |
38 |
| -sed -i "/^VERSION=/cVERSION=${VERSION}" Makefile |
39 |
| -make source |
40 |
| - |
41 |
| - |
42 |
| -# init files and vars |
43 |
| -startup_scripts_replace="startup_scripts.js" |
44 |
| -startup_scripts_path="$(find | grep -iP 'load\.php.*?modules=startup&only=scripts.*?' | head -1)" |
45 |
| - |
46 |
| -site_scripts_replace="site_scripts.js" |
47 |
| -site_scripts_path="$(find | grep -iP 'load\.php.*?modules=site&only=scripts.*?' | head -1)" |
48 |
| - |
49 |
| -site_modules_replace="site_modules.css" |
50 |
| -site_modules_path="$(find | grep -iP 'load\.php.*?modules=site&only=styles.*?' | head -1)" |
51 |
| - |
52 |
| -skin_scripts_replace="skin_scripts.js" |
53 |
| -skin_scripts_path="$(find | grep -iP 'load\.php.*?modules=skins.*&only=scripts.*?' | head -1)" |
54 |
| - |
55 |
| -ext_replace="ext.css" |
56 |
| -ext_path="$(find | grep -iP 'load\.php.*?modules=.*ext.*&only=styles.*?' | head -1)" |
57 |
| - |
58 |
| -LIST="startup_scripts site_scripts site_modules skin_scripts ext" |
59 |
| -extra_fonts="DejaVuSans.ttf DejaVuSans-Bold.ttf DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf" |
60 |
| - |
61 |
| -_7Z="${_7Z:-$(which 7z)}" |
62 |
| -CPUS="$(cat /proc/cpuinfo | grep -c '^processor')" |
63 |
| - |
64 |
| -# package un-processed files |
65 |
| -"${_7Z}" a -mx9 -myx9 -mqs "../cppreference-unprocessed-${VERSION}.7z" ./reference |
66 |
| -tar caf "../cppreference-unprocessed-${VERSION}.tar.xz" reference |
67 |
| -#rm -rf ./reference |
68 |
| -#"${_7Z}" x ../cppreference-unprocessed-20210212.7z |
69 |
| - |
70 |
| -# https://gist.github.com/cdown/1163649/8a35c36fdd24b373788a7057ed483a5bcd8cd43e |
71 |
| -url_encode() { |
72 |
| - local _length="${#1}" |
73 |
| - for (( _offset = 0 ; _offset < _length ; _offset++ )); do |
74 |
| - _print_offset="${1:_offset:1}" |
75 |
| - case "${_print_offset}" in |
76 |
| - [a-zA-Z0-9.~_-]) printf "${_print_offset}" ;; |
77 |
| - ' ') printf + ;; |
78 |
| - *) printf '%%%X' "'${_print_offset}" ;; |
79 |
| - esac |
80 |
| - done |
81 |
| -} |
82 |
| - |
83 |
| -copy_file(){ |
84 |
| - local var=$1 |
85 |
| - local path="$(eval echo "\${${var}_path}")" |
86 |
| - local replace="$(eval echo "\${${var}_replace}")" |
87 |
| - local dir="$(dirname "${path}")" |
88 |
| - cp -f -T "${path}" "${dir}/${replace}" |
89 |
| -} |
90 |
| - |
91 |
| -remove_file(){ |
92 |
| - local var=$1 |
93 |
| - local path="$(eval echo "\${${var}_path}")" |
94 |
| - local name="$(basename "${path}")" |
95 |
| - find -iname "${name}" | xargs rm -f |
96 |
| -} |
97 |
| - |
98 |
| -replace_in_html(){ |
99 |
| - local var=$1 |
100 |
| - local path="$(eval echo "\${${var}_path}")" |
101 |
| - local replace="$(eval echo "\${${var}_replace}")" |
102 |
| - local name="$(basename "${path}")" |
103 |
| - local encoded_name="$(url_encode "${name}")" |
104 |
| - find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/${name}/${replace}/gi" |
105 |
| - find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/${encoded_name}/${replace}/gi" |
106 |
| -} |
107 |
| - |
108 |
| -echo pre-processing... |
109 |
| -for i in $LIST; do copy_file $i; done |
110 |
| - |
111 |
| -# backup extra fonts |
112 |
| -mkdir -p font_temp |
113 |
| -for i in $extra_fonts; do |
114 |
| - find -iname $i -exec cp {} font_temp/$i \; |
115 |
| -done |
116 |
| - |
117 |
| -# original preprocess |
118 |
| -make doc_html |
119 |
| - |
120 |
| -# restore extra fonts |
121 |
| -if [[ -d 'reference/common' ]]; then |
122 |
| - font_path='reference/common' |
123 |
| -elif [[ -d 'output/common' ]]; then |
124 |
| - font_path='output/common' |
125 |
| -fi |
126 |
| -if [[ -d $font_path ]]; then |
127 |
| -for i in $extra_fonts; do |
128 |
| - cp -f font_temp/$i $font_path/$i |
129 |
| -done |
130 |
| -fi |
131 |
| -rm -rf font_temp |
132 |
| - |
133 |
| -find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/ - cppreference.com//g" |
134 |
| - |
135 |
| -echo post-processing... |
136 |
| -for i in $LIST; do |
137 |
| - echo processing $i |
138 |
| - remove_file $i |
139 |
| - replace_in_html $i |
140 |
| -done |
141 |
| - |
142 |
| -find -iname "${startup_scripts_replace}" | xargs sed -i 's/document\.write/void /ig' |
143 |
| -find -iname "${site_scripts_replace}" | xargs sed -i '1 i if(window.mw)' |
144 |
| -find -iname "${skin_scripts_replace}" | xargs sed -i '1 i if(window.mw)' |
145 |
| -find -iname '*.css' | xargs sed -i -r 's/\.\.\/([^.]+?)\.ttf/\1.ttf/ig' |
146 |
| - |
147 |
| -# workaround navbar-inv-tab.png |
148 |
| -find -iname '*.css' | xargs sed -i -r 's/https?:\/\/..\.cppreference\.com\/mwiki\/skins\/cppreference2\/images/skins\/cppreference2\/images/ig' |
149 |
| -pushd "${font_path}/skins/cppreference2/images" |
150 |
| -wget -nv 'https://en.cppreference.com/mwiki/skins/cppreference2/images/navbar-inv-tab.png' |
151 |
| -popd |
152 |
| -echo Cleaning up carbonads scripts |
153 |
| -find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i -r 's/<script.+?carbonads\.com\/carbon\.js.+?<\/script>//ig' |
154 |
| -echo Done. |
155 |
| - |
156 |
| -rm -rf 'reference/zh.cppreference.com' |
157 |
| - |
158 |
| -# build doc_devhelp doc_doxygen |
159 |
| -mkdir -p output |
160 |
| -mv -f reference output/ |
161 |
| -make doc_doxygen doc_devhelp |
162 |
| - |
163 |
| -# package processed files |
164 |
| -cd output |
165 |
| -"${_7Z}" a -mx9 -myx9 -mqs "../../html-book-${VERSION}.7z" ./reference cppreference-doc-zh-c.devhelp2 cppreference-doc-zh-cpp.devhelp2 cppreference-doxygen-web.tag.xml cppreference-doxygen-local.tag.xml devhelp-index-c.xml devhelp-index-cpp.xml link-map.xml |
166 |
| -tar caf "../../html-book-${VERSION}.tar.xz" reference cppreference-doc-zh-c.devhelp2 cppreference-doc-zh-cpp.devhelp2 cppreference-doxygen-web.tag.xml cppreference-doxygen-local.tag.xml devhelp-index-c.xml devhelp-index-cpp.xml link-map.xml |
167 |
| -cd .. |
168 |
| - |
169 |
| -# build qch book |
170 |
| -make doc_qch |
171 |
| -"${_7Z}" a -mx9 -myx9 -mqs "../qch-book-${VERSION}.7z" ./output/*.qch |
172 |
| -tar caf "../qch-book-${VERSION}.tar.xz" ./output/*.qch |
173 |
| - |
174 |
| -# move processed files to parent folder |
175 |
| -# for make_chm.sh |
176 |
| -mv -f output/reference/* ../ |
177 |
| -cd .. |
178 |
| - |
179 |
| -set +e |
| 1 | +#!/bin/bash |
| 2 | +for i in "$@" |
| 3 | +do |
| 4 | + case $i in |
| 5 | + _7Z=*) |
| 6 | + _7Z="${i#*=}" |
| 7 | + shift # past argument=value |
| 8 | + ;; |
| 9 | + VERSION=*) |
| 10 | + VERSION="${i#*=}" |
| 11 | + shift # past argument=value |
| 12 | + ;; |
| 13 | + UPSTREAM=*) |
| 14 | + UPSTREAM="${i#*=}" |
| 15 | + shift # past argument=value |
| 16 | + ;; |
| 17 | + *) |
| 18 | + # unknown option |
| 19 | + ;; |
| 20 | + esac |
| 21 | +done |
| 22 | + |
| 23 | +set -e |
| 24 | + |
| 25 | +if [[ "${UPSTREAM}" = "p12tic" ]]; then |
| 26 | + git clone https://github.com/p12tic/cppreference-doc.git --depth=1 |
| 27 | + cd cppreference-doc |
| 28 | + git apply -3 ../zh-p12tic.diff |
| 29 | +else |
| 30 | + git clone https://github.com/PeterFeicht/cppreference-doc.git --depth=1 |
| 31 | + cd cppreference-doc |
| 32 | + git apply -3 ../zh.diff |
| 33 | +fi |
| 34 | + |
| 35 | +git apply -3 ../preprocess_cssless.diff |
| 36 | + |
| 37 | +VERSION="${VERSION:-$(date +%Y%m%d)}" |
| 38 | +sed -i "/^VERSION=/cVERSION=${VERSION}" Makefile |
| 39 | +make source |
| 40 | + |
| 41 | + |
| 42 | +# init files and vars |
| 43 | +startup_scripts_replace="startup_scripts.js" |
| 44 | +startup_scripts_path="$(find | grep -iP 'load\.php.*?modules=startup&only=scripts.*?' | head -1)" |
| 45 | + |
| 46 | +site_scripts_replace="site_scripts.js" |
| 47 | +site_scripts_path="$(find | grep -iP 'load\.php.*?modules=site&only=scripts.*?' | head -1)" |
| 48 | + |
| 49 | +site_modules_replace="site_modules.css" |
| 50 | +site_modules_path="$(find | grep -iP 'load\.php.*?modules=site&only=styles.*?' | head -1)" |
| 51 | + |
| 52 | +skin_scripts_replace="skin_scripts.js" |
| 53 | +skin_scripts_path="$(find | grep -iP 'load\.php.*?modules=skins.*&only=scripts.*?' | head -1)" |
| 54 | + |
| 55 | +ext_replace="ext.css" |
| 56 | +ext_path="$(find | grep -iP 'load\.php.*?modules=.*ext.*&only=styles.*?' | head -1)" |
| 57 | + |
| 58 | +LIST="startup_scripts site_scripts site_modules skin_scripts ext" |
| 59 | +extra_fonts="DejaVuSans.ttf DejaVuSans-Bold.ttf DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf DejaVuSansMonoCondensed60.ttf DejaVuSansMonoCondensed75.ttf" |
| 60 | + |
| 61 | +_7Z="${_7Z:-$(which 7z)}" |
| 62 | +CPUS="$(cat /proc/cpuinfo | grep -c '^processor')" |
| 63 | + |
| 64 | +# package un-processed files |
| 65 | +"${_7Z}" a -mx9 -myx9 -mqs "../cppreference-unprocessed-${VERSION}.7z" ./reference |
| 66 | +tar caf "../cppreference-unprocessed-${VERSION}.tar.xz" reference |
| 67 | +#rm -rf ./reference |
| 68 | +#"${_7Z}" x ../cppreference-unprocessed-20210212.7z |
| 69 | + |
| 70 | +# https://gist.github.com/cdown/1163649/8a35c36fdd24b373788a7057ed483a5bcd8cd43e |
| 71 | +url_encode() { |
| 72 | + local _length="${#1}" |
| 73 | + for (( _offset = 0 ; _offset < _length ; _offset++ )); do |
| 74 | + _print_offset="${1:_offset:1}" |
| 75 | + case "${_print_offset}" in |
| 76 | + [a-zA-Z0-9.~_-]) printf "${_print_offset}" ;; |
| 77 | + ' ') printf + ;; |
| 78 | + *) printf '%%%X' "'${_print_offset}" ;; |
| 79 | + esac |
| 80 | + done |
| 81 | +} |
| 82 | + |
| 83 | +copy_file(){ |
| 84 | + local var=$1 |
| 85 | + local path="$(eval echo "\${${var}_path}")" |
| 86 | + local replace="$(eval echo "\${${var}_replace}")" |
| 87 | + local dir="$(dirname "${path}")" |
| 88 | + cp -f -T "${path}" "${dir}/${replace}" |
| 89 | +} |
| 90 | + |
| 91 | +remove_file(){ |
| 92 | + local var=$1 |
| 93 | + local path="$(eval echo "\${${var}_path}")" |
| 94 | + local name="$(basename "${path}")" |
| 95 | + find -iname "${name}" | xargs rm -f |
| 96 | +} |
| 97 | + |
| 98 | +replace_in_html(){ |
| 99 | + local var=$1 |
| 100 | + local path="$(eval echo "\${${var}_path}")" |
| 101 | + local replace="$(eval echo "\${${var}_replace}")" |
| 102 | + local name="$(basename "${path}")" |
| 103 | + local encoded_name="$(url_encode "${name}")" |
| 104 | + find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/${name}/${replace}/gi" |
| 105 | + find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/${encoded_name}/${replace}/gi" |
| 106 | +} |
| 107 | + |
| 108 | +echo pre-processing... |
| 109 | +for i in $LIST; do copy_file $i; done |
| 110 | + |
| 111 | +# backup extra fonts |
| 112 | +mkdir -p font_temp |
| 113 | +for i in $extra_fonts; do |
| 114 | + find -iname $i -exec cp {} font_temp/$i \; |
| 115 | +done |
| 116 | + |
| 117 | +# original preprocess |
| 118 | +make doc_html |
| 119 | + |
| 120 | +# restore extra fonts |
| 121 | +if [[ -d 'reference/common' ]]; then |
| 122 | + font_path='reference/common' |
| 123 | +elif [[ -d 'output/common' ]]; then |
| 124 | + font_path='output/common' |
| 125 | +fi |
| 126 | +if [[ -d $font_path ]]; then |
| 127 | +for i in $extra_fonts; do |
| 128 | + cp -f font_temp/$i $font_path/$i |
| 129 | +done |
| 130 | +fi |
| 131 | +rm -rf font_temp |
| 132 | + |
| 133 | +find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i "s/ - cppreference.com//g" |
| 134 | + |
| 135 | +echo post-processing... |
| 136 | +for i in $LIST; do |
| 137 | + echo processing $i |
| 138 | + remove_file $i |
| 139 | + replace_in_html $i |
| 140 | +done |
| 141 | + |
| 142 | +find -iname "${startup_scripts_replace}" | xargs sed -i 's/document\.write/void /ig' |
| 143 | +find -iname "${site_scripts_replace}" | xargs sed -i '1 i if(window.mw)' |
| 144 | +find -iname "${skin_scripts_replace}" | xargs sed -i '1 i if(window.mw)' |
| 145 | +find -iname '*.css' | xargs sed -i -r 's/\.\.\/([^.]+?)\.ttf/\1.ttf/ig' |
| 146 | + |
| 147 | +# workaround navbar-inv-tab.png |
| 148 | +find -iname '*.css' | xargs sed -i -r 's/https?:\/\/..\.cppreference\.com\/mwiki\/skins\/cppreference2\/images/skins\/cppreference2\/images/ig' |
| 149 | +pushd "${font_path}/skins/cppreference2/images" |
| 150 | +wget -nv 'https://en.cppreference.com/mwiki/skins/cppreference2/images/navbar-inv-tab.png' |
| 151 | +popd |
| 152 | +echo Cleaning up carbonads scripts |
| 153 | +find ./ -iname '*.html' -type f | xargs -P "${CPUS}" sed -i -r 's/<script.+?carbonads\.com\/carbon\.js.+?<\/script>//ig' |
| 154 | +echo Done. |
| 155 | + |
| 156 | +rm -rf 'reference/zh.cppreference.com' |
| 157 | + |
| 158 | +# build doc_devhelp doc_doxygen |
| 159 | +mkdir -p output |
| 160 | +mv -f reference output/ |
| 161 | +make doc_doxygen doc_devhelp |
| 162 | + |
| 163 | +# package processed files |
| 164 | +cd output |
| 165 | +"${_7Z}" a -mx9 -myx9 -mqs "../../html-book-${VERSION}.7z" ./reference cppreference-doc-zh-c.devhelp2 cppreference-doc-zh-cpp.devhelp2 cppreference-doxygen-web.tag.xml cppreference-doxygen-local.tag.xml devhelp-index-c.xml devhelp-index-cpp.xml link-map.xml |
| 166 | +tar caf "../../html-book-${VERSION}.tar.xz" reference cppreference-doc-zh-c.devhelp2 cppreference-doc-zh-cpp.devhelp2 cppreference-doxygen-web.tag.xml cppreference-doxygen-local.tag.xml devhelp-index-c.xml devhelp-index-cpp.xml link-map.xml |
| 167 | +cd .. |
| 168 | + |
| 169 | +# build qch book |
| 170 | +make doc_qch |
| 171 | +"${_7Z}" a -mx9 -myx9 -mqs "../qch-book-${VERSION}.7z" ./output/*.qch |
| 172 | +tar caf "../qch-book-${VERSION}.tar.xz" ./output/*.qch |
| 173 | + |
| 174 | +# move processed files to parent folder |
| 175 | +# for make_chm.sh |
| 176 | +mv -f output/reference/* ../ |
| 177 | +cd .. |
| 178 | + |
| 179 | +set +e |
0 commit comments