forked from myfreeer/cppreference2mshelp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_chm.sh
executable file
·86 lines (73 loc) · 2.91 KB
/
make_chm.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
#!/bin/bash
for i in "$@"
do
case $i in
PHP=*)
PHP="${i#*=}"
shift # past argument=value
;;
ICONV=*)
ICONV="${i#*=}"
shift # past argument=value
;;
HHC=*)
HHC="${i#*=}"
shift # past argument=value
;;
_7Z=*)
_7Z="${i#*=}"
shift # past argument=value
;;
VERSION=*)
VERSION="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
esac
done
PHP="${PHP:-$(which php)}"
ICONV="${ICONV:-$(which iconv)}"
HHC="${HHC:-$(which hhc)}"
_7Z="${_7Z:-$(which 7z)}"
VERSION="${VERSION:-$(date +%Y%m%d)}"
CPUS="$(cat /proc/cpuinfo | grep -c '^processor')"
# 在执行下一步之前,移动reference或output目录下文件到当前目录
rm -rf chmhelp
# 防止loadHTMLFile乱码
find -iname '*.html' | xargs -P "${CPUS}" sed -i 's/<head>/<head><meta charset="utf-8">/ig'
# 生成用于打包chm的文件
"${PHP}" make_chm.php
# 设置ie兼容性,使样式正确显示
cd chmhelp
find -iname '*.html' | xargs -P "${CPUS}" sed -i 's/<head>/<head><meta http-equiv="x-ua-compatible" content="ie=edge">/ig'
cd ..
# width hack
sed -i -e 's/ − <a href="cpp-thread-condition_variable.html">/<br><a href="cpp-thread-condition_variable.html">/' -e 's/ − <a href="cpp-memory-shared_ptr.html">/<br><a href="cpp-memory-shared_ptr.html">/' chmhelp/index.html
mkdir -p chm_temp
for i in cppreference.{hhc,hhk,hhp}; do
sed -i '/chmhelp\\首页.html/d' "${i}"
mv "${i}" "chm_temp/${i}"
"${ICONV}" -c -f UTF-8 -t GBK "chm_temp/${i}" > "${i}"
done
rm -rf chm_temp
sed "s/cppreference\.chm/cppreference-zh-${VERSION}\.chm/" cppreference.hhp > "cppreference-zh-${VERSION}.hhp"
# Compile and package UTF-8 version
"${HHC}" "cppreference-zh-${VERSION}.hhp"
"${_7Z}" a -mx9 "cppreference-zh-${VERSION}-chm-project.7z" "cppreference-zh-${VERSION}.hhp" cppreference.{hhc,hhk} hh{a.dll,c.exe} chmhelp/*
tar caf "cppreference-zh-${VERSION}-chm-project.tar.xz" "cppreference-zh-${VERSION}.hhp" cppreference.{hhc,hhk} hh{a.dll,c.exe} chmhelp/*
# Convert HTML to GBK
mv chmhelp chmhelp1
mkdir -p chmhelp
cd chmhelp1
find -iname '*.html' | xargs -P "${CPUS}" sed -i 's/<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>/<meta http-equiv="Content-Type" content="text\/html; charset=gbk" \/>/'
ls | grep .html | xargs -P "${CPUS}" -I {} sh -c "${ICONV} -c -f UTF-8 -t GBK '{}' > '../chmhelp/{}'"
cp -n ./* ../chmhelp/
cd ..
rm -rf chmhelp1
sed "s/cppreference\.chm/cppreference-zh-${VERSION}-gbk\.chm/" cppreference.hhp > "cppreference-zh-${VERSION}-gbk.hhp"
# Compile and package GBK version
"${HHC}" "cppreference-zh-${VERSION}-gbk.hhp"
"${_7Z}" a -mx9 "cppreference-zh-${VERSION}-chm-project-gbk.7z" "cppreference-zh-${VERSION}-gbk.hhp" cppreference.{hhc,hhk} hh{a.dll,c.exe} chmhelp/*
tar caf "cppreference-zh-${VERSION}-chm-project-gbk.tar.xz" "cppreference-zh-${VERSION}-gbk.hhp" cppreference.{hhc,hhk} hh{a.dll,c.exe} chmhelp/*