diff --git a/ACCESSIBILITY.md b/ACCESSIBILITY.md index c8a0f72..366b500 100644 --- a/ACCESSIBILITY.md +++ b/ACCESSIBILITY.md @@ -67,6 +67,17 @@ has not been audited by a third party, and this is not a claim of conformance. WCAG 2.5.8 through the space around them. - **Reading.** Stories have their own settings: three text sizes and a paper, sepia or dark background. +- **Content warnings.** A labelled post, chapter or album opens with a banner that names its + labels (horror, violence, politics…) in words, not by colour or icon alone. For the visual + labels, images in the page are blurred until "Show images" is ticked. That control is a real + checkbox, and the blur is plain CSS, so it works from the keyboard and without JavaScript. + Blurring is a courtesy layer, not access control: the images are still downloaded. +- **Age check.** An age-rated text is folded inside a `
` element. With JavaScript, its + summary asks for the reader's age in a native modal ``: focus starts on "No", Esc + cancels and never counts as "yes", and focus returns to the summary. If the reader says no, + focus moves to a line that explains why and offers to choose again. Nothing pops up on its own. + Without JavaScript the summary opens the text. The answer stays in the browser + (`localStorage`); see the privacy policy. ## Tested with diff --git a/docs/templates/blog.md b/docs/templates/blog.md index eb33bdc..946b724 100644 --- a/docs/templates/blog.md +++ b/docs/templates/blog.md @@ -12,6 +12,10 @@ draft: true translationKey add the SAME value to the vi and en file to pair them for hreflang updated optional, YYYY-MM-DD — adds dateModified to the BlogPosting schema cover optional, path relative to this file; Astro validates it exists + contentWarning optional labels from src/lib/content-labels.ts, e.g. [politics] — a banner; + the visual ones (horror, blood, violence…) also blur the post's images + ageRating optional "13+" | "16+" | "18+" — the text stays folded until the reader + confirms their age draft: true hidden in production, visible in `npm run dev`. Flip when ready. --> diff --git a/docs/templates/story-chapter.md b/docs/templates/story-chapter.md index 98432cb..c0ade31 100644 --- a/docs/templates/story-chapter.md +++ b/docs/templates/story-chapter.md @@ -7,6 +7,7 @@ series: "{{SERIES}}" chapter: 1 status: ongoing contentWarning: [] +# ageRating: "16+" tags: [] draft: true --- @@ -16,7 +17,11 @@ draft: true series in one folder, e.g. stories/dem-khong-tieng/chuong-01.md chapter integer, consecutive; drives prev/next links and ordering status ongoing | complete | dropped - contentWarning e.g. [horror, violence] — renders a warning gate before the text + contentWarning labels from src/lib/content-labels.ts, e.g. [horror, violence]: a warning + banner; horror, blood, jumpscare, violence, self-harm and death also + blur the images + ageRating "13+" | "16+" | "18+" (optional): the text stays folded until the + reader confirms their age (remembered in their browser only) --> Chương bắt đầu ở đây. diff --git a/poli0981.dev-docs/03_DESIGN_SYSTEM.md b/poli0981.dev-docs/03_DESIGN_SYSTEM.md index 04f4925..af8e835 100644 --- a/poli0981.dev-docs/03_DESIGN_SYSTEM.md +++ b/poli0981.dev-docs/03_DESIGN_SYSTEM.md @@ -112,10 +112,11 @@ Token `--scrollbar-thumb` / `--scrollbar-thumb-hover` / `--scrollbar-track` khai | Header / MobileTabBar / Footer | .astro | TabBar: Home·Blog·Truyện·Menu, ẩn ≥768px; nav chính của header hiện từ 960px (dưới đó dùng nút menu — bản EN cần ~900px) | | ThemeToggle, LangSwitch | island nhỏ / .astro | ThemeToggle 3 trạng thái (§6); LangSwitch nhận href đã giải bản dịch từ BaseLayout | | ScrollbarToggle | island nhỏ (footer, chỉ hiện khi `pointer: fine`) | switch `role="switch"`; localStorage `scrollbar=hidden` → `html[data-scrollbar="hidden"]`, áp trước first paint cùng bootstrap theme | -| PostCard / StoryCard / ProjectCard | .astro | StoryCard có badge status + CW | +| PostCard / StoryCard / ProjectCard | .astro | StoryCard có badge status + nhãn đã dịch + mốc tuổi; PostCard/GalleryCard: bìa mờ khi có nhãn làm mờ | | Prose | .astro + `src/styles/prose.css` | typography cho nội dung md; cùng stylesheet dùng cho preview trong admin | | ReadingControls | island | cỡ chữ (3 mức, localStorage `reader`), theme giấy/sepia/tối, progress bar 2px | -| ContentWarning | .astro | banner `--horror`, bấm để mở nội dung | +| ContentNotice | .astro | banner `--horror` nêu mọi nhãn (`src/lib/content-labels.ts`); nhãn làm mờ ⇒ ô "Hiện ảnh" (checkbox + CSS `:has()`, chạy khi tắt JS); vùng bài mang `data-cw-blur` | +| AgeGate | .astro | nội dung có `ageRating` nằm trong `
`; có JS ⇒ `` hỏi tuổi (Esc = huỷ), trả lời lưu localStorage `ageGate` (`src/lib/age-gate.ts`) | | Lightbox | island | vuốt được, lazy; thumbnail là link tới ảnh lớn (chạy được khi tắt JS) | | SearchModal | island | Pagefind, mở bằng `/` hoặc nút; ARIA combobox (`aria-activedescendant`), báo lỗi khi không tải được index | | MenuSheet | island | dialog modal, bẫy focus, trả focus về nút mở | diff --git a/poli0981.dev-docs/04_CONTENT_MODEL.md b/poli0981.dev-docs/04_CONTENT_MODEL.md index a76220f..b378045 100644 --- a/poli0981.dev-docs/04_CONTENT_MODEL.md +++ b/poli0981.dev-docs/04_CONTENT_MODEL.md @@ -25,6 +25,8 @@ const base = z.object({ tags: z.array(z.string()).default([]), cover: image().optional(), draft: z.boolean().default(false), + contentWarning: z.array(z.enum(LABEL_IDS)).default([]), // nhãn: src/lib/content-labels.ts + ageRating: z.enum(["13+","16+","18+"]).optional(), // có ⇒ hỏi tuổi trước khi hiện }); blog: base // tags gợi ý: dev-log, diary, share, gaming @@ -32,7 +34,6 @@ stories: base.extend({ series: z.string().optional(), chapter: z.number().int().positive().optional(), status: z.enum(['ongoing','complete','dropped']).default('ongoing'), - contentWarning: z.array(z.string()).default([]), // vd: ['horror','blood'] }) projects: z.object({ name, tagline, lang, stack: z.array(z.string()), repo: z.string().url().optional(), url: z.string().url().optional(), @@ -46,6 +47,20 @@ gallery: z.object({ title, lang, date, description: z.string().optional(), Alt text ảnh gallery: file `src/assets/gallery//captions.json` (`{"IMG_001.avif": {"vi":"...","en":"..."}}`) — build fail nếu thiếu key. +### Nhãn nội dung & giới hạn tuổi (v2.3.0) + +- **Nhãn** (`contentWarning`, blog · truyện · album; danh sách cố định ở `src/lib/content-labels.ts`, + tên vi/en ở `src/i18n` nhóm `labels`): `horror`, `blood`, `jumpscare`, `violence`, `self-harm`, + `death` — **làm mờ ảnh** + banner; `politics`, `religion`, `strong-language`, `flashing-lights`, + `spoilers` — chỉ banner. Nhãn lạ ⇒ build fail. +- **Từng ảnh** có thể có nhãn riêng: `contentWarning` cạnh caption trong `gallery-photos/.json` + (admin → Gallery → "Nhãn") hoặc `captions.json` (`{"IMG_001.avif": {"vi":"…","en":"…","contentWarning":["blood"]}}`). +- **Giới hạn tuổi** (`ageRating`: `13+` | `16+` | `18+`): phần nội dung thu gọn tới khi người đọc xác + nhận tuổi; câu trả lời chỉ lưu localStorage `ageGate` (mốc tuổi, không ngày sinh) — xem chính sách + quyền riêng tư §6. Tắt JS: bấm mở là tự xác nhận. +- Làm mờ là lớp hiển thị, **không** phải kiểm soát truy cập (ảnh vẫn được tải). Thẻ danh sách, RSS và + ảnh OG đều nêu nhãn; trích đoạn tìm kiếm không lấy banner và phần nội dung có giới hạn tuổi. + ## 3. Frontmatter mẫu ```yaml @@ -71,6 +86,7 @@ series: "Đêm không tiếng" chapter: 1 status: ongoing contentWarning: [horror] +ageRating: "16+" tags: [horror, short-story] --- ``` @@ -121,6 +137,6 @@ Tiện ích khuyến nghị: snippet VS Code cho từng frontmatter; `npm run ne - [ ] frontmatter đủ + đúng schema (`astro check` pass) - [ ] slug không dấu, chưa từng dùng - [ ] ảnh đã strip EXIF, có alt/caption -- [ ] truyện: contentWarning đặt đúng; chương đánh số liên tục +- [ ] nhãn nội dung (`contentWarning`) và mốc tuổi (`ageRating`) đặt đúng; truyện: chương đánh số liên tục - [ ] đọc lại trên preview mobile (dev server, viewport 390px) - [ ] bài EN/VI có `translationKey` nếu là bản dịch diff --git a/poli0981.dev-docs/05_SITEMAP_UX.md b/poli0981.dev-docs/05_SITEMAP_UX.md index d925576..7b6e868 100644 --- a/poli0981.dev-docs/05_SITEMAP_UX.md +++ b/poli0981.dev-docs/05_SITEMAP_UX.md @@ -40,7 +40,8 @@ ``` [thanh mảnh: ← series | tiêu đề chương | Aa] ← Aa mở ReadingControls [progress bar 2px sticky top] -[ContentWarning nếu có → bấm mới hiện nội dung] +[ContentNotice nếu có nhãn → banner; nhãn làm mờ ⇒ ảnh mờ tới khi tick "Hiện ảnh"] +[AgeGate nếu có ageRating → bấm summary ⇒ hỏi tuổi ⇒ mới hiện nội dung] Literata 68ch, 1.125–1.25rem [Chương trước ─ Mục lục series ─ Chương sau] ``` diff --git a/poli0981.dev-docs/13_SEO_RSS_OG.md b/poli0981.dev-docs/13_SEO_RSS_OG.md index f113f33..b46e141 100644 --- a/poli0981.dev-docs/13_SEO_RSS_OG.md +++ b/poli0981.dev-docs/13_SEO_RSS_OG.md @@ -48,7 +48,8 @@ Item: title, link, pubDate, description, `` theo bài, category = tags ## 5. OG image tự sinh - Build-time bằng Satori + resvg (hoặc `astro-og-canvas` nếu gọn hơn lúc triển khai): template 1200×630, nền glacier night (palette tối) + Waveline + title (Bricolage) + badge khu (Blog/Truyện/Project) + `poli0981.dev`. -- Truyện có contentWarning: OG thêm dải màu horror + nhãn CW (không spoil chi tiết). +- Bài/truyện có nhãn (`contentWarning`) hoặc mốc tuổi (`ageRating`): OG thêm dải màu horror "Cảnh báo · Kinh dị · 16+" bằng ngôn ngữ của bài (không spoil chi tiết). Thẻ OG chỉ có chữ nên không bao giờ lộ ảnh bìa. +- RSS: description của mục có nhãn được thêm tiền tố "[Cảnh báo: Kinh dị · 16+] " (theo ngôn ngữ của mục) — feed reader không có banner. - Cache theo hash(title+khu) để build nhanh. ## 6. Dữ liệu có cấu trúc (JSON-LD) diff --git a/scripts/gen-og.mjs b/scripts/gen-og.mjs index d564322..83f8d65 100644 --- a/scripts/gen-og.mjs +++ b/scripts/gen-og.mjs @@ -12,6 +12,9 @@ import { fileURLToPath } from "node:url"; import path from "node:path"; import { ogKey } from "../src/lib/og.ts"; import { PALETTE } from "../src/lib/palette.ts"; +import { labelNames } from "../src/lib/content-labels.ts"; +import vi from "../src/i18n/vi.ts"; +import en from "../src/i18n/en.ts"; const root = fileURLToPath(new URL("..", import.meta.url)); const fontsDir = path.join(root, "src/assets/fonts"); @@ -69,7 +72,7 @@ function entryCard({ title, badge, cw }) { const t = esc(title); const size = t.length > 70 ? 50 : t.length > 45 ? 60 : 74; const strip = cw - ? `
CW · ${esc(cw)}
` + ? `
${esc(cw)}
` : ""; return html( SHELL(` @@ -141,10 +144,16 @@ for (const { dir, section, titleKey } of SECTIONS) { const id = relPosix.replace(/\.(md|mdx)$/, ""); const lang = data.lang === "en" ? "en" : "vi"; const title = data[titleKey] ?? id; + // A labelled post or chapter says so on its card, in its own language: a link preview + // shows no banner. Cards are text only, so no image of the item ever appears on them. + const strings = lang === "en" ? en : vi; + const labels = Array.isArray(data.contentWarning) ? data.contentWarning.map(String) : []; + const parts = [ + ...labelNames(labels, strings.labels), + ...(data.ageRating ? [String(data.ageRating)] : []), + ]; const cw = - section === "story" && Array.isArray(data.contentWarning) && data.contentWarning.length - ? data.contentWarning.join(" · ") - : null; + section !== "project" && parts.length ? [strings.cw.title, ...parts].join(" · ") : null; const png = await render(entryCard({ title, badge: BADGES[section][lang], cw })); writeFileSync(path.join(outDir, `${ogKey(section, id)}.png`), png); count++; diff --git a/src/components/AgeGate.astro b/src/components/AgeGate.astro new file mode 100644 index 0000000..f64127e --- /dev/null +++ b/src/components/AgeGate.astro @@ -0,0 +1,254 @@ +--- +import { useTranslations } from "../i18n"; +import { homePath, type Locale } from "../i18n/routing"; +import { withAge } from "../lib/age-gate"; +import { minAge, type AgeRating } from "../lib/content-labels"; + +interface Props { + rating: AgeRating; + locale: Locale; +} + +// Folds an age-rated text away until the reader confirms their age (src/lib/age-gate.ts). +// - In the HTML the text is a closed
: the safe state needs no script, and without +// JavaScript opening it is the confirmation (privacy policy §8: core content works with +// JavaScript off). +// - With JavaScript, the summary asks first, in a native modal (focus stays inside, +// Esc cancels — it never means "yes"); the answer is kept in this browser's localStorage. +// - It never pops up on its own: the page around it (title, banner, navigation) stays usable. +// Search indexes the page's title, not anything inside the gate. +const { rating, locale } = Astro.props; +const t = useTranslations(locale); +const age = minAge(rating) ?? 18; +--- + + +
+ + + + +
+ + {rating} + {withAge(t.cw.gate, age)} + + {t.cw.gateHint} + +
+ +
+
+ + +
+

{withAge(t.cw.question, age)}

+

{withAge(t.cw.explain, age)}

+
+ + + +
+
+
+
+ + + + diff --git a/src/components/ContentNotice.astro b/src/components/ContentNotice.astro new file mode 100644 index 0000000..883ae22 --- /dev/null +++ b/src/components/ContentNotice.astro @@ -0,0 +1,119 @@ +--- +import { useTranslations } from "../i18n"; +import type { Locale } from "../i18n/routing"; +import { labelNames, needsBlur, type AgeRating } from "../lib/content-labels"; + +interface Props { + /** The item's content labels (src/lib/content-labels.ts). */ + labels: readonly string[]; + ageRating?: AgeRating | undefined; + locale: Locale; +} + +// The banner at the top of a labelled post, chapter or album. When a label blurs images, the +// region this sits in must carry `data-cw-blur` (global.css): every image in it stays blurred +// until "Hiện ảnh" is ticked. That is a real checkbox read by CSS `:has()`, so it works with +// JavaScript off and nothing sharp shows before a script runs. Search skips the banner. +const { labels, ageRating, locale } = Astro.props; +const t = useTranslations(locale); +const names = labelNames(labels, t.labels); +const blur = needsBlur(labels); +--- + +{ + (names.length > 0 || ageRating) && ( +
+

+ + {t.cw.title} +

+
    + {names.map((name) => ( +
  • {name}
  • + ))} + {ageRating &&
  • {ageRating}
  • } +
+ {blur && ( +

+ {t.cw.blurNote} + +

+ )} +
+ ) +} + + diff --git a/src/components/ContentWarning.astro b/src/components/ContentWarning.astro deleted file mode 100644 index abc0c1d..0000000 --- a/src/components/ContentWarning.astro +++ /dev/null @@ -1,81 +0,0 @@ ---- -interface Props { - warnings: string[]; - title?: string; - hint?: string; -} -// JS-free reveal via native
— keyboard-accessible and CSP-clean. -const { warnings, title = "Cảnh báo nội dung", hint = "Bấm để đọc" } = Astro.props; ---- - -
- - - {title} - { - warnings.length > 0 && ( - - {warnings.map((w) => ( - {w} - ))} - - ) - } - {hint} - -
- -
-
- - diff --git a/src/components/GalleryCard.astro b/src/components/GalleryCard.astro index 2201841..115b636 100644 --- a/src/components/GalleryCard.astro +++ b/src/components/GalleryCard.astro @@ -1,9 +1,11 @@ --- import { Image } from "astro:assets"; import MediaImage from "./MediaImage.astro"; -import { type GalleryEntry } from "../lib/collections"; +import { albumWarning, type GalleryEntry } from "../lib/collections"; import type { GalleryPhoto } from "../lib/gallery"; import { sectionPath, type Locale } from "../i18n/routing"; +import { useTranslations } from "../i18n"; +import { labelNames, needsBlur } from "../lib/content-labels"; interface Props { entry: GalleryEntry; @@ -17,11 +19,18 @@ const { entry, cover, locale, headingLevel = 3 } = Astro.props; const Title = `h${headingLevel}` as const; const href = sectionPath("gallery", locale, entry.data.album); const year = entry.data.date.getFullYear(); +// The cover stays blurred when the album (in either language) or that photo carries a label +// that blurs images, or when the album is age-rated; the card says why. +const t = useTranslations(locale); +const { labels: albumLabels, ageRating } = await albumWarning(entry.data.album); +const labels = [...new Set([...albumLabels, ...cover.labels])]; +const blurCover = needsBlur(labels) || Boolean(ageRating); +const warning = [...labelNames(labels, t.labels), ...(ageRating ? [ageRating] : [])].join(" · "); --- @@ -70,11 +88,22 @@ const year = entry.data.date.getFullYear(); } .body { display: flex; + flex-wrap: wrap; align-items: baseline; justify-content: space-between; - gap: 0.75rem; + gap: 0.25rem 0.75rem; padding: 0.9rem 1.1rem 1rem; } + /* Its own line under the title; the gap stands in for the whitespace the build strips. */ + .cw { + display: inline-flex; + flex-wrap: wrap; + gap: 0.35em; + flex-basis: 100%; + color: color-mix(in srgb, var(--horror) 35%, var(--text)); + font-family: var(--ff-mono); + font-size: var(--text-meta); + } .title { font-size: var(--text-lead); font-weight: 700; diff --git a/src/components/GalleryGrid.astro b/src/components/GalleryGrid.astro new file mode 100644 index 0000000..e5de3e8 --- /dev/null +++ b/src/components/GalleryGrid.astro @@ -0,0 +1,99 @@ +--- +import { Image } from "astro:assets"; +import MediaImage from "./MediaImage.astro"; +import type { GalleryPhoto } from "../lib/gallery"; +import type { Locale } from "../i18n/routing"; + +interface Props { + photos: GalleryPhoto[]; + /** The lightbox slide (full-size image) each thumbnail links to. */ + hrefs: string[]; + /** Per photo: blurred on its own (a label of its own, in an album that isn't blurred). */ + blurred: boolean[]; + /** Per photo: the accessible name — "open", the caption, and any warning. */ + labels: string[]; + locale: Locale; +} + +// The album's thumbnails. Each links to its full-size image, so the album works without JS; +// the lightbox island takes over plain clicks once it hydrates. +const { photos, hrefs, blurred, labels } = Astro.props; +--- + +
+ { + photos.map((p, i) => ( + + {p.kind === "local" ? ( + + ) : ( + + )} + + )) + } +
+ + diff --git a/src/components/Lightbox.svelte b/src/components/Lightbox.svelte index be2256d..a42e590 100644 --- a/src/components/Lightbox.svelte +++ b/src/components/Lightbox.svelte @@ -3,9 +3,12 @@ import { prefersReducedMotion } from "../lib/motion"; /** + * `blur`: the photo has a content label that blurs images (src/lib/content-labels.ts); + * `warning` names it. Such a slide opens blurred, behind a "show" button, unless the page's + * own "Hiện ảnh" box (ContentNotice) is ticked. * @type {{ - * slides: { src: string, srcset: string, width: number, height: number, alt: string }[], - * labels: { viewer: string, close: string, prev: string, next: string, counter: string } + * slides: { src: string, srcset: string, width: number, height: number, alt: string, blur?: boolean, warning?: string }[], + * labels: { viewer: string, close: string, prev: string, next: string, counter: string, reveal?: string } * }} */ let { slides = [], labels } = $props(); @@ -15,8 +18,12 @@ let dialogEl = $state(null); let trackEl = $state(null); let opener = null; // element to restore focus to on close + /** @type {Record} slides shown unblurred in this viewing */ + let revealed = $state({}); + let pageRevealed = $state(false); const current = $derived(slides[index]); + const veiled = $derived(Boolean(current?.blur) && !pageRevealed && !revealed[index]); const counter = $derived( labels.counter.replace("{i}", String(index + 1)).replace("{n}", String(slides.length)), ); @@ -25,6 +32,7 @@ if (i < 0 || i >= slides.length) return; opener = document.activeElement; index = i; + pageRevealed = document.querySelector(".cw-reveal-input:checked") !== null; open = true; await tick(); dialogEl?.querySelector(".close")?.focus(); @@ -152,7 +160,9 @@ - {counter} — {current.alt} + {counter} + — {current.alt}{veiled && current.warning ? ` — ${current.warning}` : ""} + @@ -176,6 +186,7 @@ onpointercancel={onPointerUp} > {current.alt} + {#if veiled} +
+ {#if current.warning}

{current.warning}

{/if} + + +
+ {/if}