Μετάβαση στο κύριο περιεχόμενο
Συνταγή αριθμός 136

Συνταγολόγιο · Κεφάλαιο 10 · Έξοδος και ενσωμάτωση

Μια ζωντανή εφημερίδα με εικόνες που κινούνται

Έξι πόροι βίντεο ως φωτογραφίες ειδήσεων σε ταμπλόιντ τεσσάρων στηλών· τα autoplay, loop και exclusive: false κάνουν τα κλιπ να παίζουν μαζί στο Folio.

  • Δείγμα στα αγγλικά: δεν υπάρχει ακόμη ελληνική έκδοση
  • Διάσταση σελίδας 280 × 430 mm
  • 4 στήλες, Διάκενο 4,5 mm
  • Libre Caslon Text 8,8/11,6
  • Courier Prime
  • Oswald
  • 4 σελίδες
  • Επίπεδο
  • Postext 1.57.1
  • Σελιδοποίηση σε 202 ms
  • 250 γραμμές κώδικα

Με λίγα λόγια

Μια τοπική εφημερίδα σε ύφος της δεκαετίας του 1930, όπου κάθε φωτογραφία είναι μια σύντομη βουβή ταινία. Στο χαρτί είναι ακίνητες εικόνες· στην τρισδιάστατη προβολή κινούνται όλες μαζί, ξανά και ξανά, σαν εφημερίδα παραμυθιού.

Τι θα στοιχειοθετήσετε

Το The Wexcombe Lantern, μια επινοημένη εβδομαδιαία εφημερίδα παραθαλάσσιας πόλης του Ιουνίου 1933, σε σελίδα ταμπλόιντ 280 × 430 mm με τέσσερις στήλες και γραμμές ανάμεσά τους: μια στενή κεφαλίδα με το όνομα της εφημερίδας, ένα κύριο θέμα με την εικόνα του σε τρεις στήλες, ένα δεύτερο σε δύο, πίνακες παλιρροιών, μικρές αγγελίες και μια αθλητική σελίδα. Κάθε εικόνα είναι μια ασπρόμαυρη ταινία πέντε δευτερολέπτων. Στο τυπωμένο χαρτί, και στις επίπεδες σελίδες κάτω από την προβολή, η καθεμία είναι το πρώτο της καρέ. Όταν ανοίγει στο Folio ως διπλωμένη εφημερίδα σε ελαφρύ χαρτί εφημερίδας, οι εικόνες στις ανοιχτές σελίδες κινούνται όλες μαζί και δεν σταματούν: ο δήμαρχος μιλά, η αεροπόρος χαιρετά, ο ψαράς γελά, ο τερματοφύλακας βουτά και σηκώνεται ξανά. Η σελίδα δεν σχεδιάζει τίποτα· η σελιδοποίηση είναι μιας συνηθισμένης εφημερίδας, και τα κλιπ κάνουν τα υπόλοιπα.

Αυτή η συνταγή απαντά

  • Πώς κάνω πολλά βουβά βίντεο σε επανάληψη να παίζουν ταυτόχρονα σε μια σελίδα και να ξαναρχίζουν κάθε φορά που ανοίγει η σελίδα;
  • Πώς δείχνω μια εφημερίδα στο τρισδιάστατο πρόγραμμα προβολής ως διπλωμένα φύλλα, με τις οικονομικές σελίδες σε ροζ χαρτί;

Η σύντομη απάντηση

script.js · γραμμές 47–61στον πλήρη κώδικα
// A video resource prints its poster (the first frame) on the flat page. In Folio, and in the
// HTML viewer, the poster comes alive: autoplay starts it muted when its page is on show, loop
// keeps it going, and exclusive: false lets it run alongside the other clips instead of
// pausing them, as one exclusive player at a time would.
const videoStyle = {
  playMark: { enabled: false }, // a press photograph, not a play button
  qr: { enabled: false }, // the clips live on the page, not behind a link
  linkPoster: false,
  player: { autoplay: true, loop: true, muted: true, exclusive: false, controls: false },
};
const clip = (id, url, [w, h], placement, caption, altText) => ({ id, typeId: 'picture',
  kind: 'video', createdAt: 0, updatedAt: 0, caption, altText, placement,
  video: { source: 'file', fileId: `${id}-loop.mp4`, url, // url: where the clip plays from
    format: 'mp4', width: w, height: h, duration: 5,
    poster: { fileId: `${id}-poster.jpg`, format: 'jpeg', width: w, height: h } } });

