简单来说
把历史课本里相对的两页当作一页来排:一条彩色的带子横过书的中间,下面挂着六张带插图的卡片,而模板只画一张卡片和一条线,不管有多少个日期。
成品一览
初中历史课本的第48、49页:《纸的旅程》,从蔡伦的作坊到凯勒的磨石,造纸术走过的一千年。左页是标题和两段导语,右页是一个方框,讲手工抄一张纸的步骤。年表从两页中间横穿而过:亚洲一段用靛蓝色带,欧洲一段用赭红色带,后者从左页开始,跨过书脊。色带下面挂着六张卡片,每张有一幅插图,用一个圆环和一条竖线连到色带上。模板里只有一张亚洲卡片、一张欧洲卡片,每条色带一条连接线:网格组按Markdown里的每个日期放一张卡片,连接线再找到网格放下的所有卡片。所有文字都写在Markdown里,有西班牙语、英语和日语三个版本;本页显示西班牙语版。
这道食谱解答
- 怎样把年表排成跨页,让一条色带跨过书脊,卡片分布在两页上?
- 怎样让一行方框分配宽度,文字最长的那个变宽?
简短回答
const pageTemplates = [{
id: 'timeline',
spread: true, // two facing pages laid as one sheet; it opens on a verso
gutter: mm(10), // the band round the spine that frames keep off
grid: { columns: 2, rows: ROWS, columnGap: mm(2 * PAGE.inner), rowGap: mm(ROW_GAP) },
frames: [
{ name: 'title', takes: 'h1' },
{ name: 'lead', flow: true, fit: { minScale: 0.8 } },
{ name: 'box', style: 'box', grid: { col: 2, row: 1, rows: 4 }, height: 'fill',
padding: { right: mm(66) }, fit: { minScale: 0.85 } },
{ name: 'box-picture', layer: 2, width: mm(56), placement: at('#box', 'top-right', -5, 10) },
{ name: 'band-1', style: 'band-asia', grid: { col: 1, row: 5 }, height: mm(BAND) },
{ name: 'band-2', style: 'band-europe', crossGutter: true, width: 'fill', height: mm(BAND),
padding: { left: mm(2 * PAGE.inner + 4) }, // the colour crosses the fold, the words do not
placement: at('#band-1', 'right-of') },
card('asia', 'card-asia'), card('europe', 'card-europe'),
{ name: 'colophon', style: 'colophon', optional: true, width: mm(170),
placement: at('page', 'bottom-right', -PAGE.outer, -7) },
],
groups: [
{ name: 'opening', kind: 'stack', grid: { col: 1, row: 1, rows: 4 }, gap: mm(4),
frames: ['title', 'lead'] },
// A row of cards under each band, as many as the Markdown has: a longer text makes its
// row taller, and the other cards of the row stretch to the same height.
row('asia', 1), row('europe', 2),
],
decoration: { elements: [ground(), ticks('band-1', 'asia'), ticks('band-2', 'europe')] },
}];
用料
- 类型
- Literata, Archivo, Noto Serif JP, Noto Sans JP(SIL OFL 1.1)
- 素材
forma-800.jpgv105-1000.jpgv1150-1000.jpgv1282-1000.jpgv1844-1000.jpgv610-1000.jpgv751-1000.jpg- A Han court official watches a craftsman lift a bamboo mould from a vat. (Generated With Diffusion Models, 原创)
- A monk shows two Japanese courtiers how to hold a papermaking mould. (Generated With Diffusion Models, 原创)
- Papermakers by a canal in Samarkand, sheets drying on a wall. (Generated With Diffusion Models, 原创)
- A paper workshop below the castle of Xàtiva. (Generated With Diffusion Models, 原创)
- A Fabriano mill with its water wheel; a sheet held up to the light. (Generated With Diffusion Models, 原创)
- A craftsman grinds a spruce log against a stone into wood pulp. (Generated With Diffusion Models, 原创)
- Two hands lift a papermaker's mould from a vat of pulp. (Generated With Diffusion Models, 原创)
做法
#1 · 两页共用一张纸
const pageTemplates = [{
id: 'timeline',
spread: true, // two facing pages laid as one sheet; it opens on a verso
gutter: mm(10), // the band round the spine that frames keep off
grid: { columns: 2, rows: ROWS, columnGap: mm(2 * PAGE.inner), rowGap: mm(ROW_GAP) },
frames: [
{ name: 'title', takes: 'h1' },
{ name: 'lead', flow: true, fit: { minScale: 0.8 } },
{ name: 'box', style: 'box', grid: { col: 2, row: 1, rows: 4 }, height: 'fill',
padding: { right: mm(66) }, fit: { minScale: 0.85 } },
{ name: 'box-picture', layer: 2, width: mm(56), placement: at('#box', 'top-right', -5, 10) },
{ name: 'band-1', style: 'band-asia', grid: { col: 1, row: 5 }, height: mm(BAND) },
{ name: 'band-2', style: 'band-europe', crossGutter: true, width: 'fill', height: mm(BAND),
padding: { left: mm(2 * PAGE.inner + 4) }, // the colour crosses the fold, the words do not
placement: at('#band-1', 'right-of') },
card('asia', 'card-asia'), card('europe', 'card-europe'),
{ name: 'colophon', style: 'colophon', optional: true, width: mm(170),
placement: at('page', 'bottom-right', -PAGE.outer, -7) },
],
groups: [
{ name: 'opening', kind: 'stack', grid: { col: 1, row: 1, rows: 4 }, gap: mm(4),
frames: ['title', 'lead'] },
// A row of cards under each band, as many as the Markdown has: a longer text makes its
// row taller, and the other cards of the row stretch to the same height.
row('asia', 1), row('europe', 2),
],
decoration: { elements: [ground(), ticks('band-1', 'asia'), ticks('band-2', 'europe')] },
}];
spread: true把模板变成一张和两页一样宽的纸,页面块也用spread标明这一点。跨页从左页开始,所以排版时传入continuation: { pageIndexOffset: 1, pageNumbering: { startAt: 48 } }:这段节选的第1页就是书的第48页,是左页,前面不需要空白页。网格每页一栏,两栏之间的间距是内侧页边距的两倍,所以只有色带靠近书脊。第二条色带设了crossGutter和36毫米的左内边距:颜色接着第一条色带跨过书脊,文字从右页开始,排版也在右页读取这些文字。
#2 · 一张卡片,由网格重复
// Each `:::frame{slot="asia"}` of the page is an item of the `asia` grid: the grid lays the
// card frame once per item, three to a row, and names the copies `#asia[1]`, `#asia[2]`…
const card = (name, style) => ({ name, style, minHeight: mm(CARD) }); // auto above that height
const row = (name, col) => ({ name: `${name}-row`, kind: 'grid', columns: 3, columnGap: mm(5),
grid: { col, row: 6, rows: ROWS - 5 }, repeat: { frames: [name] } });
kind: 'grid'加上repeat: { frames: ['asia'] }的组,会为页面里的每个:::frame{slot="asia"}放一次asia框,每行三张,放在模板网格的col: 1单元里,占第6到第12行。这些副本叫#asia[1]、#asia[2]和#asia[3],各自取自己那个块的label,也就是标签上的年份。卡片至少有minHeight那么高,超过就是auto:某段文字变长时(比如西班牙语版和日语版里1844年那张),它所在的行会长高,同一行的其他卡片也拉到同样的高度(rowAlign默认是'stretch')。Markdown里再加第四个日期,就在第一行下面开出第二行,模板不用改。
#3 · 每条色带一条连接线
// `routing: 'tree'` with `trunk: 0` draws no bar of its own: each drop hangs from the band's
// foot straight down to the middle of a card's top, and `#asia[*]` names every card laid.
function ticks(band, cards) {
return { kind: 'connector', id: `${cards}-ticks`, routing: 'tree', trunk: 0,
from: { to: `#${band}`, side: 'bottom', gap: mm(2.4) }, to: { to: `#${cards}[*]`, side: 'top' },
color: col(cards), width: pt(1), startCap: 'ring', capSize: mm(3.6) };
}
这些竖线是模板装饰(decoration)里的connector,每条色带一条。routing: 'tree'把一个父元素连到多个子元素;设了trunk: 0就不画自己的横杠,只从色带底边垂直画到每张卡片上边的中点,startCap: 'ring'在每条竖线的顶端放一个圆环,位于色带下方2.4毫米处(gap)。圆环是按线宽描出的空心圆点,外缘直径3.6毫米(capSize);竖线停在圆环外缘,所以环里露出米色的底。#asia[*]指网格在这一页放下的所有卡片,所以在Markdown里增删一个日期,它的竖线也随之增删。连接线在框排好之后才画,所以某一行长高时,竖线仍然连到卡片上。米色的底也是装饰:一个锚定在出血底边的方块,高度向上到#band-1的底边为止(size: { height: { to: '#band-1', edge: 'bottom' } }),所以它跟着色带走。
#4 · 按印刷尺寸放的插图
const ART = {
v105: t({ es: 'Un funcionario de la corte Han mira cómo un artesano saca de la tina un molde '
+ 'de bambú lleno de pasta, junto a corteza, trapos y redes viejas.',
en: 'A Han court official watches a craftsman lift a bamboo mould full of pulp from a vat, '
+ 'beside bark, rags and old nets.',
ja: '漢の役人が見守るなか、職人が竹のすき枠を漉き舟から引き上げる。そばに樹皮、ぼろ布、古い網。' }),
v610: t({ es: 'Un monje enseña a dos cortesanos japoneses a sostener el molde sobre una tina, '
+ 'con ramas de kozo en una estera.',
en: 'A monk shows two Japanese courtiers how to hold the mould over a tub, with kozo '
+ 'branches on a mat.',
ja: '僧が二人の宮廷人に、桶の上ですき枠を持つ手つきを見せる。むしろの上に楮の枝。' }),
v751: t({ es: 'Papeleros de Samarcanda junto a un canal; las hojas se secan al sol contra un '
+ 'muro de adobe.',
en: 'Samarkand papermakers by a canal; the sheets dry in the sun against a mud-brick wall.',
ja: '水路のそばで働くサマルカンドの紙すき職人。日干しれんがの壁に紙が張られて乾いている。' }),
v1150: t({ es: 'Un taller de Xàtiva bajo el castillo: un operario golpea trapos en una pila '
+ 'de piedra y las hojas cuelgan de cuerdas.',
en: 'A workshop in Xàtiva below the castle: a worker pounds rags in a stone trough and the '
+ 'sheets hang on ropes.',
ja: '城の下のシャティバの工房。職人が石の槽でぼろ布をたたき、紙が綱につるされている。' }),
v1282: t({ es: 'Un molino de Fabriano con su rueda hidráulica y sus mazos; un papelero mira '
+ 'una filigrana al trasluz.',
en: 'A Fabriano mill with its water wheel and hammers; a papermaker holds a watermark up '
+ 'to the light.',
ja: '水車と木づちのあるファブリアーノの製紙場。職人が紙を光にかざして透かしを見ている。' }),
v1844: t({ es: 'Un artesano aprieta un tronco de abeto contra una muela que gira; debajo se '
+ 'amontonan las fibras.',
en: 'A craftsman presses a spruce log against a turning grindstone; the fibres pile up '
+ 'below.',
ja: '職人がトウヒの丸太を回る砥石に押し当て、その下に木の繊維が積もっていく。' }),
forma: t({ es: 'Dos manos sacan de la tina el molde con una capa fina de fibras.',
en: 'Two hands lift the mould from the vat with a thin layer of fibres on it.',
ja: '両手ですき枠を引き上げる。網の上に繊維の薄い層ができている。' }),
};
const SIZE = { forma: [800, 800, 363] }; // pixels and ppi: 56 mm wide; the cards' are 46 mm
const resources = await Promise.all(Object.entries(ART).map(async ([id, altText]) => {
const px = SIZE[id] ?? [1000, 667, 550];
const fileId = `${id}-${px[0]}.jpg`;
await loadImage(fileId, asset(fileId));
return { id, typeId: 'picture', kind: 'bitmap', caption: '', altText, createdAt: 0,
updatedAt: 0,
bitmap: { fileId, format: 'jpeg', width: px[0], height: px[1], resolution: px[2] } };
}));
插图宽1000像素,分辨率550 ppi,在页面上宽46毫米,而图片从不放大。网格的三栏等宽,每页每栏56.3毫米,所以每幅插图都能按原尺寸放进卡片3.5毫米的内边距里,卡片其余的地方留给文字。
完整食谱
// ═══ Postext Cookbook · Nº 158 · An illustrated timeline across a double page ═══════
// https://postext.dev/en/cookbook/illustrated-timeline-spread
// Code: MIT · Text: original (CC BY 4.0) · Pictures: generated with diffusion models
// Fonts: Literata, Archivo, Noto Serif JP, Noto Sans JP (SIL OFL 1.1) · Needs postext ≥ 1.49.0
import {
buildDocument, withLoadedFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { renderToPdf, decompressWoff2 } from 'https://esm.sh/postext-pdf';
const LANG = 'es'; // @lang: the language of the sample document ('es' | 'en' | 'ja')
const RECIPE = 'illustrated-timeline-spread';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: one ink, an accent for each half of the timeline, a pale ground
const palette = {
ink: '#22201d', // text
asia: '#2f4f7a', // indigo: the Asian half of the timeline
europe: '#a2412a', // terracotta: the European half
ground: '#f1ebdf', // the cream under the cards
rule: '#c9bfae', // hairlines and the card borders
muted: '#6b6359', // running heads and the colophon
paper: '#ffffff',
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'europe (defaults)', value: { hex: palette.europe, model: 'hex' } },
];
// #endregion
const JA = LANG === 'ja';
const SERIF = JA ? 'Noto Serif JP' : 'Literata';
const SANS = JA ? 'Noto Sans JP' : 'Archivo';
// A Western textbook page is 210 × 280 mm; a Japanese one is AB判, 210 × 257 mm.
const PAGE = { w: 210, h: JA ? 257 : 280, top: 22, bottom: 20, inner: 16, outer: 15 };
const ROWS = 12;
const ROW_GAP = 3;
const ROW = (PAGE.h - PAGE.top - PAGE.bottom - (ROWS - 1) * ROW_GAP) / ROWS; // one grid row, mm
const BAND = 9; // the timeline band, in grid row 5
const CARD_TOP = 5 * (ROW + ROW_GAP); // grid row 6
// The drawn height of a card; 16 mm of the area stay free for a longer text.
const CARD = PAGE.h - PAGE.top - PAGE.bottom - CARD_TOP - 16;
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
// #region cards: one card frame per row, repeated by a grid once for each card of the Markdown
// Each `:::frame{slot="asia"}` of the page is an item of the `asia` grid: the grid lays the
// card frame once per item, three to a row, and names the copies `#asia[1]`, `#asia[2]`…
const card = (name, style) => ({ name, style, minHeight: mm(CARD) }); // auto above that height
组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)
变化
#每行四张卡片
设成columns: 4后,每条色带下并排放四个日期;卡片变窄,文字占的行数变多,各行也随之往下长。
-const row = (name, col) => ({ name: `${name}-row`, kind: 'grid', columns: 3, columnGap: mm(5),
+const row = (name, col) => ({ name: `${name}-row`, kind: 'grid', columns: 4, columnGap: mm(5),#用箭头代替圆环
endCap: 'arrow'在每条竖线碰到卡片的地方画一个箭头,startCap: 'none'去掉圆环。
常见问题
- 网格每个条目放一个单元格,而一个条目就是一个单独的
:::frame{slot="asia"}块:把两张卡片的文字写在同一个块里,只会得到一张卡片。 - 不带
[*]的#asia指的是网格本身的方框,而不是里面的卡片:连到它的连接线只画一条竖线,落在这一行的正中。 - 延伸到另一个方框边缘的尺寸,从元素自己的锚点算起:米色的底锚定在出血底边,向上长到
#band-1。位于锚点后方的边,得到的高度是0。
致谢
- 文本
- The paper road, a double-page timeline written for this recipe in Spanish, English and Japanese · Postext Cookbook · CC BY 4.0
- 图片
- A Han court official watches a craftsman lift a bamboo mould from a vat. · Generated With Diffusion Models · 原创
- A monk shows two Japanese courtiers how to hold a papermaking mould. · Generated With Diffusion Models · 原创
- Papermakers by a canal in Samarkand, sheets drying on a wall. · Generated With Diffusion Models · 原创
- A paper workshop below the castle of Xàtiva. · Generated With Diffusion Models · 原创
- A Fabriano mill with its water wheel; a sheet held up to the light. · Generated With Diffusion Models · 原创
- A craftsman grinds a spruce log against a stone into wood pulp. · Generated With Diffusion Models · 原创
- Two hands lift a papermaker's mould from a vat of pulp. · Generated With Diffusion Models · 原创
- 字体
- Literata (SIL OFL 1.1) · Archivo (SIL OFL 1.1) · Noto Serif JP (SIL OFL 1.1) · Noto Sans JP (SIL OFL 1.1)


