forked from myfreeer/cppreference2mshelp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzh.diff
More file actions
386 lines (331 loc) · 16.6 KB
/
zh.diff
File metadata and controls
386 lines (331 loc) · 16.6 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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
From 5939fd0b80d765a6572d9560b36c8223da53ce6b Mon Sep 17 00:00:00 2001
From: myfreeer <myfreeer@users.noreply.github.com>
Date: Sun, 14 Oct 2018 16:43:53 +0800
Subject: [PATCH] source: use zh localized version
---
Makefile | 54 ++++++++++++------------
commands/preprocess.py | 23 ++++++----
commands/preprocess_cssless.py | 5 ++-
gadgets/standard_revisions-tests/base.py | 2 +-
gadgets/sync_tests_mwiki.py | 2 +-
index2ddg.py | 4 +-
index_transform/browser.py | 2 +-
preprocess.py | 8 ++--
tests/test_preprocess.py | 19 ++++++---
tests/test_preprocess_cssless.py | 2 +-
10 files changed, 67 insertions(+), 54 deletions(-)
diff --git a/Makefile b/Makefile
index 2366fbc..423be32 100644
--- a/Makefile
+++ b/Makefile
@@ -100,18 +100,18 @@ install: all
popd > /dev/null
# install the devhelp documentation
- install -DT -m 644 "output/cppreference-doc-en-c.devhelp2" \
- "$(DESTDIR)$(bookdir)/cppreference-doc-en-c/cppreference-doc-en-c.devhelp2"
- install -DT -m 644 "output/cppreference-doc-en-cpp.devhelp2" \
- "$(DESTDIR)$(bookdir)/cppreference-doc-en-cpp/cppreference-doc-en-cpp.devhelp2"
+ install -DT -m 644 "output/cppreference-doc-zh-c.devhelp2" \
+ "$(DESTDIR)$(bookdir)/cppreference-doc-zh-c/cppreference-doc-zh-c.devhelp2"
+ install -DT -m 644 "output/cppreference-doc-zh-cpp.devhelp2" \
+ "$(DESTDIR)$(bookdir)/cppreference-doc-zh-cpp/cppreference-doc-zh-cpp.devhelp2"
install -DT -m 644 "output/cppreference-doxygen-local.tag.xml" \
"$(DESTDIR)$(bookdir)/cppreference-doxygen-local.tag.xml"
install -DT -m 644 "output/cppreference-doxygen-web.tag.xml" \
"$(DESTDIR)$(bookdir)/cppreference-doxygen-web.tag.xml"
# install the .qch (Qt Help) documentation
- install -DT -m 644 "output/cppreference-doc-en-cpp.qch" \
- "$(DESTDIR)$(docdir)/qch/cppreference-doc-en-cpp.qch"
+ install -DT -m 644 "output/cppreference-doc-zh-cpp.qch" \
+ "$(DESTDIR)$(docdir)/qch/cppreference-doc-zh-cpp.qch"
uninstall:
rm -rf "$(DESTDIR)$(docdir)"
@@ -138,16 +138,16 @@ release: all
# zip qch
pushd "output"; \
- tar c$(TAR_OPTION)f "../release/qch-book-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-en-cpp.qch"; \
- zip -qr "../release/qch-book-$(VERSION).zip" "cppreference-doc-en-cpp.qch"; \
+ tar c$(TAR_OPTION)f "../release/qch-book-$(VERSION).tar.$(TAR_FORMAT)" "cppreference-doc-zh-cpp.qch"; \
+ zip -qr "../release/qch-book-$(VERSION).zip" "cppreference-doc-zh-cpp.qch"; \
popd
#WORKER RULES
doc_html: output/reference
-doc_devhelp: output/cppreference-doc-en-c.devhelp2 output/cppreference-doc-en-cpp.devhelp2
+doc_devhelp: output/cppreference-doc-zh-c.devhelp2 output/cppreference-doc-zh-cpp.devhelp2
-doc_qch: output/cppreference-doc-en-cpp.qch
+doc_qch: output/cppreference-doc-zh-cpp.qch
doc_doxygen: output/cppreference-doxygen-web.tag.xml output/cppreference-doxygen-local.tag.xml
@@ -156,32 +156,32 @@ output/link-map.xml: output/reference
./build_link_map.py
#build the .devhelp2 index
-output/cppreference-doc-en-c.devhelp2: output/reference output/link-map.xml
+output/cppreference-doc-zh-c.devhelp2: output/reference output/link-map.xml
./index2devhelp.py $(docdir)/html index-chapters-c.xml \
- "C Standard Library reference" "cppreference-doc-en-c" "c" \
+ "C Standard Library reference" "cppreference-doc-zh-c" "c" \
index-functions-c.xml "output/devhelp-index-c.xml"
./fix_devhelp-links.py "output/devhelp-index-c.xml" \
- "output/cppreference-doc-en-c.devhelp2"
+ "output/cppreference-doc-zh-c.devhelp2"
-output/cppreference-doc-en-cpp.devhelp2: output/reference output/link-map.xml
+output/cppreference-doc-zh-cpp.devhelp2: output/reference output/link-map.xml
./index2devhelp.py $(docdir)/html index-chapters-cpp.xml \
- "C++ Standard Library reference" "cppreference-doc-en-cpp" "cpp" \
+ "C++ Standard Library reference" "cppreference-doc-zh-cpp" "cpp" \
index-functions-cpp.xml "output/devhelp-index-cpp.xml"
./fix_devhelp-links.py "output/devhelp-index-cpp.xml" \
- "output/cppreference-doc-en-cpp.devhelp2"
+ "output/cppreference-doc-zh-cpp.devhelp2"
#build the .qch (QT help) file
-output/cppreference-doc-en-cpp.qch: output/qch-help-project-cpp.xml
+output/cppreference-doc-zh-cpp.qch: output/qch-help-project-cpp.xml
#qhelpgenerator only works if the project file is in the same directory as the documentation
cp "output/qch-help-project-cpp.xml" "output/reference_cssless/qch.xml"
pushd "output/reference_cssless" > /dev/null; \
- $(qhelpgenerator) "qch.xml" -o "../cppreference-doc-en-cpp.qch"; \
+ $(qhelpgenerator) "qch.xml" -o "../cppreference-doc-zh-cpp.qch"; \
popd > /dev/null
rm -f "output/reference_cssless/qch.xml"
-output/qch-help-project-cpp.xml: output/cppreference-doc-en-cpp.devhelp2 output/reference_cssless
+output/qch-help-project-cpp.xml: output/cppreference-doc-zh-cpp.devhelp2 output/reference_cssless
#build the file list
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?><files>" > "output/qch-files.xml"
@@ -193,7 +193,7 @@ output/qch-help-project-cpp.xml: output/cppreference-doc-en-cpp.devhelp2 output/
echo "</files>" >> "output/qch-files.xml"
#create the project (copies the file list)
- ./devhelp2qch.py --src=output/cppreference-doc-en-cpp.devhelp2 \
+ ./devhelp2qch.py --src=output/cppreference-doc-zh-cpp.devhelp2 \
--dst=output/qch-help-project-cpp.xml \
--virtual_folder=cpp --file_list=output/qch-files.xml
@@ -229,7 +229,7 @@ indexes:
./index2autolinker.py index-functions-c.xml output/indexes/autolink-c
./index2autolinker.py index-functions-cpp.xml output/indexes/autolink-cpp
-#redownloads the source documentation directly from en.cppreference.com
+#redownloads the source documentation directly from zh.cppreference.com
source:
rm -rf "reference"
mkdir "reference"
@@ -238,15 +238,15 @@ source:
regex=".*index\\.php.*|.*/Special:.*|.*/Talk:.*" \
regex+="|.*/Help:.*|.*/File:.*|.*/Cppreference:.*" \
regex+="|.*/WhatLinksHere:.*|.*/Template:.*|.*/Category:.*" \
- regex+="|.*action=.*|.*printable=.*|.*en.cppreference.com/book.*" ; \
+ regex+="|.*action=.*|.*printable=.*|.*zh.cppreference.com/book.*" ; \
echo $$regex ; \
wget --adjust-extension --page-requisites --convert-links \
- --force-directories --recursive --level=15 \
- --span-hosts --domains=en.cppreference.com,upload.cppreference.com \
+ --force-directories --recursive --level=17 \
+ --span-hosts --domains=zh.cppreference.com,upload.cppreference.com \
--reject-regex $$regex \
- --timeout=5 --tries=50 --no-verbose \
+ --timeout=5 --tries=150 --no-verbose \
--retry-connrefused --waitretry=10 --read-timeout=20 \
- https://en.cppreference.com/w/ ; \
+ https://zh.cppreference.com/w/ ; \
popd > /dev/null
- ./export.py --url=http://en.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
+ ./export.py --url=https://zh.cppreference.com/mwiki reference/cppreference-export-ns0,4,8,10.xml 0 4 8 10
diff --git a/commands/preprocess.py b/commands/preprocess.py
index 12cb4e3..9e394d9 100644
--- a/commands/preprocess.py
+++ b/commands/preprocess.py
@@ -41,15 +41,15 @@ def rearrange_archive(root):
# rearrange the archive. {root} here is output/reference
# before
- # {root}/en.cppreference.com/w/ : html
- # {root}/en.cppreference.com/mwiki/ : data
- # {root}/en.cppreference.com/ : data
+ # {root}/zh.cppreference.com/w/ : html
+ # {root}/zh.cppreference.com/mwiki/ : data
+ # {root}/zh.cppreference.com/ : data
# ... (other languages)
# {root}/upload.cppreference.com/mwiki/ : data
# after
# {root}/common/ : all common data
- # {root}/en/ : html for en
+ # {root}/zh/ : html for zh
# ... (other languages)
data_path = os.path.join(root, 'common')
@@ -57,7 +57,7 @@ def rearrange_archive(root):
shutil.move(os.path.join(root, 'upload.cppreference.com/mwiki'), data_path)
shutil.rmtree(os.path.join(root, 'upload.cppreference.com'))
- for lang in ["en"]:
+ for lang in ["zh"]:
path = os.path.join(root, lang + ".cppreference.com/")
src_html_path = path + "w/"
src_data_path = path + "mwiki/"
@@ -78,7 +78,7 @@ def rearrange_archive(root):
shutil.copy(os.path.join(path, 'favicon.ico'), data_path)
# remove what's left
- shutil.rmtree(path)
+ # shutil.rmtree(path)
# remove the XML source file
for fn in fnmatch.filter(os.listdir(root), 'cppreference-export*.xml'):
@@ -295,7 +295,9 @@ def remove_google_analytics(html):
for el in html.xpath('/html/body/script'):
if el.get('src') is not None and 'google-analytics.com/ga.js' in el.get('src'):
el.getparent().remove(el)
- elif el.text is not None and ('google-analytics.com/ga.js' in el.text or 'pageTracker' in el.text):
+ elif el.text is not None and ('google-analytics.com/ga.js' in el.text or 'pageTracker' in el.text or '_trackPageview' in el.text):
+ el.getparent().remove(el)
+ elif el.get('src') is not None and 'carbonads.com/carbon.js' in el.get('src'):
el.getparent().remove(el)
# remove Carbon ads
@@ -316,7 +318,10 @@ def remove_fileinfo(html):
# make custom footer
def add_footer(html, root, fn):
- footer = html.xpath('//*[@id=\'footer\']')[0]
+ footers = html.xpath('//*[@id=\'footer\']')
+ if len(footers) == 0:
+ return
+ footer = footers[0]
for child in footer.getchildren():
id = child.get('id')
if id == 'cpp-navigation':
@@ -338,7 +343,7 @@ def add_footer(html, root, fn):
footer.remove(child)
def preprocess_html_file(root, fn, rename_map):
- parser = etree.HTMLParser()
+ parser = etree.HTMLParser(encoding="utf-8")
html = etree.parse(fn, parser)
output = io.StringIO()
diff --git a/commands/preprocess_cssless.py b/commands/preprocess_cssless.py
index 2f75d5a..64742c6 100644
--- a/commands/preprocess_cssless.py
+++ b/commands/preprocess_cssless.py
@@ -27,11 +27,12 @@ import io
import logging
import os
import warnings
+import codecs
def preprocess_html_merge_cssless(src_path, dst_path):
- with open(src_path, 'r') as a_file:
+ with codecs.open(src_path, 'r', 'utf-8') as a_file:
content = a_file.read()
- parser = etree.HTMLParser()
+ parser = etree.HTMLParser(encoding="utf-8")
stripped = content.strip()
root = etree.fromstring(stripped, parser)
diff --git a/gadgets/standard_revisions-tests/base.py b/gadgets/standard_revisions-tests/base.py
index 848d431..91a0a99 100644
--- a/gadgets/standard_revisions-tests/base.py
+++ b/gadgets/standard_revisions-tests/base.py
@@ -27,7 +27,7 @@ import unittest, time, re
class Driver:
def __init__(self):
- base_url = "http://en.cppreference.com/"
+ base_url = "https://zh.cppreference.com/"
driver = webdriver.Firefox()
driver.implicitly_wait(30)
try:
diff --git a/gadgets/sync_tests_mwiki.py b/gadgets/sync_tests_mwiki.py
index 9aa3fc7..13294ec 100755
--- a/gadgets/sync_tests_mwiki.py
+++ b/gadgets/sync_tests_mwiki.py
@@ -114,7 +114,7 @@ def perform_sync(url, direction, dest_root, title_filter, user, password,
# Supply information to config that would otherwise be defined in
# user-config.py
pywikibot.config2.family = 'cppreference'
- pywikibot.config2.mylang = 'en'
+ pywikibot.config2.mylang = 'zh'
pywikibot.config2.family_files['cppreference'] = url
pywikibot.config2.step = 100
pywikibot.config2.put_throttle = 0
diff --git a/index2ddg.py b/index2ddg.py
index 9789e56..32a8707 100755
--- a/index2ddg.py
+++ b/index2ddg.py
@@ -447,7 +447,7 @@ def process_identifier(out, redirects, root, link, item_ident, item_type,
abstract = abstract.replace('\n','\\n')
line += abstract + '\t'
# source url
- line += 'http://en.cppreference.com/w/' + link + '\n'
+ line += 'https://zh.cppreference.com/w/' + link + '\n'
out.write(line)
build_redirects(redirects, item_ident, item_type)
@@ -540,7 +540,7 @@ def main():
#print(str(i) + '/' + str(len(proc_ins)) + ': ' + link)
#i+=1
- root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser())
+ root = e.parse(os.path.join(args.reference, fn), parser=html.HTMLParser(encoding="utf-8"))
for ident in idents:
diff --git a/index_transform/browser.py b/index_transform/browser.py
index d2e625c..11375f2 100644
--- a/index_transform/browser.py
+++ b/index_transform/browser.py
@@ -42,7 +42,7 @@ class Index2Browser(IndexTransform):
res = u''
res += '<tt><b>' + xml_escape(full_name) + '</b></tt> [<span class="link">'
- res += '<a href="http://en.cppreference.com/w/' + xml_escape(full_link) + '">'
+ res += '<a href="https://zh.cppreference.com/w/' + xml_escape(full_link) + '">'
res += full_link + '</a></span>] <span class="mark">' + mark + '</span>\n'
return res
diff --git a/preprocess.py b/preprocess.py
index ba5d37b..f852885 100755
--- a/preprocess.py
+++ b/preprocess.py
@@ -29,12 +29,12 @@ def main():
parser.add_argument('--dst', type=str, help='Destination folder to put preprocessed archive to')
args = parser.parse_args()
- root = args.dst
- src = args.src
+ root = args.src
+ # src = args.src
# copy the source tree
- preprocess.rmtree_if_exists(root)
- shutil.copytree(src, root)
+ # rmtree_if_exists(root)
+ # shutil.copytree(src, root)
preprocess.rearrange_archive(root)
diff --git a/tests/test_preprocess.py b/tests/test_preprocess.py
index 0c6568c..247d062 100644
--- a/tests/test_preprocess.py
+++ b/tests/test_preprocess.py
@@ -26,19 +26,26 @@ from lxml import etree
class TestConvertLoaderName(unittest.TestCase):
def test_convert_loader_name(self):
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=scripts&skin=cppreference2&*'
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
+modules=site&only=scripts&skin=cppreference2&*'
self.assertEqual('site_scripts.js', convert_loader_name(url))
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=site&only=styles&skin=cppreference2&*'
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
+modules=site&only=styles&skin=cppreference2&*'
self.assertEqual('site_modules.css', convert_loader_name(url))
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
+modules=skins.cppreference2&only=scripts&skin=cppreference2&*'
self.assertEqual('skin_scripts.js', convert_loader_name(url))
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=startup&only=scripts&skin=cppreference2&*'
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
+modules=startup&only=scripts&skin=cppreference2&*'
self.assertEqual('startup_scripts.js', convert_loader_name(url))
- url = 'http://en.cppreference.com/mwiki/load.php?debug=false&lang=en&modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=cppreference2&*'
+ url = 'https://zh.cppreference.com/mwiki/load.php?debug=false&lang=*&\
+modules=ext.gadget.ColiruCompiler%2CMathJax%7Cext.rtlcite%7Cmediawiki.\
+legacy.commonPrint%2Cshared%7Cskins.cppreference2&only=styles&skin=\
+cppreference2&*'
self.assertEqual('ext.css', convert_loader_name(url))
with self.assertRaises(Exception):
@@ -196,7 +203,7 @@ class TestPreprocessHtml(unittest.TestCase):
def setUp(self):
self.testdata = os.path.join(os.path.dirname(__file__), 'preprocess_data')
infile = os.path.join(self.testdata, "fabs.html")
- self.parser = etree.HTMLParser()
+ self.parser = etree.HTMLParser(encoding="utf-8")
self.html = etree.parse(infile, self.parser)
# Check whether the HTML matches the contents of the specified test data file
diff --git a/tests/test_preprocess_cssless.py b/tests/test_preprocess_cssless.py
index fc93019..ffad345 100644
--- a/tests/test_preprocess_cssless.py
+++ b/tests/test_preprocess_cssless.py
@@ -63,7 +63,7 @@ class HTMLTestBase(unittest.TestCase):
input = '<html><body>{0}</body></html>'.format(input)
expected_output = '<html><body>{0}</body></html>'.format(expected_output)
- parser = etree.HTMLParser()
+ parser = etree.HTMLParser(encoding="utf-8")
root = etree.fromstring(input, parser)
root = function(root)
--
2.19.0