Υλικά

Λειτουργίες
Βίντεο που παίζουν ταυτόχροναΤρεις ή περισσότερες στήλεςΒίντεο ως πόροιΕικόνες προεπισκόπησης βίντεο: σήμα αναπαραγωγής και κωδικός QRΚινητά στοιχεία σε πολλές στήλεςΔιαστάσεις σελίδας εφημερίδαςΔιπλωμένη εφημερίδα (Folio)Τρισδιάστατη προβολή βιβλίου (Folio)Χαρτί, βιβλιοδεσία, γραφείο και φως (Folio)Σχεδιασμένες εναρκτήριες σελίδεςΣτιλ επικεφαλίδωνΙδιότητες επικεφαλίδωνΚείμενο, γραμμές και πλαίσια στις σχεδιάσεις σελίδαςΤρέχουσες κεφαλίδες και αριθμοί σελίδαςΓραμμή στηλώνΠλαίσια σημειώσεωνΣτήλες σε πλαίσιο ή στο κείμενοΣτιλ παραγράφωνΓραμμές πηγής και πίστωσης
Γραμματοσειρές
Libre Caslon Text, Oswald, Courier Prime (SIL OFL 1.1)
Αρχεία
  • actress-loop.mp4
  • actress-poster.jpg
  • aviator-loop.mp4
  • aviator-poster.jpg
  • clock-loop.mp4
  • clock-poster.jpg
  • fisherman-loop.mp4
  • fisherman-poster.jpg
  • keeper-loop.mp4
  • keeper-poster.jpg
  • mayor-loop.mp4
  • mayor-poster.jpg
  • Mrs Edith Rowe speaks at the opening of the Harbour line: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the mayor loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • The Guildhall clock tower: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the clock loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Skipper Jacob Hosking with the cod: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the fisherman loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Miss Constance Lacey in the cockpit: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the aviator loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Miss Rosalind Avery on the stage: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the actress loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)
  • Tom Rundle in goal: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg (Generated With Diffusion Models, CC BY 4.0)
  • The first frame of the keeper loop, its printed picture (Generated With Diffusion Models, CC BY 4.0)

Προετοιμασία

#1 · Κάντε κάθε εικόνα κλιπ που επαναλαμβάνεται μαζί με τα άλλα

Ο κώδικας είναι η σύντομη απάντηση παραπάνω. Ένας πόρος βίντεο τυπώνει την αφίσα του ως εικόνα, έτσι τα κλιπ παίρνουν τη θέση των φωτογραφιών και έχουν λεζάντα όπως αυτές. Τρεις επιλογές του προγράμματος αναπαραγωγής ζωντανεύουν τη σελίδα: το autoplay ξεκινά ένα κλιπ όταν η σελίδα του είναι ορατή (πάντα σε σίγαση, όπως απαιτούν τα προγράμματα περιήγησης), το loop το παίζει ξανά από την αρχή, και το exclusive: false το αφήνει να παίζει μαζί με τα άλλα κλιπ. Εξ ορισμού ένα βίντεο είναι αποκλειστικό: όταν ξεκινά, σταματά ό,τι άλλο παίζει, κάτι που ταιριάζει σε μια διάλεξη αλλά όχι σε μια σελίδα με κινούμενες φωτογραφίες. Το σήμα αναπαραγωγής και ο κωδικός QR είναι απενεργοποιημένα, έτσι στο χαρτί τα κλιπ διαβάζονται ως φωτογραφίες ειδήσεων.

#2 · Δώστε σε κάθε κλιπ τη θέση του στο πλέγμα

