Skip to content

Commit 8ffee02

Browse files
committed
Add a png fallback mechanism for browsers that don't support svg
1 parent 7993106 commit 8ffee02

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

00_intro.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ do. Computers are about as common as screwdrivers today, but contain a
88
lot more hidden complexity, and thus are harder to operate and
99
understand. To many, they remain alien, slightly threatening things.
1010

11-
image::img/computer.png[alt="Communicating with a computer"]
11+
image::img/generated/computer.png[alt="Communicating with a computer"]
1212

1313
(((graphical user interface)))We've found two effective ways of
1414
bridging the communication gap between us, squishy biological

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ CHAPTERS := 00_intro 01_values 02_program_structure 03_functions 04_data 05_high
44
07_elife 08_error 09_regexp 10_modules 11_language 12_browser 13_dom 14_event 15_game 16_canvas \
55
17_http 18_forms 19_paint 20_node 21_skillsharing
66

7+
SVGS := $(wildcard img/*.svg)
8+
79
.SECONDARY: $(foreach CHAP,$(CHAPTERS),tex/$(CHAP).db)
810

9-
html: $(foreach CHAP,$(CHAPTERS),html/$(CHAP).html) html/js/chapter_info.js code/skillsharing.zip code/solutions/20_4_a_public_space_on_the_web.zip
11+
html: $(foreach CHAP,$(CHAPTERS),html/$(CHAP).html) html/js/chapter_info.js \
12+
code/skillsharing.zip code/solutions/20_4_a_public_space_on_the_web.zip \
13+
$(patsubst img/%.svg,img/generated/%.png,$(SVGS))
1014

1115
html/%.html: %.txt asciidoc_html.conf
1216
PATH=node_modules/codemirror/bin:$(PATH) asciidoc -f asciidoc_html.conf --backend=html5 -o $@ $<
@@ -15,6 +19,12 @@ html/%.html: %.txt asciidoc_html.conf
1519
html/js/chapter_info.js: $(foreach CHAP,$(CHAPTERS),$(CHAP).txt) code/solutions/* bin/chapter_info.js
1620
node bin/chapter_info.js > html/js/chapter_info.js
1721

22+
img/generated/%.png: img/%.svg
23+
inkscape --export-png=$@ $<
24+
25+
img/generated/%.pdf: img/%.svg
26+
inkscape --export-pdf=$@ $<
27+
1828
code/skillsharing.zip: html/21_skillsharing.html
1929
rm -f $@
2030
cd code; zip skillsharing.zip skillsharing/*.js* skillsharing/public/*.*
@@ -38,7 +48,8 @@ test: html
3848
@node bin/check_links.js
3949
@echo Done.
4050

41-
book.pdf: tex/book/book.tex $(foreach CHAP,$(CHAPTERS),tex/$(CHAP).tex) tex/solutions.tex
51+
book.pdf: tex/book/book.tex $(foreach CHAP,$(CHAPTERS),tex/$(CHAP).tex) tex/solutions.tex \
52+
$(patsubst img/%.svg,img/generated/%.pdf,$(SVGS))
4253
cd tex/book && xelatex book.tex
4354
cd tex/book && xelatex book.tex
4455
makeindex -s tex/book/nostarch.ist -o tex/book/book.ind tex/book/book.idx

bin/pre_latex.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ function convertImage(name, type) {
5151
} catch (e) {
5252
newAge = 0;
5353
}
54-
var oldAge = fs.statSync(oldName).atime;
55-
if (newAge < oldAge)
56-
child.spawn("inkscape", ["--export-pdf=" + newName, oldName]);
5754
return newName;
5855
} else {
5956
return oldName;

html/js/ejs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
window.addEventListener("load", function() {
2+
// Fall back to pngs when svg images are not supported
3+
if (document.getElementsByTagName && !document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#Image", "1.1")) {
4+
var imgs = document.getElementsByTagName("img");
5+
for (var i = 0, svg; i < imgs.length; i++)
6+
if (svg = /^(.*?img\/)([^.]+)\.svg$/.exec(imgs[i].src))
7+
imgs[i].src = svg[1] + "generated/" + svg[2] + ".png";
8+
}
9+
210
// If there's no ecmascript 5 support, don't try to initialize
311
if (!Object.create || !window.JSON) return;
412

img/computer.png

-402 KB
Binary file not shown.

0 commit comments

Comments
 (0)