Em poucas palavras
Um boletim de duas páginas de um clube de jardinagem. A matéria principal ocupa uma coluna larga e continua na página 2, e as notícias curtas ficam numa coluna estreita ao lado.
O que você vai compor
A edição de primavera de The Allotment Gazette, boletim de uma associação de horta comunitária inventada, impresso nos dois lados de uma folha A4. Uma faixa cor de palha leva o nome em Titan One, em duas linhas, uma fileira de mudas na borda inferior e uma aba cor de tomate com o número e a estação. Abaixo dela a página se divide numa coluna de 113 mm e noutra de 57 mm. A matéria principal, sobre três novas baias de compostagem, enche a coluna larga sob uma planta da horta desenhada em código e para numa etiqueta “Continued on page 2”. A coluna estreita reúne cinco notas, cada uma aberta por etiquetas em forma de pílula. A página 2 retoma a matéria sob um título de continuação e centraliza um gráfico de temperatura na coluna. Mais abaixo, o parágrafo sobre um canteiro é composto ao lado do desenho dele, posto à direita da coluna. Oito avisos enchem a coluna estreita.
Esta receita responde a
- Como monto uma diagramação em coluna e meia, com uma coluna de texto larga e uma coluna lateral estreita?
- O Postext consegue compor três ou mais colunas de texto, ou fazer o texto contornar uma imagem?
- Como coloco duas colunas dentro de um boxe (uma coluna de texto ao lado de uma coluna com figura)?
- Como faço chips em linha: teclas, etiquetas, bancos de palavras para exercícios?
A resposta curta
const layout = {
layoutType: 'oneAndHalf', // the narrow column sits on the right and takes text (the
// defaults of sideColumnSide and sideColumnRole; 'floats' would keep text out of it)
sideColumnPercent: 32, // 57 mm of the 178 mm measure
gutterWidth: mm(8), // the wide column keeps the other 113 mm
columnRule: { enabled: true, color: col('rule') }, // a 0.5 pt hairline in the gutter
};
// The text runs down the wide column, then the narrow one, then the next page's wide
// column. A :::columnbreak sends the next block on to the following column, so the
// Markdown decides what each column holds:
// ## Shared compost bays open by the top gate ← the lead, in the wide column
// … :chip[Continued on page 2]{style="jump"}
// :::columnbreak ← the briefs open the narrow column
// ## In brief {style="rail"}
// …
// :::columnbreak ← from the last column: next page
// :chip[Continued from page 1]{style="jump"} ← the lead goes on in the wide column
Ingredientes
- Funcionalidades
- Coluna e meiaQuebras de página e de colunaChips no textoTexto contornando imagens e caixasEstilos de títuloPosicionamento de figurasBoxesFiguras exatamente aquiFio entre colunasMetadados do documentoAberturas desenhadasAtributos de títuloCabeços e fóliosCabeços por tipo de páginaEstilos de parágrafoTipos de recurso personalizadosLinhas de fonte e créditoPaleta de cores semânticaPáginas em um canvasFiguras e tabelas como recursos
- Tipografia
- Work Sans, Titan One, Courier Prime (SIL OFL 1.1)
- Materiais
- The site plan, the temperature chart, the square-metre bed and the row of seedlings under the nameplate, drawn in code in the page's palette (Ignacio Ferro, CC BY 4.0)
Preparo
#1 · Deixe o Markdown encher cada coluna
As configurações de layout estão na resposta curta, lá em cima. Num layout oneAndHalf a coluna estreita recebe texto por padrão, e o texto desce pela coluna larga, depois pela estreita, depois pela coluna larga da página seguinte (tipos de layout). Um :::columnbreak encerra a coluna onde está (diretivas): depois da etiqueta “Continued on page 2” da matéria, ele abre a coluna estreita para as notas, e depois da última nota, na última coluna da página, abre a página 2. Nesta edição as duas colunas da página 1 foram ajustadas para terminar na mesma linha da grade, a 275 mm da borda superior, por isso apagar qualquer uma das duas quebras deixa as páginas como estão. As quebras fazem diferença quando o texto muda. Corte o segundo parágrafo da matéria e, sem a primeira quebra, “In brief” começa a 247 mm, na coluna larga, embaixo da etiqueta, e a primeira nota transborda para a coluna estreita, onde a segunda metade é quebrada de novo para a medida de 57 mm dessa coluna.
#2 · Monte o cabeçalho a partir do frontmatter
const BEARING = 0.6; // mm: Titan One's left side bearing at 60 pt (T 0.42, G 0.63, L/H 0.85)
const DRILL = { id: 'drill', typeId: 'drawing', kind: 'svg', createdAt: 0, updatedAt: 0,
svg: { fileId: 'drill.svg', width: 2100, height: 80 } }; // drawn by the design, not the text
const masthead = { enabled: true,
minHeight: pt(10 * LEAD), // ten grid lines: the text starts one line clear of the band
slot: { elements: [
// The band is 62 mm deep. The column rule starts under the masthead, where the text does.
{ kind: 'box', id: 'band', style: { backgroundColor: col('straw') },
placement: { ...at('page', 'top-left'), size: { width: mm(210), height: mm(62) } } },
{ kind: 'image', id: 'drill', resourceId: 'drill', // seedlings along the band's foot
placement: { ...at('page', 'top-left', 0, 54), size: { width: mm(210), height: mm(8) } } },
{ kind: 'text', id: 'society', content: '{subtitle}', ...caps(8, 'leaf'), align: 'left',
placement: { ...at('page', 'top-left', SIDE, 12), size: { width: mm(150) } } },
{ kind: 'text', id: 'title', content: '{titleText}', fontFamily: DISPLAY, fontSize: pt(60),
lineHeight: 0.9, // 54 pt from line to line
color: col('leaf'), align: 'left', overflow: 'wrap', // two lines in 178 mm
placement: { ...at('page', 'top-left', SIDE - BEARING, 17), size: { width: mm(178) } } },
// {attr.issue} comes from the H1 line, {publishDate} from the frontmatter.
{ kind: 'text', id: 'tab', content: '{attr.issue} · {publishDate}', ...caps(9, 'paper'),
align: 'right', box: { backgroundColor: col('tomato'),
padding: { top: mm(1.8), right: mm(3.2), bottom: mm(1.6), left: mm(3.2) } },
placement: at('page', 'top-right', -SIDE, 44) },
] } };
O H1 recebe um estilo de título cujo design desenha o cabeçalho do boletim, e span: 'page' põe esse design por cima das duas colunas. {titleText} em 60 pt quebra em duas linhas na caixa de 178 mm. A aba junta {attr.issue}, escrito na linha do H1, e {publishDate}, do front matter (elementos de texto). Sem minHeight, o cabeçalho reservaria espaço até a borda inferior da faixa, a 62 mm da borda superior, e o texto começaria na linha seguinte da grade, a 62,5 mm, encostado na faixa. Um minHeight de dez linhas da grade faz o texto começar a 67 mm.
#3 · Marque as notas com chips
const chip = (id, look) => ({ id, fontFamily: LABEL, bold: true,
fontSize: pt(7.7), // in points: em(0.82) is 7.7 pt in the text, 6.6 pt on the 8 pt jump lines
borderWidth: pt(0), borderRadius: em(1), // a radius past half the height draws a pill
paddingX: em(0.5), paddingY: em(0.14), ...look }); // em: of the chip's own size
const chipStyles = [
chip('tag', { background: col('tomato'), color: col('paper') }), // the first is the default
chip('free', { background: col('marigold'), color: col('ink') }),
chip('when', { backgroundEnabled: false, borderWidth: pt(0.8), borderColor: col('leaf'),
color: col('leaf') }),
chip('jump', { background: col('straw'), color: col('ink') }),
];
Declarar chipStyles substitui o chip azul-claro padrão, e um chip sem style usa o primeiro (estilos de chip). Um raio maior que metade da altura da caixa desenha uma pílula. Um chip nunca quebra por dentro, por isso a linha só quebra no espaço antes ou depois de um chip, e uma data como “Sat 11 April” fica numa linha só. As etiquetas são digitadas em maiúsculas no Markdown porque os estilos de chip não têm opção de caixa. O preenchimento vertical é pintado fora da linha, por isso a grade de 13,4 pt se mantém.
#4 · Componha o texto ao lado do desenho
// wrap sets the drawing at that side of its column, width of it, and the text after the
// ::resource line runs beside it at the measure left over, then under it at full width:
// #### Sixteen squares by the gate {style="kicker"}
// ::resource{id="bed"} ← 51 mm at the right of the 113 mm column
// The demonstration bed by the gate is 1.2 metres square … ← beside it, then under it
const WRAP = { wrap: 'right', width: 0.45 }; // a body line of white between it and the text
wrap: 'right' põe o desenho do canteiro na borda direita da coluna de 113 mm, com 45 % da largura dela (51 mm), e o parágrafo depois da linha ::resource é composto ao lado dele nos 57 mm que sobram, a uma linha do corpo de distância do desenho e da legenda (contorno de texto). O topo do desenho fica na altura da primeira linha do parágrafo, e todas as linhas ficam na grade de 13,4 pt. Um parágrafo mais longo continuaria embaixo do desenho nos 113 mm inteiros, como um parágrafo só; um título ou outra figura que viesse com o desenho ainda ao lado do texto iria para baixo dele. O título de nível 4 em cima dele usa um estilo de título que só muda a cor para o verde-folha.
#5 · Centralize um gráfico estreito na sua faixa
const drawing = (id, w, h, placement = {}) => ({ id, typeId: 'drawing', kind: 'svg',
svg: { fileId: `${id}.svg`, width: w * 10, height: h * 10 }, // mm × 10: fitted to the column
placement: { position: 'here', ...placement }, // drawn where ::resource{id} stands
caption: CAPTIONS[id][0], note: CAPTIONS[id][1], altText: CAPTIONS[id][2],
createdAt: 0, updatedAt: 0 });
// width is a fraction of the column and align where the figure sits in it: the text above
// and below never moves into the white either side.
const HEAT = { width: 0.62, align: 'center' };
const resources = () => [drawing('plan', 114, 56.5), drawing('heat', 68, 40, HEAT),
drawing('bed', 50, 50, WRAP), DRILL];
// Newsletter drawings carry no "Figure 1": an empty prefix prints no label.
const resourceTypes = [{ id: 'drawing', name: 'Drawing', shortLabel: 'Drawing',
captionPrefix: '', numberingTemplate: '', resetOn: 'never', counterFormat: 'decimal' }];
width: 0.62 dá ao gráfico 70,1 mm de largura na coluna de 113 mm, e align: 'center' deixa 21,5 mm de papel de cada lado (posicionamento). O texto acima e abaixo mantém a medida inteira e nunca entra nesse branco. Os desenhos pertencem a um tipo de recurso com captionPrefix vazio, de modo que cada legenda começa com as próprias palavras em negrito, sem “Figura 1” na frente.
A receita completa
// ═══ Postext Cookbook · Nº 042 · Community newsletter: lead story and briefs ═════
// https://postext.dev/en/cookbook/community-newsletter
// Code: MIT · Text: original (CC BY 4.0) · Drawings: generated in code (CC BY 4.0)
// Fonts: Work Sans, Titan One, Courier Prime (SIL OFL 1.1) · Needs postext ≥ 1.25.0
import {
buildDocumentWithFonts, renderPageToCanvas, registerResourceImage, inlineSvgFonts,
} from 'https://esm.sh/postext';
const LANG = 'en'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'community-newsletter';
// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: garden colours, every one linked by id
// ink: text · leaf: nameplate and headlines · tomato, the accent: tags, tab, column heads ·
// straw: the band · marigold: second tag · tint: pale greens · rule: hairlines · muted: notes
const palette = { ink: '#1d211c', leaf: '#2f6b3a', tomato: '#c43f2a', straw: '#f2d492',
marigold: '#e2b33c', tint: '#eef4e8', rule: '#cfd3c6', muted: '#5f6659', paper: '#fbfaf5' };
// Each colour carries its hex and the palette entry it follows.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the leaf, never blue
...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
{ id: 'main-color', name: 'leaf (defaults)', value: { hex: palette.leaf, model: 'hex' } },
];
// #endregion
const [TEXT, DISPLAY, LABEL] = ['Work Sans', 'Titan One', 'Courier Prime'];
const SIDE = 16; // mm: the side margins of one A4 sheet, printed on both sides
const LEAD = 13.4; // body leading in pt: the baseline grid
const caps = (size, colour) => ({ fontFamily: LABEL, fontSize: pt(size), fontWeight: 700,
textTransform: 'uppercase', letterSpacing: pt(size * 0.12), color: col(colour) });
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
// #region answer: a wide column for the lead, a narrow one for the briefs, one flow
const layout = {
layoutType: 'oneAndHalf', // the narrow column sits on the right and takes text (the
// defaults of sideColumnSide and sideColumnRole; 'floats' would keep text out of it)
sideColumnPercent: 32, // 57 mm of the 178 mm measure
gutterWidth: mm(8), // the wide column keeps the other 113 mm
columnRule: { enabled: true, color: col('rule') }, // a 0.5 pt hairline in the gutter
};
// The text runs down the wide column, then the narrow one, then the next page's wide
// column. A :::columnbreak sends the next block on to the following column, so the
// Markdown decides what each column holds:
// ## Shared compost bays open by the top gate ← the lead, in the wide column
// … :chip[Continued on page 2]{style="jump"}
// :::columnbreak ← the briefs open the narrow column
// ## In brief {style="rail"}
// …
// :::columnbreak ← from the last column: next page
O script.js montado funciona como está: cole-o como script de módulo em qualquer página ou abra a receita no CodePen. Pasta da receita no GitHub ↗ (abre em uma nova aba)
Variações
#Ponha as notas à esquerda
A coluna larga continua sendo lida primeiro, por isso o mesmo Markdown põe a matéria à direita e as notas à esquerda.
layoutType: 'oneAndHalf',
+ sideColumnSide: 'left',#Distribua as notas na largura da página
O texto corrido tem no máximo duas colunas. A primeira página de jornal espalha quatro notas na largura do pé da página num boxe com :::columns{count=4}.
Créditos
- Receita
- Ignacio Ferro
- Texto
- Texto original, CC BY 4.0
- Imagens
- The site plan, the temperature chart, the square-metre bed and the row of seedlings under the nameplate, drawn in code in the page's palette · Ignacio Ferro · CC BY 4.0
- Fontes
- Work Sans (SIL OFL 1.1) · Titan One (SIL OFL 1.1) · Courier Prime (SIL OFL 1.1)
- Código
- MIT, como o Postext
Editar este texto ↗ (abre em uma nova aba)Pasta da receita no GitHub ↗ (abre em uma nova aba)


