Commit 04f0b598 by PLN (Algolia)

les-femmes: expérience OG — cards 1200x630 par le pipeline og (landing quote…

les-femmes: expérience OG — cards 1200x630 par le pipeline og (landing quote Marie Curie, état femmes 27/34, celebres, une par fiche avec portrait à droite et la punchline du personnage), metadata openGraph/twitter/canonical disk-checked ; les cards vivent dans public/images/og/les-femmes/ après avoir appris à ne jamais écraser les portraits
parent 759039ba
import Link from "next/link"; import Link from "next/link";
import { Header, Footer } from "../Chrome"; import { Header, Footer } from "../Chrome";
import FemmeKeys from "../FemmeKeys";
import { femmeOg, socialMeta } from "../og";
import { FEMMES, VERDICT_META, getImage, getFemme, getPersonnage } from "../data"; import { FEMMES, VERDICT_META, getImage, getFemme, getPersonnage } from "../data";
import style from "../style.module.css"; import style from "../style.module.css";
...@@ -11,10 +13,12 @@ export async function generateMetadata({ params }) { ...@@ -11,10 +13,12 @@ export async function generateMetadata({ params }) {
const { femme: slug } = await params; const { femme: slug } = await params;
const femme = getFemme(slug); const femme = getFemme(slug);
if (!femme) return {}; if (!femme) return {};
return { return socialMeta({
title: `${femme.name} — Les femmes derrière « Comment ça va ce matin ? »`, title: `${femme.name} — Comment ça va, les femmes ?`,
description: femme.entries.map((e) => e.text).join(" ").slice(0, 160), description: femme.entries.map((e) => e.text).join(" ").slice(0, 160),
}; canonicalPath: `/les-femmes/${femme.slug}`,
image: femmeOg(femme.slug),
});
} }
export default async function FemmePage({ params }) { export default async function FemmePage({ params }) {
...@@ -30,6 +34,9 @@ export default async function FemmePage({ params }) { ...@@ -30,6 +34,9 @@ export default async function FemmePage({ params }) {
const commonsUrl = img const commonsUrl = img
? `https://commons.wikimedia.org/wiki/File:${encodeURIComponent(img.commons)}` ? `https://commons.wikimedia.org/wiki/File:${encodeURIComponent(img.commons)}`
: null; : null;
// Crédit lisible : les underscores des fichiers Commons ne sont pas un
// contenu, juste un encodage.
const commonsLabel = img?.commons.replace(/\.[a-z0-9]+$/i, "").replace(/_/g, " ");
const wikiHref = femme.wikipedia?.fr const wikiHref = femme.wikipedia?.fr
? `https://fr.wikipedia.org/wiki/${encodeURIComponent(femme.wikipedia.fr)}` ? `https://fr.wikipedia.org/wiki/${encodeURIComponent(femme.wikipedia.fr)}`
: femme.wikipedia?.en : femme.wikipedia?.en
...@@ -111,7 +118,7 @@ export default async function FemmePage({ params }) { ...@@ -111,7 +118,7 @@ export default async function FemmePage({ params }) {
<p className={style.credit}> <p className={style.credit}>
Image :{" "} Image :{" "}
<a href={commonsUrl} target="_blank" rel="noopener noreferrer"> <a href={commonsUrl} target="_blank" rel="noopener noreferrer">
{img.commons} {commonsLabel}
</a>{" "} </a>{" "}
— Wikimedia Commons — Wikimedia Commons
</p> </p>
...@@ -156,10 +163,21 @@ export default async function FemmePage({ params }) { ...@@ -156,10 +163,21 @@ export default async function FemmePage({ params }) {
</ul> </ul>
</> </>
)} )}
<p className={style.kbdHint}>
clavier : ← → femme précédente/suivante · Échap accueil
{img ? " · Entrée : zoom portrait" : ""}
</p>
</div> </div>
</aside> </aside>
</div> </div>
<FemmeKeys
prev={prev?.slug}
next={next?.slug}
imgSrc={img ? `/images/les-femmes/${img.file}` : null}
imgAlt={femme.name}
/>
<Footer /> <Footer />
</main> </main>
); );
......
[
{"slug":"jocaste-et-antigone","name":"Jocaste et Antigone","verdictLabel":"Fiction","color":"#553c9a","personnage":"Œdipe","punchline":"La question est complexe.","file":"jocaste-et-antigone.jpg"},
{"slug":"themistoclea-theano","name":"Thémistocléa, Théano et les pythagoriciennes","verdictLabel":"Éclipse (sources fragiles)","color":"#7b3f8c","personnage":"Pythagore","punchline":"Tout est d'équerre.","file":null},
{"slug":"diotime-aspasie","name":"Diotime de Mantinée et Aspasie","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Socrate","punchline":"Je ne sais pas.","file":"diotime-aspasie.jpg"},
{"slug":"sages-femmes","name":"Les sages-femmes","verdictLabel":"Effacement collectif","color":"#a83a52","personnage":"Hippocrate","punchline":"Tant qu'on a la santé.","file":"sages-femmes.jpg"},
{"slug":"caterina-mere-de-leonard","name":"Caterina, mère de Léonard","verdictLabel":"Effacement (hypothèse récente)","color":"#a83a52","personnage":"Léonard de Vinci","punchline":"(se contente de sourire)...","file":null},
{"slug":"maria-celeste","name":"Maria Celeste","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Galilée","punchline":"Ça tourne rond !","file":"maria-celeste.jpg"},
{"slug":"elisabeth-de-boheme","name":"Élisabeth de Bohême","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Descartes","punchline":"Bien, je pense.","file":"elisabeth-de-boheme.jpg"},
{"slug":"soeurs-pascal","name":"Gilberte et Jacqueline, les sœurs Pascal","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Pascal","punchline":"Bien, je parie.","file":"soeurs-pascal.jpg"},
{"slug":"emilie-du-chatelet","name":"Émilie du Châtelet","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Newton","punchline":"La question tombe à pic.","file":"emilie-du-chatelet.jpg"},
{"slug":"anna-maria-della-pieta","name":"Anna Maria della Pietà et les figlie di coro","verdictLabel":"Éclipse collective","color":"#7b3f8c","personnage":"Vivaldi","punchline":"Ça dépend des saisons...","file":null},
{"slug":"jane-mecom","name":"Jane Mecom","verdictLabel":"Effacement","color":"#a83a52","personnage":"Franklin","punchline":"Du tonnerre !","file":null},
{"slug":"geoffrin-lespinasse","name":"Mme Geoffrin et Julie de Lespinasse","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"D'Alembert et Diderot","punchline":"Impossible de répondre en deux mots.","file":"geoffrin-lespinasse.jpg"},
{"slug":"rose-keller","name":"Rose Keller et les victimes","verdictLabel":"Effacement des victimes","color":"#a83a52","personnage":"Sade","punchline":"Foutrement bien.","file":null},
{"slug":"simonne-evrard","name":"Simonne Évrard","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Marat","punchline":"Ça baigne !","file":null},
{"slug":"olympe-de-gouges","name":"Olympe de Gouges","verdictLabel":"Exclusion","color":"#c05621","personnage":"Robespierre","punchline":"Vous perdez la tête ?","file":"olympe-de-gouges.png"},
{"slug":"nannette-streicher","name":"Nannette Streicher","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Beethoven","punchline":"En sourdine.","file":"nannette-streicher.jpg"},
{"slug":"johanna-et-adele-schopenhauer","name":"Johanna et Adele Schopenhauer","verdictLabel":"Éclipse (histoire inversée)","color":"#7b3f8c","personnage":"Schopenhauer","punchline":"Ce n'est pas la volonté qui me manque.","file":"johanna-et-adele-schopenhauer.jpg"},
{"slug":"clemence-royer","name":"Clémence Royer","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Darwin","punchline":"On s'adapte.","file":"clemence-royer.jpg"},
{"slug":"flora-tristan-helene-demuth","name":"Flora Tristan et Helene Demuth","verdictLabel":"Éclipse et effacement","color":"#7b3f8c","personnage":"Marx","punchline":"Ça ira mieux demain.","file":"flora-tristan-helene-demuth.jpg"},
{"slug":"elisabeth-forster-nietzsche","name":"Elisabeth Förster-Nietzsche et Lou Andreas-Salomé","verdictLabel":"Cas inverse","color":"#2b6cb0","personnage":"Nietzsche","punchline":"Par-delà le bien, merci.","file":"elisabeth-forster-nietzsche.jpg"},
{"slug":"spielrein-pappenheim","name":"Sabina Spielrein et Bertha Pappenheim","verdictLabel":"Appropriation partielle","color":"#8c1d3f","personnage":"Freud","punchline":"Et vous ?","file":"spielrein-pappenheim.jpg"},
{"slug":"marie-curie","name":"Marie Curie","verdictLabel":"Presque effacée de son Nobel","color":"#a83a52","personnage":"Marie Curie","punchline":"Je suis radieuse !","file":"marie-curie.jpg"},
{"slug":"nordlinger-weil","name":"Marie Nordlinger et Jeanne Weil","verdictLabel":"Éclipse","color":"#7b3f8c","personnage":"Proust","punchline":"Donnons du temps au temps...","file":null},
{"slug":"mileva-maric","name":"Mileva Marić","verdictLabel":"Soupçon non prouvé","color":"#6b7280","personnage":"Einstein","punchline":"Relativement bien.","file":"mileva-maric.jpg"},
{"slug":"dora-maar-francoise-gilot","name":"Dora Maar et Françoise Gilot","verdictLabel":"Éclipse et sabotage","color":"#7b3f8c","personnage":"Picasso","punchline":"Ça dépend des périodes.","file":"dora-maar-francoise-gilot.jpg"},
{"slug":"emily-gerard","name":"Emily Gerard","verdictLabel":"Éclipse d'une source","color":"#7b3f8c","personnage":"Dracula","punchline":"J'ai de la veine !","file":"emily-gerard.webp"},
{"slug":"rosemonde-gerard","name":"Rosemonde Gérard","verdictLabel":"Carrière sacrifiée","color":"#a83a52","personnage":"Cyrano de Bergerac","punchline":"À vue de nez, bien !","file":"rosemonde-gerard.jpg"}
]
import fs from "fs";
import path from "path";
/**
* OG images de /les-femmes/, servies depuis le disque (générées par
* scripts/les-femmes-og.mjs dans public/images/og/les-femmes/) : une image
* absente laisse tomber son tag, jamais l'inverse. Cards : landing (quote
* focus), femmes (27/34), celebres, et une par fiche avec portrait.
*/
const OG_DIR = (f) => path.join(process.cwd(), "public", "images", "og", "les-femmes", f);
function ogImage(file) {
for (const [name, type] of [
[`${file}.png`, "image/png"],
[`${file}.jpg`, "image/jpeg"],
]) {
if (fs.existsSync(OG_DIR(name))) {
return { url: `/images/og/les-femmes/${name}`, type, width: 1200, height: 630 };
}
}
return null;
}
export const landingOg = () => ogImage("landing");
export const femmesOg = () => ogImage("femmes");
export const celebresOg = () => ogImage("celebres");
export const femmeOg = (slug) => ogImage(slug);
/** Bloc openGraph + twitter commun, images optionnelles. */
export function socialMeta({ title, description, canonicalPath, image }) {
return {
title,
description,
alternates: { canonical: canonicalPath },
openGraph: {
title,
description,
url: canonicalPath,
siteName: "me.nech.pl",
locale: "fr_FR",
type: "website",
...(image ? { images: [image] } : {}),
},
twitter: {
card: image ? "summary_large_image" : "summary",
title,
description,
...(image ? { images: [image.url] } : {}),
},
};
}
#!/usr/bin/env node
/**
* OG images pour /les-femmes/ — même pipeline que scripts/og.mjs (HTML →
* Playwright → PNG 1200×630, budget taille PNG sinon JPEG) mais cards
* dédiées au micro-brand :
*
* landing.png la quote focus (Marie Curie) sur le titre de l'app
* femmes.png l'état « Au tour des femmes ! » (27/34)
* celebres.png l'état « Comment ça va, les célébres ? »
* <femme>.png par fiche : portrait à droite, nom + verdict + la
* punchline du personnage à gauche
*
* node scripts/les-femmes-og.mjs [--force]
*
* Incremental : les fichiers existants sont sautés sauf --force. Le
* metadata côté pages vit dans app/les-femmes/og.js (disk-checked).
*/
import { createRequire } from "module";
import fs from "fs";
import os from "os";
import path from "path";
const require = createRequire(import.meta.url);
const { chromium } = require("@playwright/test");
const ROOT = path.resolve(import.meta.dirname, "..");
const FONTS_DIR = path.join(ROOT, "scripts", "og-assets", "fonts");
// Sortie séparée du répertoire des portraits : les cards OG ne doivent
// JAMAIS porter le même nom qu'un portrait (elles l'écraseraient).
const OUT_DIR = path.join(ROOT, "public", "images", "og", "les-femmes");
const PORTRAITS = path.join(ROOT, "public", "images", "les-femmes");
const WIDTH = 1200;
const HEIGHT = 630;
const TMP = fs.mkdtempSync(path.join(os.tmpdir(), "og-les-femmes-"));
const FORCE = process.argv.includes("--force");
// Cohérent avec app/les-femmes/data.ts (CELEBRES/PERSONNAGES) — dupliqué
// volontairement : le script tourne hors build, pas de parse TS.
const FEMMES = JSON.parse(
fs.readFileSync(path.join(ROOT, "app", "les-femmes", "femmes.json"), "utf8")
);
const SHARED_CSS = `
@font-face { font-family: 'Source Serif 4'; font-weight: 400; src: url('file://${FONTS_DIR}/source-serif-4-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Source Serif 4'; font-weight: 600; src: url('file://${FONTS_DIR}/source-serif-4-latin-600-normal.woff2') format('woff2'); }
html, body { margin: 0; }
.card { width: ${WIDTH}px; height: ${HEIGHT}px; box-sizing: border-box; position: relative;
background: #ffffff; color: #1a1a1a; font-family: 'Source Serif 4', Georgia, serif;
padding: 52px 64px; display: flex; flex-direction: column; }
.mast { display: flex; justify-content: space-between; align-items: baseline;
font-size: 16px; letter-spacing: 0.08em; text-transform: uppercase; color: #7b3f8c;
border-bottom: 1px solid #e4dee8; padding-bottom: 16px; }
.quote { margin: auto 0 0; font-size: 68px; line-height: 1.15; font-style: italic; font-weight: 400; }
.who { margin-top: 26px; font-size: 30px; font-weight: 600; }
.host { margin-top: 18px; font-size: 17px; color: #555555; letter-spacing: 0.04em; }
.big { font-size: 88px; font-weight: 600; line-height: 1.1; }
.sub { margin-top: 22px; font-size: 27px; line-height: 1.4; color: #555555; max-width: 900px; }
.femme { display: flex; height: ${HEIGHT}px; }
.femmeText { flex: 1 1 58%; padding: 52px 56px; display: flex; flex-direction: column; box-sizing: border-box; }
.femmePortrait { flex: 1 1 42%; position: relative; }
.femmePortrait img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.verdict { display: inline-block; align-self: flex-start; font-size: 15px; font-weight: 600; letter-spacing: 0.05em;
text-transform: uppercase; color: #fff; border-radius: 4px; padding: 6px 12px; margin-top: 22px; }
.perso { margin-top: auto; font-size: 24px; color: #555555; line-height: 1.4; }
`;
const pageShell = (body) =>
`<!doctype html><html><head><meta charset="utf-8"><style>${SHARED_CSS}</style></head><body>${body}</body></html>`;
const esc = (s) => String(s).replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
function cards() {
const out = [];
out.push({
file: "landing.png",
html: pageShell(`<div class="card">
<div class="mast"><span>Comment ça va, les femmes ?</span><span>me.nech.pl/les-femmes</span></div>
<div class="quote">« Je suis radieuse ! »</div>
<div class="who">Marie Curie</div>
<div class="sub">Les femmes derrière « Comment ça va ce matin ? » — enquête sur les 34 personnages du mème.</div>
</div>`),
});
out.push({
file: "femmes.png",
html: pageShell(`<div class="card">
<div class="mast"><span>Comment ça va, les femmes ?</span><span>me.nech.pl/les-femmes</span></div>
<div class="big">Au tour des femmes !</div>
<div class="sub">Sur les 34 personnages du mème, 27 cachent une femme éclipsée, effacée, moquée ou exclue. Verdicts : appropriation, éclipse, effacement, exclusion.</div>
</div>`),
});
out.push({
file: "celebres.png",
html: pageShell(`<div class="card">
<div class="mast"><span>Comment ça va, les femmes ?</span><span>me.nech.pl/les-femmes</span></div>
<div class="quote">« Tout est bien rangé. »</div>
<div class="who">Simone de Beauvoir</div>
<div class="sub">Les femmes célèbres répondent aussi — punchlines, fiches, vécu.</div>
</div>`),
});
for (const f of FEMMES) {
const portrait = f.file ? path.join(PORTRAITS, f.file) : null;
const imgTag = portrait && fs.existsSync(portrait)
? `<img src="file://${portrait}" alt="">`
: `<div style="height:100%;display:flex;align-items:center;justify-content:center;font-size:180px;color:#7b3f8c;background:#f7f3f8;">${esc(f.name.slice(0, 1))}</div>`;
out.push({
file: `${f.slug}.png`,
html: pageShell(`<div class="femme">
<div class="femmeText">
<div class="mast" style="border-bottom:none;padding-bottom:0;"><span>Comment ça va, les femmes ?</span></div>
<div class="big" style="margin-top:auto;font-size:64px;">${esc(f.name)}</div>
<div class="verdict" style="background:${f.color};">${esc(f.verdictLabel)}</div>
<div class="perso">derrière ${esc(f.personnage)} : « ${esc(f.punchline)} »</div>
<div class="host">me.nech.pl/les-femmes/${esc(f.slug)}</div>
</div>
<div class="femmePortrait">${imgTag}</div>
</div>`),
});
}
return out;
}
async function finalize(browser, card) {
const page = await browser.newPage({ viewport: { width: WIDTH, height: HEIGHT } });
const htmlFile = path.join(TMP, `card-${card.file.replace(/\.png$/, "")}.html`);
fs.writeFileSync(htmlFile, card.html);
await page.goto(`file://${htmlFile}`, { waitUntil: "networkidle" });
await page.waitForTimeout(250); // woff2 + file:// images settle
const png = path.join(TMP, card.file);
await page.screenshot({ path: png, clip: { x: 0, y: 0, width: WIDTH, height: HEIGHT } });
await page.close();
if (process.env.OG_DEBUG) fs.copyFileSync(png, "/tmp/og-debug.png");
const buf = fs.readFileSync(png);
const dest = path.join(OUT_DIR, buf.length > 400_000 ? card.file.replace(".png", ".jpg") : card.file);
if (dest.endsWith(".jpg")) {
// simple re-encode via playwright screenshot jpeg
const page2 = await browser.newPage({ viewport: { width: WIDTH, height: HEIGHT } });
await page2.goto(`file://${htmlFile}`, { waitUntil: "networkidle" });
await page2.waitForTimeout(200);
await page2.screenshot({ path: dest, type: "jpeg", quality: 85, clip: { x: 0, y: 0, width: WIDTH, height: HEIGHT } });
await page2.close();
// Le PNG périmé d'une run précédente ne doit jamais survivre au JPG :
// le metadata helper sert le PNG en priorité.
const stalePng = path.join(OUT_DIR, card.file);
if (fs.existsSync(stalePng)) fs.unlinkSync(stalePng);
} else {
fs.writeFileSync(dest, buf);
}
console.log(`${card.file} -> ${path.basename(dest)} (${fs.statSync(dest).size} bytes)`);
}
fs.mkdirSync(OUT_DIR, { recursive: true });
const todo = cards().filter((c) => FORCE || !fs.existsSync(path.join(OUT_DIR, c.file)) && !fs.existsSync(path.join(OUT_DIR, c.file.replace(".png", ".jpg"))));
if (todo.length === 0) {
console.log("les-femmes og: rien à faire");
process.exit(0);
}
const browser = await chromium.launch();
for (const card of todo) await finalize(browser, card);
await browser.close();
console.log(`${todo.length} og cards écrites dans public/images/les-femmes/`);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment