Skip to content

Commit 22c8ae7

Browse files
author
p12
committed
Preprocess: rearrange whole archive into better structure
1 parent 7effa0a commit 22c8ae7

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

preprocess.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,46 @@
2626
os.system('mkdir output')
2727
os.system('cp -rt output reference/*')
2828

29+
# rearrange the archive
30+
31+
# before
32+
# output/en.cppreference.com/w/ : html
33+
# output/en.cppreference.com/mwiki/ : data
34+
# output/en.cppreference.com/ : data
35+
# ... (other languages)
36+
# output/upload.cppreference.com/mwiki/ : data
37+
38+
# after
39+
# output/common/ : all data
40+
# output/en/ : html for en
41+
# ... (other languages)
42+
43+
data_path = "output/common"
44+
os.system('mkdir ' + data_path)
45+
os.system('mv output/upload.cppreference.com/mwiki/* ' + data_path)
46+
os.system('rm -r output/upload.cppreference.com/')
47+
48+
for lang in ["en"]:
49+
path = "output/" + lang + ".cppreference.com/"
50+
src_html_path = path + "w/"
51+
src_data_path = path + "mwiki/"
52+
html_path = "output/" + lang
53+
54+
if (os.path.isdir(src_html_path)):
55+
os.system('mv ' + src_html_path + ' ' + html_path)
56+
57+
if (os.path.isdir(src_data_path)):
58+
# the skin files should be the same for all languages thus we
59+
# can merge everything
60+
os.system('cp -rl ' + src_data_path + '/* ' + data_path)
61+
os.system('rm -r ' + src_data_path)
62+
63+
# also copy the custom fonts
64+
os.system('cp ' + path + 'DejaVuSansMonoCondensed60.ttf ' +
65+
path + 'DejaVuSansMonoCondensed75.ttf ' + data_path)
66+
# remove what's left
67+
os.system('rm -r '+ path)
68+
2969
# find all html and css files
3070
html_files = []
3171
css_files = []
@@ -56,5 +96,14 @@
5696
os.system('xsltproc --novalid --html preprocess.xsl "' + fn + '" > "' + tmpfile + '"')
5797
os.system('mv "' + tmpfile + '" "' + fn + '"')
5898

99+
# append css modifications to the css files
100+
for fn in css_files:
101+
f = open(fn, "r")
102+
text = f.read()
103+
f.close()
59104

60-
os.system('cat preprocess-css.css >> "output/en.cppreference.com/mwiki/load7fe1.css"')
105+
r = re.compile('DejaVuSansMonoCondensed60')
106+
if (r.search(text)):
107+
# assume this is minified MediaWiki:Common.css
108+
# append the modifications
109+
os.system('cat preprocess-css.css >> "'+fn+'"')

preprocess.xsl

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
You should have received a copy of the GNU General Public License
1818
along with this program. If not, see http://www.gnu.org/licenses/.
1919
-->
20-
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
20+
<xsl:stylesheet
21+
version="1.0"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:str="http://exslt.org/strings">
2124

2225
<xsl:output
2326
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
@@ -89,4 +92,18 @@
8992
<xsl:template match="/html/head/script[contains(text(),'google-analytics.com/ga.js')]"/>
9093
<xsl:template match="/html/head/script[contains(text(),'pageTracker')]"/>
9194

95+
<!-- update links to resources: -->
96+
<xsl:template match="//@href | //@src">
97+
<xsl:attribute name="{name()}">
98+
<xsl:choose>
99+
<xsl:when test="contains(.,'../../upload.cppreference.com/mwiki/')">
100+
<xsl:value-of select="str:replace(.,'../../upload.cppreference.com/mwiki/','../common/')"/>
101+
</xsl:when>
102+
<xsl:otherwise>
103+
<xsl:value-of select="str:replace(.,'../mwiki/','../common/')"/>
104+
</xsl:otherwise>
105+
</xsl:choose>
106+
</xsl:attribute>
107+
</xsl:template>
108+
92109
</xsl:stylesheet>

0 commit comments

Comments
 (0)