Skip to content

Commit 6510993

Browse files
committed
patch: tracking the official repo
Close #15
1 parent a13164c commit 6510993

2 files changed

Lines changed: 352 additions & 4 deletions

File tree

preprocess-zh.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,30 @@ do
1010
VERSION="${i#*=}"
1111
shift # past argument=value
1212
;;
13+
UPSTREAM=*)
14+
UPSTREAM="${i#*=}"
15+
shift # past argument=value
16+
;;
1317
*)
1418
# unknown option
1519
;;
1620
esac
1721
done
1822

1923
set -e
20-
git clone https://github.com/PeterFeicht/cppreference-doc.git --depth=1
21-
cd cppreference-doc
22-
git apply -3 ../zh.diff
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+
VERSION="${VERSION:-$(date +%Y%m%d)}"
36+
sed -i "/^VERSION=/cVERSION=${VERSION}" Makefile
2337
make source
2438

2539
# init files and vars
@@ -42,7 +56,6 @@ LIST="startup_scripts site_scripts site_modules skin_scripts ext"
4256
extra_fonts="DejaVuSans.ttf DejaVuSans-Bold.ttf DejaVuSansMono.ttf DejaVuSansMono-Bold.ttf"
4357

4458
_7Z="${_7Z:-$(which 7z)}"
45-
VERSION="${VERSION:-$(date +%Y%m%d)}"
4659
CPUS="$(cat /proc/cpuinfo | grep -c '^processor')"
4760

4861
# package un-processed files

zh-p12tic.diff

