build fiddling

This commit is contained in:
Mark Pilgrim
2009-06-05 11:42:04 -04:00
parent 3b6ff0f0cb
commit 7be922d7b0
9 changed files with 30 additions and 34 deletions
+5 -2
View File
@@ -18,8 +18,11 @@ h1:before{content:""}
<p>The dynamic highlighting effects in the online edition are built on top of <a href=http://jquery.com>jQuery</a>, which is dual-licensed under the MIT and GPL licenses.
<p>The online edition loads as quickly as it does because
<ol>
<li>jQuery is served by <a href=http://code.google.com/apis/ajaxlibs/>Google AJAX Libraries API</a>.
<li>Other Javascript and CSS resources are minimized by <a href=http://developer.yahoo.com/yui/compressor/>YUI Compressor</a>.
<li>HTML is <a href=http://httpd.apache.org/docs/trunk/mod/mod_deflate.html>compressed</a>.
<li>Scripts and stylesheets are minimized by <a href=http://developer.yahoo.com/yui/compressor/>YUI Compressor</a>.
<li>Scripts are combined to reduce HTTP requests.
<li>Stylesheets are combined and inlined to reduce HTTP requests.
<li>Unused CSS selectors and properties are <a href=http://hg.diveintopython3.org/file/default/util/lesscss.py>removed on a page-by-page basis</a> with <a href=http://pyquery.org/>pyquery</a>.
<li>HTTP caching and other server-side options are optimized based on advice from <a href=http://developer.yahoo.com/yslow/>YSlow</a> and <a href=http://code.google.com/speed/page-speed/>Page Speed</a>.
<li>The text uses <a href=http://www.alanwood.net/unicode/unicode_samples.html>Unicode characters</a> in place of graphics wherever possible.
<li>The entire book was <a href=http://diveintomark.org/archives/2009/03/27/dive-into-history-2009-edition>lovingly hand-authored in HTML 5</a> to avoid markup cruft.
-3
View File
@@ -27,8 +27,6 @@ POSSIBILITY OF SUCH DAMAGE.
*/
var HS = {'visible': 'hide', 'hidden': 'show'};
//google.load("jquery", "1.3");
//google.setOnLoadCallback(function() {
$(document).ready(function() {
hideTOC();
@@ -93,7 +91,6 @@ $(document).ready(function() {
});
});
}); /* document.ready */
//}); /* google.setOnLoadCallback */
function toggleCodeBlock(id) {
$("#" + id).find("div.b").toggle();
+1 -1
View File
@@ -1 +1 @@
<script>var gaJsHost="http://www.";document.write(unescape("%3Cscript src='"+gaJsHost+"google-analytics.com/ga.js'%3E%3C/script%3E"));</script><script>try{var pageTracker=_gat._getTracker("UA-7434570-3");pageTracker._trackPageview();}catch(err){}</script>
<script src=//www.google-analytics.com/ga.js></script><script>try{var pageTracker=_gat._getTracker("UA-7434570-3");pageTracker._trackPageview();}catch(err){}</script>
+1 -1
View File
@@ -16,7 +16,7 @@ body{counter-reset:h1 5}
<p id=level>Difficulty level: <span title=intermediate>&#x2666;&#x2666;&#x2666;&#x2662;&#x2662;</span>
<h1>Generators</h1>
<blockquote class=q>
<p><span>&#x275D;</span> My spelling is Wobbly. It's good spelling but it Wobbles, and the letters get in the wrong places. <span>&#x275E;</span><br>&mdash; Winnie-the-Pooh
<p><span>&#x275D;</span> My spelling is Wobbly. It&#8217;s good spelling but it Wobbles, and the letters get in the wrong places. <span>&#x275E;</span><br>&mdash; Winnie-the-Pooh
</blockquote>
<p id=toc>&nbsp;
<h2 id=divingin>Diving In</h2>
+1
View File
File diff suppressed because one or more lines are too long
+3 -12
View File
@@ -45,9 +45,6 @@ span {
.q span {
font-size: 13pt;
}
.note span {
color: #000;
}
.f:first-letter {
color: #888;
font: normal 48pt/0.68 serif;
@@ -61,11 +58,8 @@ p, ul, ol {
html {
background: #fff;
color: #000;
margin: 0;
padding: 0;
}
body {
html, body {
margin: 0;
padding: 0;
}
@@ -76,10 +70,7 @@ a {
text-decoration: none;
border-bottom: 1px dotted;
}
a:link, .w a {
color: #000;
}
a:visited {
html, a:link, a:visited, .w a, .note span {
color: #000;
}
@@ -111,7 +102,7 @@ h3, h3 code {
aside {
font-size: 24pt;
background: #667;
color: white;
color: #fff;
}
/* overrides */
+16 -12
View File
@@ -27,15 +27,17 @@ for f in build/*.html; do
mv build/tmp "$f"
done
# jQuery will be served by Google AJAX Libraries API
sed -i -e "s|jquery\.js|http://www.google.com/jsapi|g" build/*.html
sed -i -e "s|//google\.|google.|g" build/dip3.js
sed -i -e "s|//}.; /\* google\..*|});|g" build/dip3.js
# minimize JS and CSS
echo "minimizing JS"
revision=`hg log|grep changeset|cut -d":" -f3|head -1`
java -jar yuicompressor-2.4.2.jar build/dip3.js > build/$revision.js
java -jar yuicompressor-2.4.2.jar build/dip3.js > build/dip3-$revision.js
# combine jQuery and our script
echo "combining JS"
cat jquery.min.js build/dip3-$revision.js > build/$revision.js
rm build/dip3-$revision.js
sed -i -e "s|<script src=jquery.js></script>||g" build/*.html
echo "minimizing CSS"
java -jar yuicompressor-2.4.2.jar build/dip3.css > build/$revision.css
java -jar yuicompressor-2.4.2.jar build/mobile.css > build/m-$revision.css
@@ -47,7 +49,9 @@ sed -i -e "s|;}|}|g" build/p-$revision.css
# put CSS inline
echo "inlining CSS"
css=`cat build/$revision.css`
sed -i -e "s|<link rel=stylesheet href=dip3.css>|<style>${css}</style>|g" -e "s|</style><style>||g" build/*.html
mobilecss=`cat build/m-$revision.css`
printcss=`cat build/p-$revision.css`
sed -i -e "s|<link rel=stylesheet href=dip3.css>|<style>${css}</style>|g" -e "s|<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>|<style>@media only screen and (max-device-width: 480px){${mobilecss}}</style>|g" -e "s|<link rel=stylesheet media=print href=print.css>|<style>@media print{${printcss}}</style>|g" -e "s|</style><style>||g" build/*.html
# remove unused CSS properties on a page-by-page basis
echo "removing unused CSS"
@@ -55,10 +59,10 @@ for f in build/*.html; do
python2.6 util/lesscss.py "$f"
done
# secondary stylesheets will be served from a separate domain
echo "fixing hrefs"
sed -i -e "s|href=mobile.css|href=http://wearehugh.com/dip3/m-${revision}.css|g" build/*.html
sed -i -e "s|href=print.css|href=http://wearehugh.com/dip3/p-${revision}.css|g" build/*.html
## secondary stylesheets will be served from a separate domain
#echo "fixing hrefs"
#sed -i -e "s|href=mobile.css|href=http://wearehugh.com/dip3/m-${revision}.css|g" build/*.html
#sed -i -e "s|href=print.css|href=http://wearehugh.com/dip3/p-${revision}.css|g" build/*.html
# JS will be served from a separate domain
sed -i -e "s|dip3\.js|http://wearehugh.com/dip3/${revision}.js|g" build/*.html
@@ -77,5 +81,5 @@ chmod 644 build/*.html build/*.css build/*.js build/examples/*.py build/examples
# ship it!
echo "publishing"
rsync -essh -avzP build/$revision.js build/html5.js build/m-$revision.css build/p-$revision.css diveintomark.org:~/web/wearehugh.com/dip3/
rsync -essh -avzP build/$revision.js build/html5.js diveintomark.org:~/web/wearehugh.com/dip3/
rsync -essh -avzP build/*.html build/examples build/*.txt diveintomark.org:~/web/diveintopython3.org/
+1 -1
View File
@@ -234,7 +234,7 @@ body{counter-reset:h1 4}
<samp>&lt;_sre.SRE_Match object at 0x008EEB48></samp>
<a><samp class=p>>>> </samp><kbd>re.search(pattern, 'MMDCLXVI')</kbd> <span>&#x2461;</span></a>
<samp>&lt;_sre.SRE_Match object at 0x008EEB48></samp>
<a><samp class=p>>>> </samp><kbd>re.search(pattern, 'MMMDCCCLXXXVIII')</kbd> <span>&#x2462;</span></a>
<a><samp class=p>>>> </samp><kbd>re.search(pattern, 'MMMDCCCLXXXVIII')</kbd> <span>&#x2462;</span></a>
<samp>&lt;_sre.SRE_Match object at 0x008EEB48></samp>
<a><samp class=p>>>> </samp><kbd>re.search(pattern, 'I')</kbd> <span>&#x2463;</span></a>
<samp>&lt;_sre.SRE_Match object at 0x008EEB48></samp></pre>
+2 -2
View File
@@ -7,14 +7,14 @@ import sys
filename = sys.argv[1]
pqd = pq(filename=filename)
raw_data = open(filename, 'rb').read()
if raw_data.count('<pre'):
if raw_data.count('<pre><code>') or raw_data.count('<pre class=screen>'):
def keep(s):
return s == '.w' or s.startswith('.w ') or s == '.b' or s.startswith('.b ')
else:
def keep(s):
return False
original_css = raw_data.split('<style>', 1)[1].split('</style>', 1)[0]
original_css = raw_data.split('<style>', 1)[1].split('@media', 1)[0]
new_css = ''
for rule in original_css.split('}')[:-1]:
selectors, properties = rule.split('{', 1)