bookcover-node
生成印刷就绪的书籍封面。部分 封套 一代系统。
npm install bookcover-node
这是书封面生成器的Node.js包装器。将文件写入临时目录; 产生的 typst CLI二进制文件,并回读编译后的输出。
需要 typst 在 $PATH.
看到 模式参考 这是作为参数传递的,它实际上配置了封面设计。
import {generate} from 'bookcover-node'
generate(options): Promise<GenerateResult>
interface GenerateOptions {
schema: unknown // raw schema (see above)
input_path: string // directory to search for background image
output_path: string // where to write the output file
format?: 'pdf'|'svg'|'png' // default: 'pdf'
ppi?: number // PNG resolution, default: 144
split?: boolean // also write front/back/spine panel files
pdf_pages?: boolean // PDF: front and back pages (no spine), bleed all round
assets_dir?: string // root of the assets tree (see "Assets" below)
fonts_dir?: string // fonts tree if kept elsewhere, default: <assets_dir>/fonts
typst_path?: string // typst CLI binary, default: 'typst' from $PATH
custom_fonts?: CustomFont[] // user-uploaded font families (from typst-fonts)
// Filename of the built-in background the image is (e.g. 'beach.jpg') — colors come from its
// baked data, whichever copy of it is in input_path
image_builtin?: string
}
interface GenerateResult {
output_path: string
split_paths?: {front: string, back: string, spine?: string}
}
资产
Typst模板被捆绑在里面 bookcover-core 本身(绑到确切的安装)
版本-不需要设置)。生成仍然需要本地字体集合,而本地字体集合不需要
在NPM包中发布。设置它一次,并将其路径传递为 assets_dir
(或 fonts_dir 直接):
# Fonts — download the curated families + Noto fallbacks named by the repo's font config
curl -O https://raw.githubusercontent.com/gracious-tech/bookcover/main/font_config.json
npx typst-fonts-download --fonts assets/fonts --config font_config.json
这将产生预期的布局:
assets/
fonts/ manifest.json, <family>/, _noto/<family>/
在 封套回购 本身 assets_dir
可以省略-它默认是回购自己的 assets/ dir。
例子
import {generate} from 'bookcover-node'
await generate({
schema: {
title1: 'My Book',
author: 'Jane Doe',
page_count: 200,
printer: {service: 'kdp', binding_type: 'paperback', ink_type: 'bw', paper_type: 'white'},
size_id: 'us_trade',
},
input_path: '.',
output_path: './cover.pdf',
assets_dir: './assets',
})