script.js · γραμμές 65–91στον πλήρη κώδικα
const resources = [
  clip('mayor', asset('mayor-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 3 },
    '**Mrs Edith Rowe** speaks from the platform at the foot of Quay Hill before cutting '
      + 'the ribbon.',
    'A woman in a dark coat and small hat speaks at a draped podium, one hand raised.'),
  clip('clock', asset('clock-loop.mp4'), [480, 640],
    { position: 'top', span: 'column', columns: 2 },
    '**Twelve o’clock** on the Guildhall tower, for the first time since 1924.',
    'A stone clock tower against clouds, pigeons on its ledge.'),
  clip('fisherman', asset('fisherman-loop.mp4'), [640, 480],
    { position: 'auto', span: 'column', columns: 2 },
    '**Skipper Jacob Hosking** and the 82-pound cod on the quay.',
    'An old fisherman in an oilskin laughs, holding up a huge cod.'),
  clip('aviator', asset('aviator-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 2 },
    '**Miss Constance Lacey** waves from the cockpit on Wexcombe Common.',
    'A young woman in a flying helmet waves from the open cockpit of a biplane.'),
  clip('actress', asset('actress-loop.mp4'), [480, 640],
    { position: 'top', span: 'column', columns: 2 },
    '**Miss Rosalind Avery** as Hester Lane, on the garden steps in Act III.',
    'An actress in a long gown on a garden stage set, one arm outstretched.'),
  clip('keeper', asset('keeper-loop.mp4'), [640, 480],
    { position: 'top', span: 'column', columns: 3 },
    '**Tom Rundle** at Gannet Park, before the penalty he saved.',
    'A goalkeeper in a flat cap crouches on his line in front of a packed terrace.'),
];

Η σελιδοποίηση είναι layoutType: 'multiple' με columnCount: 4. Το columns ενός κινητού στοιχείου ορίζει πόσες από αυτές παίρνει: ο δήμαρχος και ο τερματοφύλακας τρεις, η αεροπόρος, ο πύργος του ρολογιού, ο ψαράς και η ηθοποιός δύο. Ένα κινητό στοιχείο σε πολλές στήλες παίρνει την κορυφή μιας σειράς κενών στηλών που αρχίζουν στο ίδιο ύψος, ή το κάτω μέρος της στήλης όπου παραπέμπεται και των κενών στηλών μετά από αυτήν, άρα η θέση της γραμμής ::resource καθορίζει τη θέση. Ο δήμαρχος παραπέμπεται μετά την πρώτη παράγραφο, κάτι που αφήνει τη στήλη 1 στο κείμενο και βάζει την εικόνα πάνω από τις στήλες 2 έως 4.

#3 · Στήστε την κεφαλίδα και τις σελίδες των ενοτήτων

script.js · γραμμές 131–147στον πλήρη κώδικα
const nameplate = { enabled: true, slot: { elements: [
  depth(10), // the masthead is ten grid lines deep; the rules and the dateline hang from it
  { kind: 'rule', id: 'foot', thickness: pt(2.5), color: col('ink'),
    placement: { ...at('#depth', 'align-bottom', 0, -1.5), size: { width: 'fill' } } },
  ...[['left', '{attr.issue}'], ['center', '{publishDate}'], ['right', '{attr.price}']].map(
    ([align, content]) => text(`date-${align}`, content, { ...typed(9, { fontWeight: 700 }),
      align }, { ...at('#foot', 'above', 0, -1.6), size: { width: 'fill' } })),
  rule('thin', '#date-left', 0.6, 1.8),
  text('name', '{titleText}', { ...oswald(66, 700, { textTransform: 'uppercase',
    letterSpacing: pt(1.5) }), lineHeight: 1, align: 'center' },
  { ...at('#thin', 'above', 0, -2), size: { width: 'fill' } }),
  // Two ears over the name: the paper's age on the left, the weather on the right.
  text('since', '{attr.since}', { ...caps(8, 600, 'flag'), align: 'left' },
    { ...at('container', 'top-left', 0, 1), size: { width: mm(90) } }),
  text('weather', 'Weather: {attr.weather}', { ...typed(8.5, { italic: true }), align: 'right' },
    { ...at('container', 'top-right', 0, 1), size: { width: mm(110) } }),
] } };

Η επικεφαλίδα επιπέδου 1 του πρωτοσέλιδου είναι το όνομα της εφημερίδας, σχεδιασμένο από μια θέση σχεδίασης: δύο «αυτιά» από πάνω, το όνομα σε κεφαλαία Oswald, και μια γραμμή ημερομηνίας ανάμεσα σε μια λεπτή και μια χοντρή γραμμή. Οι εσωτερικές σελίδες ανοίγουν με μια κόκκινη σημαία ενότητας πάνω σε μπάρα 3 pt (η περιοχή pages), και μια γραμμή με τον αριθμό σελίδας στην κορυφή κάθε σελίδας εκτός από την πρώτη.

#4 · Ανοίξτε την εφημερίδα στο Folio

script.js · γραμμές 572–581στον πλήρη κώδικα
const stage = Object.assign(document.createElement('section'),
  { id: 'folio', ariaLabel: 'The newspaper in 3D' });
stage.style.cssText = 'height: min(82vh, 820px); margin: 0 auto; max-width: 1280px';
document.getElementById('pages').before(stage);
createFolioFromDocument(stage, doc, {
  // Folio plays each clip from its video.url, muted, while its page is on show.
  appearance: { textureBaseUrl: 'https://postext.dev/folio/textures' },
  onChange: ({ pages }) => kitStatus(`${doc.pages.length} pages · open at `
    + pages.map((i) => doc.pages[i].pageLabel || i + 1).join('–')),
});

Το config.folio απλώνει την εφημερίδα πάνω σε δρυ στο φως της ημέρας: χαρτί εφημερίδας 45 g/m², μέσα από το οποίο φαίνεται η επόμενη σελίδα, και binding.type: 'folded', φύλλα διπλωμένα μία φορά και τοποθετημένα το ένα μέσα στο άλλο χωρίς συρραφή και χωρίς ράχη, όπως συναρμολογείται μια εφημερίδα. Το Folio σχεδιάζει κάθε κλιπ του ανοιχτού δισέλιδου σε μία υφή, έως οκτώ τη φορά, ξεκινά τα κλιπ αυτόματης αναπαραγωγής κάθε φορά που ένα γύρισμα σελίδας σταθεροποιείται στη σελίδα τους και τα σταματά όταν η σελίδα γυρίσει. Ένα κλικ σε αποκλειστικό βίντεο εξακολουθεί να το παίζει μόνο του, με τον ήχο του, και τα κλιπ σε επανάληψη περιμένουν να σταματήσει.

Η πλήρης συνταγή

Sandbox
// ═══ Postext Cookbook · Nº 136 · A living newspaper of video loops ══════════════
// https://postext.dev/en/cookbook/living-newspaper-video-loops
// Code: MIT · Text: original (CC BY 4.0) · Clips: generated with diffusion models (CC BY 4.0)
// Fonts: Oswald, Libre Caslon Text, Courier Prime (SIL OFL 1.1) · Needs postext ≥ 1.28.0
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';
import { createFolioFromDocument } from 'https://esm.sh/postext-folio';

const LANG = 'en'; // @lang: the language of the sample document ('en')
const RECIPE = 'living-newspaper-video-loops';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: newsprint, a warm black and a dark red for the flags
const palette = {
  ink: '#16130f', // text, rules and the nameplate
  paper: '#f3efe4', // newsprint, and type reversed out of ink or red
  flag: '#8e1b14', // the one accent: section flags, kickers, the jump lines
  tint: '#e6dfcf', // the In brief strip
  rule: '#8f897c', // hairlines: the column rules
  muted: '#5b554b', // bylines, captions' credits, the imprint
};
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = [ // defaults link to 'main-color': point it at the ink, never blue
  ...Object.entries(palette).map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } })),
  { id: 'main-color', name: 'ink (defaults)', value: { hex: palette.ink, model: 'hex' } },
];
// #endregion
const MARGIN = { top: 12, bottom: 12, side: 12 }; // mm: a tabloid's narrow margins
const GUTTER = 4.5; // mm between the four columns
const LEAD = 11.6; // body leading in pt: the baseline grid
const oswald = (size, weight, look = {}) => ({ fontFamily: 'Oswald', fontSize: pt(size),
  fontWeight: weight, color: col('ink'), ...look });
