工农解放报第二期26.11
This commit is contained in:
1 parent
97e84fa6c4
commit
5977b1b272
17 files changed
+604
-46
No files matched your search
@@ -79,3 +79,87 @@ Deno.test("uses EPUB output path or a stable default", () => {
|
||||
});
|
||||
assertEquals(builder.outputPath(), "./outputs/book.epub");
|
||||
});
|
||||
|
||||
Deno.test("bundles shared assets referenced by publication articles", async () => {
|
||||
const root = await Deno.makeTempDir();
|
||||
const publication = `${root}/publication`;
|
||||
const templates = `${root}/templates`;
|
||||
const assets = `${root}/assets`;
|
||||
const output = `${root}/shared-assets.epub`;
|
||||
await Deno.mkdir(`${publication}/1::专栏`, { recursive: true });
|
||||
await Deno.mkdir(templates, { recursive: true });
|
||||
await Deno.mkdir(`${assets}/pictures`, { recursive: true });
|
||||
await Deno.writeTextFile(
|
||||
`${publication}/1::专栏/1::文章.md`,
|
||||
"",
|
||||
);
|
||||
const imageBytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
await Deno.writeFile(`${assets}/pictures/shared.png`, imageBytes);
|
||||
const builder = new EpubBuilder({
|
||||
asset_base: assets,
|
||||
journal: {
|
||||
build_mode: "detached",
|
||||
from_directory: publication,
|
||||
template_directory: templates,
|
||||
},
|
||||
epub: { path: output },
|
||||
}).with_files_sync();
|
||||
|
||||
try {
|
||||
await builder.build();
|
||||
const archive = inspectEpub(await Deno.readFile(output));
|
||||
const chapter = new TextDecoder().decode(
|
||||
archive["EPUB/text/0001-文章.xhtml"],
|
||||
);
|
||||
assertStringIncludes(chapter, "../media/1/1.png");
|
||||
assertEquals(
|
||||
[...archive["EPUB/media/1/1.png"]],
|
||||
[...imageBytes],
|
||||
);
|
||||
} finally {
|
||||
await Deno.remove(root, { recursive: true });
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("packages shared assets directory images as EPUB resources", async () => {
|
||||
const root = await Deno.makeTempDir();
|
||||
const publication = `${root}/publication`;
|
||||
const templates = `${root}/templates`;
|
||||
const assets = `${root}/assets`;
|
||||
const output = `${root}/shared-assets.epub`;
|
||||
await Deno.mkdir(`${publication}/1::专栏`, { recursive: true });
|
||||
await Deno.mkdir(templates, { recursive: true });
|
||||
await Deno.mkdir(`${assets}/pictures`, { recursive: true });
|
||||
await Deno.writeTextFile(
|
||||
`${publication}/1::专栏/1::文章.md`,
|
||||
"",
|
||||
);
|
||||
const imageBytes = new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10]);
|
||||
await Deno.writeFile(`${assets}/pictures/shared.png`, imageBytes);
|
||||
const builder = new EpubBuilder({
|
||||
asset_base: assets,
|
||||
journal: {
|
||||
build_mode: "detached",
|
||||
from_directory: publication,
|
||||
template_directory: templates,
|
||||
identifier: "urn:test:shared-assets",
|
||||
},
|
||||
epub: { path: output },
|
||||
}).with_files_sync();
|
||||
|
||||
try {
|
||||
await builder.build();
|
||||
const zip = inspectEpub(await Deno.readFile(output));
|
||||
const chapter = new TextDecoder().decode(
|
||||
zip["EPUB/text/0001-文章.xhtml"],
|
||||
);
|
||||
assertStringIncludes(chapter, "../media/1/1.png");
|
||||
assertEquals(zip["EPUB/media/1/1.png"], imageBytes);
|
||||
assertStringIncludes(
|
||||
new TextDecoder().decode(zip["EPUB/content.opf"]),
|
||||
'media/1/1.png" media-type="image/png"',
|
||||
);
|
||||
} finally {
|
||||
await Deno.remove(root, { recursive: true });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user