This commit is contained in:
1 parent
5977b1b272
commit
09af3bd8c0
18 files changed
+53
-26
No files matched your search
+19
-1
@@ -4,6 +4,24 @@ GP 是一个基于 Deno、Markdown 和 HTML 模板的刊物构建工具,可以
|
|||||||
PDF,也可以导出合并后的 Markdown 或纯文本。PDF 支持自动生成目录、PDF 线性化和
|
PDF,也可以导出合并后的 Markdown 或纯文本。PDF 支持自动生成目录、PDF 线性化和
|
||||||
OpenPGP 签名。
|
OpenPGP 签名。
|
||||||
|
|
||||||
|
## 代码目录
|
||||||
|
|
||||||
|
`main.ts` 保留为命令入口,配置和输出路径仍相对于 `tools/gp` 工作目录解析。
|
||||||
|
各模块的测试与实现放在同一目录:
|
||||||
|
|
||||||
|
```text
|
||||||
|
tools/gp/
|
||||||
|
├── main.ts # 命令入口和配置加载
|
||||||
|
├── cli/ # 子命令分发与导出处理
|
||||||
|
├── publication/ # 出版物、专栏、文章读取及排序
|
||||||
|
├── template/ # 模板变量和模板渲染
|
||||||
|
├── mdit/ # Markdown 解析及插件
|
||||||
|
├── assets/ # 外部素材缓存
|
||||||
|
├── pdf_builder/ # 文档渲染、PDF 目录、流水线及 Worker
|
||||||
|
├── epub_builder/ # EPUB 章节和资源打包
|
||||||
|
└── sync/ # WebDAV 上传、同步及清理
|
||||||
|
```
|
||||||
|
|
||||||
## 工作流程
|
## 工作流程
|
||||||
|
|
||||||
```text
|
```text
|
||||||
@@ -382,7 +400,7 @@ deno test -A
|
|||||||
deno task dev
|
deno task dev
|
||||||
|
|
||||||
# 检查类型和格式
|
# 检查类型和格式
|
||||||
deno check main.ts pdf_pipeline.ts
|
deno check main.ts pdf_builder/pipeline.ts
|
||||||
deno fmt --check
|
deno fmt --check
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
File renamed without changes.
File renamed without changes.
@@ -2,9 +2,9 @@
|
|||||||
import { args, cfg } from "../main.ts";
|
import { args, cfg } from "../main.ts";
|
||||||
import { OpenPGPSigner } from "../pdf_builder/utils.ts";
|
import { OpenPGPSigner } from "../pdf_builder/utils.ts";
|
||||||
import { DocuBuilder } from "../pdf_builder/docu_builder.ts";
|
import { DocuBuilder } from "../pdf_builder/docu_builder.ts";
|
||||||
import { createTemplateVariables } from "../template_engine.ts";
|
import { createTemplateVariables } from "../template/engine.ts";
|
||||||
import { prepareLocalCache } from "../local_cache.ts";
|
import { prepareLocalCache } from "../assets/local_cache.ts";
|
||||||
import { EpubBuilder } from "../epub_builder.ts";
|
import { EpubBuilder } from "../epub_builder/epub_builder.ts";
|
||||||
|
|
||||||
function selectedConfigs() {
|
function selectedConfigs() {
|
||||||
return cfg.settings.filter((config: Record<string, unknown>) =>
|
return cfg.settings.filter((config: Record<string, unknown>) =>
|
||||||
@@ -65,7 +65,7 @@ function runPdfWorker(
|
|||||||
return createTemplateVariables(args, config, cfg.vars).then((variables) =>
|
return createTemplateVariables(args, config, cfg.vars).then((variables) =>
|
||||||
new Promise<void>((resolve, reject) => {
|
new Promise<void>((resolve, reject) => {
|
||||||
const worker = new Worker(
|
const worker = new Worker(
|
||||||
new URL("../pdf_worker.ts", import.meta.url).href,
|
new URL("../pdf_builder/worker.ts", import.meta.url).href,
|
||||||
{
|
{
|
||||||
type: "module",
|
type: "module",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import {
|
|||||||
generate_txt,
|
generate_txt,
|
||||||
just_local_cache,
|
just_local_cache,
|
||||||
} from "./handlers.ts";
|
} from "./handlers.ts";
|
||||||
import { clean_local_files, sync_webdav, upload_webdav } from "../webdav.ts";
|
import {
|
||||||
|
clean_local_files,
|
||||||
|
sync_webdav,
|
||||||
|
upload_webdav,
|
||||||
|
} from "../sync/webdav.ts";
|
||||||
|
|
||||||
export async function match_sub_command_to_function(
|
export async function match_sub_command_to_function(
|
||||||
sub_command: Array<string>,
|
sub_command: Array<string>,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { strToU8, unzipSync, type Zippable, zipSync } from "fflate";
|
import { strToU8, unzipSync, type Zippable, zipSync } from "fflate";
|
||||||
import { dirname, extname, relative, resolve, sep } from "node:path";
|
import { dirname, extname, relative, resolve, sep } from "node:path";
|
||||||
import { PFiles } from "./file.ts";
|
import { PFiles } from "../publication/file.ts";
|
||||||
import { md } from "./mdit/md.ts";
|
import { md } from "../mdit/md.ts";
|
||||||
import { renderTemplate, type TemplateVariables } from "./template_engine.ts";
|
import { renderTemplate, type TemplateVariables } from "../template/engine.ts";
|
||||||
|
|
||||||
type EpubConfig = {
|
type EpubConfig = {
|
||||||
journal: {
|
journal: {
|
||||||
File renamed without changes.
@@ -30,7 +30,6 @@ import { assertEquals } from "@std/assert";
|
|||||||
// async fn() {
|
// async fn() {
|
||||||
// },
|
// },
|
||||||
// });
|
// });
|
||||||
import { ripgrep } from "ripgrep";
|
|
||||||
Deno.test("default config is TOML with an asset base and vars table", async () => {
|
Deno.test("default config is TOML with an asset base and vars table", async () => {
|
||||||
const config = parseToml(await Deno.readTextFile("./config.toml")) as {
|
const config = parseToml(await Deno.readTextFile("./config.toml")) as {
|
||||||
asset_base: string;
|
asset_base: string;
|
||||||
@@ -56,7 +55,7 @@ Deno.test("ripgrep test", async () => {
|
|||||||
await writer.write(
|
await writer.write(
|
||||||
new TextEncoder().encode("This is a test string with NULL in it."),
|
new TextEncoder().encode("This is a test string with NULL in it."),
|
||||||
);
|
);
|
||||||
writer.releaseLock();
|
await writer.close();
|
||||||
const { code, stdout, stderr } = await child.output();
|
const { code, stdout, stderr } = await child.output();
|
||||||
console.log(`Exit code: ${code}`);
|
console.log(`Exit code: ${code}`);
|
||||||
console.log(`stdout: ${new TextDecoder().decode(stdout)}`);
|
console.log(`stdout: ${new TextDecoder().decode(stdout)}`);
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { Browser } from "playwright";
|
import { Browser } from "playwright";
|
||||||
import { resolve } from "node:path";
|
import { resolve } from "node:path";
|
||||||
import { pathToFileURL } from "node:url";
|
import { pathToFileURL } from "node:url";
|
||||||
import { PFiles } from "../file.ts";
|
import { PFiles } from "../publication/file.ts";
|
||||||
import { md } from "../mdit/md.ts";
|
import { md } from "../mdit/md.ts";
|
||||||
import TurndownService from "turndown";
|
import TurndownService from "turndown";
|
||||||
|
|
||||||
import "openpgp";
|
import "openpgp";
|
||||||
|
|
||||||
import { resolveChromiumPath } from "./utils.ts";
|
import { resolveChromiumPath } from "./utils.ts";
|
||||||
import { renderTemplate, type TemplateVariables } from "../template_engine.ts";
|
import { renderTemplate, type TemplateVariables } from "../template/engine.ts";
|
||||||
|
|
||||||
//原文->中间体(html)->目标格式(pdf/md/...)
|
//原文->中间体(html)->目标格式(pdf/md/...)
|
||||||
//生成pdf的流程:原文->中间体(html)->playwright渲染->pdf
|
//生成pdf的流程:原文->中间体(html)->playwright渲染->pdf
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { PFiles } from "../file.ts";
|
import { PFiles } from "../publication/file.ts";
|
||||||
import { PDFParse } from "pdf-parse";
|
import { PDFParse } from "pdf-parse";
|
||||||
import {
|
import {
|
||||||
PDFArray,
|
PDFArray,
|
||||||
@@ -168,10 +168,14 @@ export class IndexBuilder {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const missingTitles = titles.filter((title) => !this.indexed_map.has(title));
|
const missingTitles = titles.filter((title) =>
|
||||||
|
!this.indexed_map.has(title)
|
||||||
|
);
|
||||||
if (missingTitles.length > 0) {
|
if (missingTitles.length > 0) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Index coverage incomplete (${this.indexed_map.size}/${titles.length}); missing: ${missingTitles.join("、")}`,
|
`Index coverage incomplete (${this.indexed_map.size}/${titles.length}); missing: ${
|
||||||
|
missingTitles.join("、")
|
||||||
|
}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { OpenPGPSigner } from "./pdf_builder/utils.ts";
|
import { OpenPGPSigner } from "./utils.ts";
|
||||||
import { DocuBuilder } from "./pdf_builder/docu_builder.ts";
|
import { DocuBuilder } from "./docu_builder.ts";
|
||||||
import { IndexBuilder } from "./pdf_builder/index_builder.ts";
|
import { IndexBuilder } from "./index_builder.ts";
|
||||||
import type { TemplateVariables } from "./template_engine.ts";
|
import type { TemplateVariables } from "../template/engine.ts";
|
||||||
|
|
||||||
export type GPConfig = {
|
export type GPConfig = {
|
||||||
journal: {
|
journal: {
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { type GPConfig, processPdfConfig } from "./pdf_pipeline.ts";
|
import { type GPConfig, processPdfConfig } from "./pipeline.ts";
|
||||||
import type { TemplateVariables } from "./template_engine.ts";
|
import type { TemplateVariables } from "../template/engine.ts";
|
||||||
|
|
||||||
type WorkerRequest = {
|
type WorkerRequest = {
|
||||||
id: number;
|
id: number;
|
||||||
File renamed without changes.
@@ -33,12 +33,14 @@ Deno.test("parses detached column folders without an order prefix", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("parses finite JavaScript numbers as detached column order", () => {
|
Deno.test("parses finite JavaScript numbers as detached column order", () => {
|
||||||
for (const [prefix, expected] of [
|
for (
|
||||||
|
const [prefix, expected] of [
|
||||||
["-2.5", -2.5],
|
["-2.5", -2.5],
|
||||||
["+3.25", 3.25],
|
["+3.25", 3.25],
|
||||||
["1e3", 1000],
|
["1e3", 1000],
|
||||||
["0x10", 16],
|
["0x10", 16],
|
||||||
]) {
|
]
|
||||||
|
) {
|
||||||
const meta = new PFileMetadata(`/publication/${prefix}::专栏/1::文章.md`);
|
const meta = new PFileMetadata(`/publication/${prefix}::专栏/1::文章.md`);
|
||||||
assertEquals(meta.colume, "专栏");
|
assertEquals(meta.colume, "专栏");
|
||||||
assertEquals(meta.c_index, expected);
|
assertEquals(meta.c_index, expected);
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { basename, dirname, join, relative, resolve } from "node:path";
|
import { basename, dirname, join, relative, resolve } from "node:path";
|
||||||
import { cfg } from "./main.ts";
|
import { cfg } from "../main.ts";
|
||||||
|
|
||||||
type WebDavOptions = Record<string, unknown>;
|
type WebDavOptions = Record<string, unknown>;
|
||||||
type WebDavConfig = {
|
type WebDavConfig = {
|
||||||
File renamed without changes.
File renamed without changes.
@@ -1,6 +1,6 @@
|
|||||||
import { assertEquals } from "@std/assert";
|
import { assertEquals } from "@std/assert";
|
||||||
import { parse as parseToml } from "@std/toml";
|
import { parse as parseToml } from "@std/toml";
|
||||||
import { createTemplateVariables, renderTemplate } from "./template_engine.ts";
|
import { createTemplateVariables, renderTemplate } from "./engine.ts";
|
||||||
|
|
||||||
Deno.test("renders Nunjucks variables, conditionals, loops, and constants", () => {
|
Deno.test("renders Nunjucks variables, conditionals, loops, and constants", () => {
|
||||||
const result = renderTemplate(
|
const result = renderTemplate(
|
||||||
Reference in new issue
Block a user