const caps = (size, weight, colour = 'ink') => oswald(size, weight, { color: col(colour),
  textTransform: 'uppercase', letterSpacing: pt(size * 0.12) });
const typed = (size, look = {}) => ({ fontFamily: 'Courier Prime', fontSize: pt(size),
  color: col('ink'), ...look }); // the dateline and the captions: a typewriter
const at = (to, edge, x = 0, y = 0) => ({ anchor: { to, edge }, offset: { x: mm(x), y: mm(y) } });
const text = (id, content, look, placement) => ({ kind: 'text', id, content, align: 'left',
  overflow: 'wrap', color: col('ink'), ...look, placement }); // wraps, in a running head too
const rule = (id, under, weight, gap = 0) => ({ kind: 'rule', id, thickness: pt(weight),
  color: col('ink'), placement: { ...at(under, 'above', 0, -gap), size: { width: 'fill' } } });
const depth = (lines) => ({ kind: 'box', id: 'depth', style: {}, placement: {
  ...at('container', 'top-left'), size: { width: 'fill', height: pt(lines * LEAD) } } });

// #region answer: every picture is a clip that loops, autoplays and plays with the others
// A video resource prints its poster (the first frame) on the flat page. In Folio, and in the
// HTML viewer, the poster comes alive: autoplay starts it muted when its page is on show, loop

