Skip to content

Commit 175b28c

Browse files
committed
Fix linking of zip files from code/index.html
1 parent 5b6a424 commit 175b28c

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

20_node.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{meta {code_links: "[\"code/file_server.js\"]"}}}
1+
{{meta {code_links: ["code/file_server.js"]}}}
22

33
# Node.js
44

21_skillsharing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{meta {code_links: "[\"code/skillsharing.zip\"]"}}}
1+
{{meta {code_links: ["code/skillsharing.zip"]}}}
22

33
# Project: Skill-Sharing Website
44

src/chapter_info.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ for (let file of fs.readdirSync(".").sort()) {
2323
start_code: getStartCode(text, includes),
2424
exercises: [],
2525
include: includes};
26-
let zip = chapterZipFile(text, chapter);
26+
let zip = chapterZipFile(meta, chapter);
2727
let extraLinks = meta.match(/\bcode_links: (\[.*?\])/);
2828
if (extraLinks) extraLinks = JSON.parse(extraLinks[1]);
2929
if (extraLinks || zip)
@@ -180,12 +180,13 @@ function getStartCode(text, includes) {
180180
return snippet;
181181
}
182182

183-
function chapterZipFile(text, chapter) {
184-
let spec = text.match(/\n:zip: (\S+)(?: include=(.*))?/);
183+
function chapterZipFile(meta, chapter) {
184+
let spec = meta.match(/\bzip: ("(?:\\.|[^"\\])*")/);
185185
if (!spec) return null;
186186
if (!chapter.start_code) throw new Error("zip but no start code");
187+
let data = /(\S+)(?:\s+include=(.*))?/.exec(JSON.parse(spec[1]))
187188
let name = "code/chapter/" + chapter.id + ".zip";
188-
let files = (chapter.include || []).concat(spec[2] ? JSON.parse(spec[2]) : []);
189+
let files = (chapter.include || []).concat(data[2] ? JSON.parse(data[2]) : []);
189190
let exists = fs.existsSync(name) && fs.statSync(name).mtime;
190191
if (exists && files.every(file => fs.statSync("html/" + file).mtime < exists))
191192
return name;
@@ -194,13 +195,13 @@ function chapterZipFile(text, chapter) {
194195
for (let file of files) {
195196
zip.file(chapter.id + "/" + file, fs.readFileSync("html/" + file));
196197
}
197-
if (spec[1].indexOf("html") != -1) {
198+
if (data[1].indexOf("html") != -1) {
198199
let html = chapter.start_code;
199200
if (guessType(html) != "html")
200201
html = prepareHTML("<body><script>\n" + html.trim() + "\n</script></body>", chapter.include);
201202
zip.file(chapter.id + "/index.html", html);
202203
}
203-
if (spec[1].indexOf("node") != -1) {
204+
if (data[1].indexOf("node") != -1) {
204205
zip.file(chapter.id + "/code/load.js", fs.readFileSync("code/load.js", "utf8"));
205206
let js = chapter.start_code;
206207
if (chapter.include) js = "// load dependencies\nrequire(\"./code/load\")(" + chapter.include.map(JSON.stringify).join(", ") + ");\n\n" + js;

0 commit comments

Comments
 (0)