Lines changed: 335 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,335 @@
1+
From 8c67452b3c7b941b8d9155e49e79c39a898390f9 Mon Sep 17 00:00:00 2001
2+
From: myfreeer <myfreeer@users.noreply.github.com>
3+
Date: Fri, 12 Feb 2021 17:23:50 +0800
4+
Subject: [PATCH] source: use zh localized version
5+
6+
---
7+
Makefile | 56 ++++++++++++------------
8+
commands/preprocess.py | 16 +++----
9+
commands/preprocess_cssless.py | 4 +-
10+
gadgets/standard_revisions_tests/base.py | 2 +-
11+
gadgets/sync_tests_mwiki.py | 2 +-
12+
index2ddg.py | 4 +-
13+
index_transform/browser.py | 2 +-
14+
preprocess.py | 8 ++--
15+
tests/test_preprocess.py | 2 +-
16+
tests/test_preprocess_cssless.py | 2 +-
17+
10 files changed, 49 insertions(+), 49 deletions(-)
18+
19+
diff --git a/Makefile b/Makefile
20+
index 644e3a5..90a2c0b 100644
21+
--- a/Makefile
22+
+++ b/Makefile
23+
@@ -98,18 +98,18 @@ install: all
24+
-exec install -DT -m 644 '{}' "$(DESTDIR)$(docdir)/html/{}" \; ; \
25+
popd > /dev/null
26+
27+
- install -DT -m 644 "output/cppreference-doc-en-c.devhelp2" \
28+
- "$(DESTDIR)$(bookdir)/cppreference-doc-en-c/cppreference-doc-en-c.devhelp2"
29+
- install -DT -m 644 "output/cppreference-doc-en-cpp.devhelp2" \
30+
- "$(DESTDIR)$(bookdir)/cppreference-doc-en-cpp/cppreference-doc-en-cpp.devhelp2"
31+
+ install -DT -m 644 "output/cppreference-doc-zh-c.devhelp2" \
32+
+ "$(DESTDIR)$(bookdir)/cppreference-doc-zh-c/cppreference-doc-zh-c.devhelp2"
33+
+ install -DT -m 644 "output/cppreference-doc-zh-cpp.devhelp2" \
34+
+ "$(DESTDIR)$(bookdir)/cppreference-doc-zh-cpp/cppreference-doc-zh-cpp.devhelp2"
35+
install -DT -m 644 "output/cppreference-doxygen-local.tag.xml" \
36+
"$(DESTDIR)$(bookdir)/cppreference-doxygen-local.tag.xml"
37+
install -DT -m 644 "output/cppreference-doxygen-web.tag.xml" \
38+
"$(DESTDIR)$(bookdir)/cppreference-doxygen-web.tag.xml"
39+
40+
# install the .qch (Qt Help) documentation
41+
- install -DT -m 644 "output/cppreference-doc-en-cpp.qch" \
42+
- "$(DESTDIR)$(docdir)/qch/cppreference-doc-en-cpp.qch"
43+
+ install -DT -m 644 "output/cppreference-doc-zh-cpp.qch" \
44+
+ "$(DESTDIR)$(docdir)/qch/cppreference-doc-zh-cpp.qch"
45+
46+
uninstall:
47+
rm -rf "$(DESTDIR)$(docdir)"
48+
@@ -136,16 +136,16 @@ release: all
49+
50+
# zip qch
51+
pushd "output"; \
52+
- tar c$(TAR_OPTION)f "../release/qch-book-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-en-cpp.qch"; \
53+
- zip -qr "../release/qch-book-$(VERSION).zip" "cppreference-doc-en-cpp.qch"; \
54+
+ tar c$(TAR_OPTION)f "../release/qch-book-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-zh-cpp.qch"; \
55+
+ zip -qr "../release/qch-book-$(VERSION).zip" "cppreference-doc-zh-cpp.qch"; \
56+
popd
57+
58+
#WORKER RULES
59+
doc_html: output/reference
60+
61+
-doc_devhelp: output/cppreference-doc-en-c.devhelp2 output/cppreference-doc-en-cpp.devhelp2
62+
+doc_devhelp: output/cppreference-doc-zh-c.devhelp2 output/cppreference-doc-zh-cpp.devhelp2
63+
64+
-doc_qch: output/cppreference-doc-en-cpp.qch
65+
+doc_qch: output/cppreference-doc-zh-cpp.qch
66+
67+
doc_doxygen: output/cppreference-doxygen-web.tag.xml output/cppreference-doxygen-local.tag.xml
68+
69+
@@ -154,37 +154,37 @@ output/link-map.xml: output/reference
70+
./build_link_map.py
71+
72+
#build the .devhelp2 index
73+
-output/cppreference-doc-en-c.devhelp2: \
74+
+output/cppreference-doc-zh-c.devhelp2: \
75+
output/reference \
76+
output/link-map.xml
77+
./index2devhelp.py $(docdir)/html index-chapters-c.xml \
78+
- "C Standard Library reference" "cppreference-doc-en-c" "c" \
79+
+ "C Standard Library reference" "cppreference-doc-zh-c" "c" \
80+
index-functions-c.xml "output/devhelp-index-c.xml"
81+
./fix_devhelp-links.py "output/devhelp-index-c.xml" \
82+
- "output/cppreference-doc-en-c.devhelp2"
83+
+ "output/cppreference-doc-zh-c.devhelp2"
84+
85+
-output/cppreference-doc-en-cpp.devhelp2: \
86+
+output/cppreference-doc-zh-cpp.devhelp2: \
87+
output/reference \
88+
output/link-map.xml
89+
./index2devhelp.py $(docdir)/html index-chapters-cpp.xml \
90+
- "C++ Standard Library reference" "cppreference-doc-en-cpp" "cpp" \
91+
+ "C++ Standard Library reference" "cppreference-doc-zh-cpp" "cpp" \
92+
index-functions-cpp.xml "output/devhelp-index-cpp.xml"
93+
./fix_devhelp-links.py "output/devhelp-index-cpp.xml" \
94+
- "output/cppreference-doc-en-cpp.devhelp2"
95+
+ "output/cppreference-doc-zh-cpp.devhelp2"
96+
97+
#build the .qch (QT help) file
98+
-output/cppreference-doc-en-cpp.qch: output/qch-help-project-cpp.xml
99+
+output/cppreference-doc-zh-cpp.qch: output/qch-help-project-cpp.xml
100+
#qhelpgenerator only works if the project file is in the same directory as the documentation
101+
cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.qhp"
102+
103+
pushd "output/reference_cssless" > /dev/null; \
104+
- $(qhelpgenerator) "qch.qhp" -o "../cppreference-doc-en-cpp.qch"; \
105+
+ $(qhelpgenerator) "qch.qhp" -o "../cppreference-doc-zh-cpp.qch"; \
106+
popd > /dev/null
107+
108+
rm -f "output/reference_cssless/qch.qhp"
109+
110+
output/qch-help-project-cpp.xml: \
111+
- output/cppreference-doc-en-cpp.devhelp2 \
112+
+ output/cppreference-doc-zh-cpp.devhelp2 \
113+
output/reference_cssless
114+
#build the file list
115+
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><files>" > "output/qch-files.xml"
116+
@@ -197,7 +197,7 @@ output/qch-help-project-cpp.xml: \
117+
echo "</files>" >> "output/qch-files.xml"
118+
119+
#create the project (copies the file list)
120+
- ./devhelp2qch.py --src=output/cppreference-doc-en-cpp.devhelp2 \
121+
+ ./devhelp2qch.py --src=output/cppreference-doc-zh-cpp.devhelp2 \
122+
--dst=output/qch-help-project-cpp.xml \
123+
--virtual_folder=cpp --file_list=output/qch-files.xml
124+
125+
@@ -237,7 +237,7 @@ indexes:
126+
./index2autolinker.py index-functions-c.xml output/indexes/autolink-c
127+
./index2autolinker.py index-functions-cpp.xml output/indexes/autolink-cpp
128+
129+
-#redownloads the source documentation directly from en.cppreference.com
130+
+#redownloads the source documentation directly from zh.cppreference.com
131+
source:
132+
rm -rf "reference"
133+
mkdir "reference"
134+
@@ -246,15 +246,15 @@ source:
135+
regex=".*index\\.php.*|.*/Special:.*|.*/Talk:.*" \
136+
regex+="|.*/Help:.*|.*/File:.*|.*/Cppreference:.*" \
137+
regex+="|.*/WhatLinksHere:.*|.*/Template:.*|.*/Category:.*" \
138+
- regex+="|.*action=.*|.*printable=.*|.*en.cppreference.com/book.*" ; \
139+
+ regex+="|.*action=.*|.*printable=.*|.*zh.cppreference.com/book.*" ; \
140+
echo $$regex ; \
141+
wget --adjust-extension --page-requisites --convert-links \
142+
- --force-directories --recursive --level=15 \
143+
- --span-hosts --domains=en.cppreference.com,upload.cppreference.com \
144+
+ --force-directories --recursive --level=17 -e robots=off \
145+
+ --span-hosts --domains=zh.cppreference.com,upload.cppreference.com \
146+
--reject-regex $$regex \
147+
- --timeout=5 --tries=50 --no-verbose \
148+
- --retry-connrefused --waitretry=10 --read-timeout=20 \
149+
- http://en.cppreference.com/w/ ; \
150+
+ --timeout=5 --tries=180 --no-verbose \
151+
+ --retry-connrefused --waitretry=5 --read-timeout=15 \
152+
+ https://zh.cppreference.com/w/ ; \
153+
popd > /dev/null
154+
155+
- ./export.py --url=https://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
156+
+ ./export.py --url=https://zh.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
157+
diff --git a/commands/preprocess.py b/commands/preprocess.py
158+
index 45682f5..c71fb56 100644
159+
--- a/commands/preprocess.py
160+
+++ b/commands/preprocess.py
161+
@@ -42,23 +42,23 @@ def rearrange_archive(root):
162+
# rearrange the archive. {root} here is output/reference
163+
164+
# before
165+
- # {root}/en.cppreference.com/w/ : html
166+
- # {root}/en.cppreference.com/mwiki/ : data
167+
- # {root}/en.cppreference.com/ : data
168+
+ # {root}/zh.cppreference.com/w/ : html
169+
+ # {root}/zh.cppreference.com/mwiki/ : data
170+
+ # {root}/zh.cppreference.com/ : data
171+
# ... (other languages)
172+
# {root}/upload.cppreference.com/mwiki/ : data
173+
174+
# after
175+
# {root}/common/ : all common data
176+
- # {root}/en/ : html for en
177+
+ # {root}/zh/ : html for zh
178+
# ... (other languages)
179+
180+
data_path = os.path.join(root, 'common')
181+
rmtree_if_exists(data_path)
182+
shutil.move(os.path.join(root, 'upload.cppreference.com/mwiki'), data_path)
183+
- shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
184+
+ shutil.rmtree(os.path.join(root, 'upload.cppreference.com'), ignore_errors=True)
185+
186+
- for lang in ["en"]:
187+
+ for lang in ["zh"]:
188+
path = os.path.join(root, lang + ".cppreference.com/")
189+
src_html_path = path + "w/"
190+
src_data_path = path + "mwiki/"
191+
@@ -79,7 +79,7 @@ def rearrange_archive(root):
192+
data_path)
193+
194+
# remove what's left
195+
- shutil.rmtree(path)
196+
+ # shutil.rmtree(path)
197+
198+
# remove the XML source file
199+
for fn in fnmatch.filter(os.listdir(root), 'cppreference-export*.xml'):
200+
@@ -355,7 +355,7 @@ def remove_unused_external(html):
201+
202+
203+
def preprocess_html_file(root, fn, rename_map):
204+
- parser = etree.HTMLParser()
205+
+ parser = etree.HTMLParser(encoding="utf-8")
206+
html = etree.parse(fn, parser)
207+
output = io.StringIO()
208+
209+
diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py
210+
index e6f9e02..11170e3 100644
211+
--- a/commands/preprocess_cssless.py
212+
+++ b/commands/preprocess_cssless.py
213+
@@ -29,9 +29,9 @@ from premailer import Premailer
214+
215+
216+
def preprocess_html_merge_cssless(src_path, dst_path):
217+
- with open(src_path, 'r') as a_file:
218+
+ with open(src_path, 'r', encoding='utf-8') as a_file:
219+
content = a_file.read()
220+
- parser = etree.HTMLParser()
221+
+ parser = etree.HTMLParser(encoding="utf-8")
222+
stripped = content.strip()
223+
root = etree.fromstring(stripped, parser)
224+
225+
diff --git a/gadgets/standard_revisions_tests/base.py b/gadgets/standard_revisions_tests/base.py
226+
index 8b1269c..43863ee 100644
227+
--- a/gadgets/standard_revisions_tests/base.py
228+
+++ b/gadgets/standard_revisions_tests/base.py
229+
@@ -25,7 +25,7 @@ from selenium.webdriver.support.ui import Select
230+
231+
class Driver:
232+
def __init__(self):
233+
- base_url = "http://en.cppreference.com/"
234+
+ base_url = "https://zh.cppreference.com/"
235+
driver = webdriver.Firefox()
236+
driver.implicitly_wait(30)
237+
try:
238+
diff --git a/gadgets/sync_tests_mwiki.py b/gadgets/sync_tests_mwiki.py
239+
index b9e1337..41eae97 100755
240+
--- a/gadgets/sync_tests_mwiki.py
241+
+++ b/gadgets/sync_tests_mwiki.py
242+
@@ -114,7 +114,7 @@ def perform_sync(url, direction, dest_root, title_filter, user, password,
243+
# Supply information to config that would otherwise be defined in
244+
# user-config.py
245+
pywikibot.config2.family = 'cppreference'
246+
- pywikibot.config2.mylang = 'en'
247+
+ pywikibot.config2.mylang = 'zh'
248+
pywikibot.config2.family_files['cppreference'] = url
249+
pywikibot.config2.step = 100
250+
pywikibot.config2.put_throttle = 0
251+
diff --git a/index2ddg.py b/index2ddg.py
252+
index 71d15ed..a22ccf1 100755
253+
--- a/index2ddg.py
254+
+++ b/index2ddg.py
255+
@@ -467,7 +467,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
256+
abstract = abstract.replace('\n', '\\n')
257+
line += abstract + '\t'
258+
# source url
259+
- line += 'http://en.cppreference.com/w/' + link + '\n'
260+
+ line += 'https://zh.cppreference.com/w/' + link + '\n'
261+
out.write(line)
262+
263+
build_redirects(redirects, item_ident, item_type)
264+
@@ -582,7 +582,7 @@ def main():
265+
# i+=1
266+
267+
root = e.parse(os.path.join(args.reference, fn),
268+
- parser=html.HTMLParser())
269+
+ parser=html.HTMLParser(encoding="utf-8"))
270+
271+
for ident in idents:
272+
273+
diff --git a/index_transform/browser.py b/index_transform/browser.py
274+
index fb8b976..e9657a4 100644
275+
--- a/index_transform/browser.py
276+
+++ b/index_transform/browser.py
277+
@@ -48,7 +48,7 @@ class Index2Browser(IndexTransform):
278+
res = u''
279+
res += '<tt><b>{0}</b></tt> [<span class="link">'.format(
280+
xml_escape(full_name))
281+
- res += '<a href="http://en.cppreference.com/w/{0}">'.format(
282+
+ res += '<a href="https://zh.cppreference.com/w/{0}">'.format(
283+
xml_escape(full_link))
284+
res += '{0}</a></span>] <span class="mark">{1}</span>\n'.format(
285+
full_link, mark)
286+
diff --git a/preprocess.py b/preprocess.py
287+
index 65e73d6..16e3d16 100755
288+
--- a/preprocess.py
289+
+++ b/preprocess.py
290+
@@ -36,12 +36,12 @@ def main():
291+
help='Destination folder to put preprocessed archive to')
292+
args = parser.parse_args()
293+
294+
- root = args.dst
295+
- src = args.src
296+
+ root = args.src
297+
+ # src = args.src
298+
299+
# copy the source tree
300+
- preprocess.rmtree_if_exists(root)
301+
- shutil.copytree(src, root)
302+
+ # rmtree_if_exists(root)
303+
+ # shutil.copytree(src, root)
304+
305+
preprocess.rearrange_archive(root)
306+
307+
diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py
308+
index 3c0c952..b8d03d2 100644
309+
--- a/tests/test_preprocess.py
310+
+++ b/tests/test_preprocess.py
311+
@@ -258,7 +258,7 @@ class TestPreprocessHtml(unittest.TestCase):
312+
self.testdata = os.path.join(os.path.dirname(__file__),
313+
'preprocess_data')
314+
infile = os.path.join(self.testdata, "fabs.html")
315+
- self.parser = etree.HTMLParser()
316+
+ self.parser = etree.HTMLParser(encoding="utf-8")
317+
self.html = etree.parse(infile, self.parser)
318+
319+
# Check whether the HTML matches the contents of the specified test data
320+
diff --git a/tests/test_preprocess_cssless.py b/tests/test_preprocess_cssless.py
321+
index 64864cc..b48628b 100644
322+
--- a/tests/test_preprocess_cssless.py
323+
+++ b/tests/test_preprocess_cssless.py
324+
@@ -83,7 +83,7 @@ class HTMLTestBase(unittest.TestCase):
325+
expected_output = \
326+
'<html><body>{0}</body></html>'.format(expected_output)
327+
328+
- parser = etree.HTMLParser()
329+
+ parser = etree.HTMLParser(encoding="utf-8")
330+
root = etree.fromstring(input, parser)
331+
332+
root = function(root)
333+
--
334+
2.30.0
335+

0 commit comments

Comments
 (0)