Το συντεθειμένο script.js εκτελείται ως έχει: επικολλήστε το στο module script οποιασδήποτε σελίδας ή ανοίξτε τη συνταγή στο CodePen. Φάκελος της συνταγής στο GitHub ↗ (ανοίγει σε νέα καρτέλα)

Παραλλαγές

#Αφήστε τον αναγνώστη να ξεκινά κάθε κλιπ

Χωρίς autoplay οι εικόνες μένουν ακίνητες ώσπου ο αναγνώστης να κάνει κλικ σε μία· τα κλιπ εξακολουθούν να παίζουν μαζί μόλις ξεκινήσουν.

-  player: { autoplay: true, loop: true, muted: true, exclusive: false, controls: false },
+  player: { loop: true, muted: true, exclusive: false, controls: false },

#Ένα αποκλειστικό κλιπ με τον ήχο του

Ένα μεμονωμένο βίντεο μπορεί να κρατήσει την προεπιλογή και να παίζει με τους δικούς του όρους: ορίστε player: { exclusive: true, muted: false } στο video αυτού του πόρου, και όταν ξεκινά κρατά τα κλιπ σε επανάληψη σε αναμονή ώσπου να τελειώσει.

#Μεγάλη εφημερίδα σε έξι στήλες

Το Πρωτοσέλιδο εφημερίδας στοιχειοθετεί μια μικρότερη εφημερίδα με ακίνητες φωτογραφίες· το ίδιο πλέγμα παίρνει έξι στήλες σε διάσταση σελίδας broadsheet με sizePreset: 'broadsheet'.

Συνήθη λάθη

Μια ενότητα εφημερίδας είναι επικεφαλίδα επιπέδου 1 που ανοίγει σελίδα, και ένα κινητό στοιχείο δεν την περνά ποτέ. Μια εικόνα που δεν βρίσκει θέση στην τελευταία σελίδα της ενότητάς της στοιχειοθετείται σε δική της σελίδα πριν από την επόμενη ενότητα, γι’ αυτό προσαρμόστε το κείμενο στη σελίδα: εδώ η ιστορία για τα τραμ συνεχίζει στη σελίδα 2 αντί να σπρώξει την αεροπόρο έξω από το πρωτοσέλιδο.

Ευχαριστίες

Συνταγή
Ignacio Ferro
Κείμενο
Πρωτότυπο κείμενο, CC BY 4.0
Εικόνες
  • Mrs Edith Rowe speaks at the opening of the Harbour line: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the mayor loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • The Guildhall clock tower: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the clock loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Skipper Jacob Hosking with the cod: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the fisherman loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Miss Constance Lacey in the cockpit: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the aviator loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Miss Rosalind Avery on the stage: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the actress loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
  • Tom Rundle in goal: a black-and-white loop of 5 s, a still generated from a text prompt and animated with the same first and last frame, encoded with ffmpeg · Generated With Diffusion Models · CC BY 4.0
  • The first frame of the keeper loop, its printed picture · Generated With Diffusion Models · CC BY 4.0
Γραμματοσειρές
Libre Caslon Text (SIL OFL 1.1) · Oswald (SIL OFL 1.1) · Courier Prime (SIL OFL 1.1)
Sandbox