باختصار
الصفحات الأولى من طبعة إيطالية للأطفال من Pinocchio. يبدأ كل فصل بصورة مرسومة بألوان هادئة خاصة به وملخّص قصير لما يجري فيه.
ما الذي ستنضده
الصفحات الأولى من طبعة إيطالية للأطفال من رواية Le avventure di Pinocchio لـCollodi، منضّدة بخط Averia Serif Libre بحجم 13 على 19 pt في صفحة مقاسها 190 × 240 mm. صفحة عنوان على الصفحة الزوجية تقابل الفصل الأول: لوحة مائية للتلال التوسكانية، تحمل فيها عربة حمار الحطب إلى ورشة نجار، فوق العنوان بخط Fredericka the Great. يبدأ كل فصل تحت صورة رأسية بالألوان المائية تتلاشى في الورق (Maestro Ciliegia وفأسه مرفوعة فوق الجذع المتكلّم في الفصل الأول، وGeppetto بشعره المستعار الأصفر يأخذ الجذع في الفصل الثاني)، ثم سطر الفصل وملخّص Collodi بالمائل في الوسط. الصور الأربع كلها مولّدة بنماذج الانتشار من وصف أسلوب واحد ولوحة ألوان الصفحة. لا تُطبع الترويسات إلا في الصفحتين 8 و9، وهما الصفحتان اللتان ليس فيهما صفحة افتتاح. أرقام الصفحات في أقراص بلون الخشب، وحبتا كرز تختمان الفصل الأول من غير تعليق ولا رقم.
تجيب هذه الوصفة عن
- كيف أعطي كل فصل صورته أو لونه أو شكل افتتاحه الخاص؟
- كيف أنضد رسومًا غير مرقّمة: زخارف، وحليات، وشعارات؟
- كيف أضيف إلى صفحة الافتتاح سطر المؤلف أو مقدمة تمهيدية أو فقرة أولى بحرف استهلالي؟
- كيف أخفي الترويسات في صفحات الافتتاح والصفحات الفارغة، أو ألوّن صفحة زوجية فارغة بلون الجزء؟
الجواب المختصر
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's
const opener = { enabled: true,
// A floor for the height the opener reserves, in whole lines, so the text under chapter I's
// two-line summary starts on the same grid line as the text under chapter II's three lines.
minHeight: pt(14 * LEAD),
slot: { elements: [
{ kind: 'image', id: 'vignette', resourceId: '{attr.vignetta}',
placement: at('container', 'top', 0, 0,
{ width: mm(VIGNETTE.width), height: mm(VIGNETTE.height) }) },
// The chapter line 6 mm under the picture's foot, the summary 5 mm under the chapter line.
text('chapter', '{titleText}', DISPLAY, 24, at('container', 'top-left', 0,
VIGNETTE.height + 6, { width: mm(MEASURE) }), { ...caps(2.4), lineHeight: 1 }),
text('summary', '{attr.summary}', TEXT, 12.5, at('#chapter', 'below',
(MEASURE - SUMMARY) / 2, 5, { width: mm(SUMMARY) }), { italic: true, lineHeight: 1.38 }),
] },
};
const chapter = { id: 'capitolo', advancedDesign: opener };
المكونات
- الميزات
- صفحات افتتاح مصمَّمةالصور في تصاميم الصفحةالترويسات وأرقام الصفحاتأنماط العناوينسمات العنوانفصول تبدأ في صفحة فرديةالنصوص والخطوط والمربعات في تصاميم الصفحةالترويسات بحسب دور الصفحةأنواع موارد مخصّصةأشكال في هذا الموضع بالضبطالأشكال والجداول بوصفها مواردتقسيم الكلمات ولغة المستندهوامش متناظرةلوحة ألوان دلاليةصفحات على اللوحة (Canvas)
- تستخدم أيضًا
- لون الورقأنماط الفقراتترويسات لكل قسم
- الخطوط
- Averia Serif Libre, Fredericka the Great, Quicksand (SIL OFL 1.1)
- الأصول
ceppo-1200.jpgciliegie-600.jpgfrontespizio-1400.jpgpolenta-1200.jpg- The frontispiece: Tuscan hills, a hill village and a donkey cart of firewood on its way to the carpenter’s workshop (Generated With Diffusion Models, أصلي)
- Chapter I’s vignette: Maestro Ciliegia, axe raised over the talking log (Generated With Diffusion Models, أصلي)
- Chapter II’s vignette: Geppetto in his yellow wig receives the log, beside a pot of polenta (Generated With Diffusion Models, أصلي)
- The cherry tailpiece (Generated With Diffusion Models, أصلي)
طريقة التحضير
#1 · نمط عنوان واحد، وصورة رأسية يسمّيها كل عنوان
شيفرة هذه الخطوة هي الجواب المختصر. يقبل resourceId في عنصر الصورة العناصر النائبة نفسها التي يقبلها نص التصميم، فيرسم '{attr.vignetta}' المورد الذي يحدّده العنوان، كما يطبع {attr.summary} ملخّصه. يتقاسم الفصلان النمط capitolo ويحدّد كل منهما صورته على سطر العنوان: # Capitolo II {style="capitolo" vignetta="polenta" summary="…"}. الفصل الثالث يحتاج موردًا إضافيًا وعنوانًا إضافيًا، لا نمطًا آخر (عناصر الصورة). يوضع سطر الفصل بالقياس من أعلى الحاوية، على بعد 6 mm تحت مستطيل الصورة الرأسية، ويتدلّى الملخّص 5 mm تحته؛ وتحجز صفحة الافتتاح ارتفاعًا يصل إلى آخر سطر في الملخّص. ومع minHeight حدًّا أدنى من 14 سطرًا، يبدأ نص الفصل الأول على السطر نفسه الذي يبدأ عليه نص الفصل الثاني، الذي يزيد ملخّصه سطرًا؛ ومن دونه يبدأ نص الفصل الأول أعلى بـ6.7 mm (الامتداد والتصميم المتقدم).
#2 · حمّل اللوحات موارد نقطية
const PICTURES = { // id: [file, width, height, alt text in the book's language]
frontespizio: ['frontespizio-1400.jpg', 1400, 1105, 'Colline toscane con cipressi e un borgo; '
+ 'un contadino guida un asinello con un carretto di legna verso la bottega di un falegname.'],
ceppo: ['ceppo-1200.jpg', 1200, 800, 'Maestro Ciliegia, con la scure alzata sopra un pezzo di '
+ 'legno sul banco, si guarda intorno spaventato.'],
polenta: ['polenta-1200.jpg', 1200, 800, 'Geppetto, con la parrucca gialla, riceve il pezzo di '
+ 'legno da Maestro Ciliegia; accanto, un paiolo di polenta fumante.'],
ciliegie: ['ciliegie-600.jpg', 600, 626, 'Due ciliegie rosse su un picciolo, con una foglia.'],
};
const resources = Object.entries(PICTURES).map(([id, [fileId, w, h, altText]]) => ({
id, typeId: 'fregio', kind: 'bitmap', createdAt: 0, updatedAt: 0, altText,
bitmap: { fileId, format: 'jpeg', width: w, height: h } }));
كل صورة ملف JPEG في المجلد assets/ الخاص بالوصفة، مصرَّح بها بمقاسها بالبكسل: لا يقرأ الإخراج إلا هذه المقاسات، ويرسم Canvas ما سجّلته loadImage() تحت معرّف كل ملف حين ترسم الصفحة. وُلّدت الصور الرأسية وحبتا الكرز على خلفية بيضاء ثم ضُربت في لون الورق #fffaf0، فتُطبع حوافها بلون الصفحة ولا تظهر للصور حافة. صورة الواجهة مقصوصة بنسبة 190:150، أي بشكل مساحتها، فتملأ الصورة المحجّمة المساحة من غير شريط من الورق. المنظر الطبيعي والصور الرأسية ترسمها عناصر صورة في التصاميم، وحبتا الكرز يرسمهما ::resource{id="ciliegie"} في Markdown.
#3 · اجعل صفحة العنوان نمط عنوان
const SKY = 150; // mm from the top edge: the foot of the painted field
// # Pinocchio {style="frontespizio" kicker="Le avventure di"}; subtitle and author come from
// the frontmatter. Every element hangs from the page, so the field runs off three edges.
const frontispiece = {
id: 'frontespizio',
footer: { elements: [] }, // no folio; the running heads already skip openers
advancedDesign: { enabled: true, slot: { elements: [ // array order is paint order
{ kind: 'image', id: 'landscape', resourceId: 'frontespizio', // cut to the field's 190:150
placement: at('page', 'top-left', 0, 0, { width: 'fill', height: mm(SKY) }) },
text('kicker', '{attr.kicker}', LABEL, 11, at('page', 'top', 0, SKY + 11),
{ ...caps(2.6), fontWeight: 700 }),
text('title', '{titleText}', DISPLAY, 70, at('page', 'top', 0, SKY + 17),
{ lineHeight: 1, color: col('bark') }),
text('subtitle', '{subtitle}', TEXT, 15, at('page', 'top', 0, SKY + 44), { italic: true }),
text('author', '{author}', LABEL, 9, at('page', 'top', 0, SKY + 58),
{ ...caps(2), fontWeight: 600 }),
] } },
};
صفحة العنوان هي أول عنوان في Markdown، # Pinocchio {style="frontespizio" kicker="Le avventure di"}، ونمطها يرسم كل ما في الصفحة: المنظر الطبيعي، بعمق 150 mm من الحافة العليا، ثم السطر التمهيدي من السمة، والعنوان، والعنوان الفرعي والمؤلف من البيانات التمهيدية (frontmatter). كل العناصر مربوطة بالصفحة لا بكتلة النص، فتبلغ اللوحة الحافة العليا وجانبَي الورقة مع أن العنوان نفسه يبقى في عمود الكتاب الوحيد. ويزيل footer الفارغ قرص رقم الصفحة الذي تطبعه صفحات افتتاح الفصول، وpages: 'body' يُبعد الترويسات عن الصفحة أصلًا (أنماط العناوين).
#4 · ترويسات على صفحات النص، وأرقام الصفحات في أقراص
// The excerpt opens on book page 6, a verso, so the title page faces chapter I.
const continuation = { pageIndexOffset: 5, pageNumbering: { startAt: 6 } };
const SHIFT = (INNER - OUTER) / 2; // mm: the text block's centre sits off the page's centre
const head = (id, content, parity, x) => text(id, content, LABEL, 8,
at('page', 'top', x, 12), { ...caps(1.8), fontWeight: 600, parity, pages: 'body' });
const DISC = 7.4; // mm: the folio's disc
// A fixed square with a radius of half its side is a circle; the figures sit in its middle.
// lineHeight 1.17: the baseline falls at 0.8 of the line, 0.94 em down, so Quicksand's
// figures (0.70 em tall) leave 0.23 em above and below them, and 'middle' centres that line.
const disc = (id, parity, pages, edge, x) => text(id, '{pageNumber}', LABEL, 8.5,
at('page', edge, x, -(BOTTOM - DISC) / 2, { width: mm(DISC), height: mm(DISC) }),
{ fontWeight: 700, color: col('paper'), lineHeight: 1.17, verticalAlign: 'middle', parity,
pages, box: { backgroundColor: col('wood'), borderRadius: mm(DISC / 2) } });
const header = { elements: [
head('verso-title', '{title}', 'even', -SHIFT), // the book on the left-hand page
head('recto-chapter', '{chapterTitle}', 'odd', SHIFT), // the chapter on the right
] };
const footer = { elements: [
disc('verso-folio', 'even', 'body', 'bottom-left', OUTER),
disc('recto-folio', 'odd', 'body', 'bottom-right', -OUTER),
disc('opener-folio', 'all', 'opener', 'bottom', 0), // a chapter opens on either side
] };
يرقّم continuation المقتطف ابتداءً من الصفحة 6 من الكتاب، وهي صفحة زوجية، فتقابل صفحة العنوان الفصل الأول، وأول رقم صفحة مطبوع هو 7. يُبعد pages: 'body' الترويسات عن صفحة العنوان وعن صفحتَي الافتتاح، فلا تُطبع إلا في الصفحتين 8 و9، عنوان الكتاب على الصفحة الزوجية وعنوان الفصل على الفردية (عناصر النص). رقم الصفحة نص تصميم في مربع ثابت ضلعه 7.4 mm، ونصف قطر زواياه نصف ضلعه، فيصير دائرة؛ ويضع verticalAlign: 'middle' وارتفاع السطر المحسوب في التعليق الأرقامَ في وسطها. الأرقام بلون الورق نسبة تباينها 4.98:1 مع لون الخشب. ولا تحتاج التسميات المتباعدة الحروف إلى أي إزاحة: فعند توسيط السطر لا يُحتسب تباعد الحروف الذي يلي آخر حرف فيه.
#5 · اختم الفصل بزخرفة ختامية غير مرقّمة
// No caption prefix and no caption, so the cherries that close chapter I print with no
// label or number. The pictures the design slots paint are of this type too.
const resourceTypes = [{ id: 'fregio', name: 'Fregio', namePlural: 'Fregi', shortLabel: 'Fregio',
captionPrefix: '', numberingTemplate: '{n}', resetOn: 'never', counterFormat: 'decimal',
defaultPlacement: { position: 'here', width: 0.16, align: 'center' } }];
يطبع نوع المورد captionPrefix الخاص به ورقمه قبل التعليق. مع بادئة فارغة ومن غير تعليق لا يُطبع شيء تحت حبتي الكرز؛ ومع captionPrefix: 'Fregio' يطبع المورد نفسه Fregio 1. تحت الرسم ويزيد طوله 10 mm (أنواع الموارد). يضع defaultPlacement في النوع كل مورد حيث يقف سطر ::resource الخاص به، بعرض سدس عرض السطر وفي الوسط، فلا يحتاج Markdown إلا إلى ::resource{id="ciliegie"} بعد آخر فقرة في الفصل. الصور الأخرى تتقاسم النوع، لكن لا :ref ولا ::resource يذكرها، فلا توضع ولا تُعدّ أبدًا.
الوصفة كاملة
// ═══ Postext Cookbook · Nº 066 · Storybook chapters with vignettes and summaries ═══
// https://postext.dev/en/cookbook/storybook-chapter-vignettes
// Code: MIT · Text: C. Collodi, 1883 (PD, Gutenberg #52484) · Pictures: diffusion models
// Fonts: Averia Serif Libre, Fredericka the Great, Quicksand (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document (the sample is Italian in both)
const RECIPE = 'storybook-chapter-vignettes';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
const palette = { // every colour in the config comes from here; the pictures were painted to it
ink: '#2b2118', // text: a brown near-black
paper: '#fffaf0', // a warm book paper, which the vignettes' margins were tinted to
bark: '#6b4224', // chapter lines, running heads, the title
wood: '#9a5f30', // the folio discs
};
// col(id): a colour linked to its palette entry, with the entry's hex beside the id.
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' } })),
// The defaults linked to main-color, bold among them, print in bark instead of blue.
{ id: 'main-color', name: 'bark (defaults)', value: { hex: palette.bark, model: 'hex' } },
];
// Text and summaries; the book's title and the chapter lines; running heads and folios.
const [TEXT, DISPLAY, LABEL] = ['Averia Serif Libre', 'Fredericka the Great', 'Quicksand'];
const TRIM = { width: 190, height: 240 }; // mm
const [TOP, INNER, OUTER] = [22, 22, 20]; // mm; mirrored, so the spine margin swaps sides
const MEASURE = TRIM.width - INNER - OUTER; // 148 mm
const [BODY, LEAD, LINES] = [13, 19, 29]; // pt, pt, and whole lines in the text block
const BOTTOM = TRIM.height - TOP - (LINES * LEAD * 25.4) / 72; // mm: 23.6
// Design-slot shorthands: a placement from an anchor's edge (mm), and a design text.
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });
const text = (id, content, fontFamily, size, placement, extra = {}) => ({ kind: 'text', id,
content, fontFamily, fontSize: pt(size), color: col('ink'), align: 'center',
overflow: 'wrap', // a long line wraps in every slot, the running heads too
placement, ...extra });
const caps = (tracking) => ({ textTransform: 'uppercase', letterSpacing: pt(tracking),
color: col('bark') });
// #region answer: one opener for every chapter: the vignette the heading names, then its summary
// # Capitolo I {style="capitolo" vignetta="ceppo" summary="Come andò che Maestro Ciliegia…"}
// resourceId takes placeholders like a design text: '{attr.vignetta}' draws the resource the
// heading names, so every chapter shares one style.
const VIGNETTE = { width: 84, height: 56 }; // mm, centred at the head of the text block
const SUMMARY = 124; // mm: the summary's measure, narrower than the text's
يعمل ملف script.js المجمّع كما هو: الصقه في سكربت الوحدة (module) لأي صفحة، أو افتح الوصفة على CodePen. مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)
تنويعات
#ابدأ كل فصل في صفحة فردية
مع 'odd' ينتقل الفصل الثاني إلى الصفحة 11 وتُترك الصفحة 10 فارغة؛ وتوقف صفحة العنوان فاصلها الخاص، لأنها ترث فاصل المستوى، ولولا ذلك لانتقلت إلى الصفحة 7 بعد صفحة 6 فارغة.
@@ the frontispiece style @@
id: 'frontespizio',
+ breakBefore: { enabled: false },
@@ headings, in config() @@
- levels: [{ level: 1, breakBefore: { enabled: true, parity: 'any' } }],
+ levels: [{ level: 1, breakBefore: { enabled: true, parity: 'odd' } }],أخطاء شائعة
خطأ شائع
قيم السمات: لا { ولا }؛ ضع القيمة التي فيها " بين علامتي اقتباس مفردتين
تنتهي قيمة السمة عند القوس المعقوف الختامي، فلا يمكن أن تحتوي { أو }. القيمة التي فيها علامة اقتباس مزدوجة توضع بين علامتي اقتباس مفردتين؛ أما علامة الدولار فلا مشكلة فيها. سمات العنوان →
- في Markdown تربط مسافة غير قابلة للكسر (U+00A0) كل شرطة من شرطات الحوار عند Collodi بكلمتها، فلا تبدأ شرطة إغلاق سطرًا أبدًا؛ واثنتان أخريان تبقيان di legno وin piedi متلازمتين في آخر فقرتيهما. وتصمد هذه الروابط كذلك في فقرة فيها عريض أو مائل، مثل الفقرة التي فيها ohi في الصفحة 9، وفيها أربعة.
الحقوق
- الوصفة
- Ignacio Ferro
- النص
- Le avventure di Pinocchio (1883): chapter I and the opening of chapter II with Collodi’s chapter summaries, from the 1902 Bemporad edition, with typographic apostrophes, dashes and ellipses; chapter I’s summary has the comma after “falegname” that the edition’s table of contents prints and its chapter head leaves out · Carlo Collodi · ملك عام
- الصور
- The frontispiece: Tuscan hills, a hill village and a donkey cart of firewood on its way to the carpenter’s workshop · Generated With Diffusion Models · أصلي
- Chapter I’s vignette: Maestro Ciliegia, axe raised over the talking log · Generated With Diffusion Models · أصلي
- Chapter II’s vignette: Geppetto in his yellow wig receives the log, beside a pot of polenta · Generated With Diffusion Models · أصلي
- The cherry tailpiece · Generated With Diffusion Models · أصلي
- الخطوط
- Averia Serif Libre (SIL OFL 1.1) · Fredericka the Great (SIL OFL 1.1) · Quicksand (SIL OFL 1.1)
- الشيفرة
- MIT، مثل Postext
حرّر هذا الشرح ↗ (يفتح في تبويب جديد)مجلد الوصفة على GitHub ↗ (يفتح في تبويب جديد)


