import { readFile } from "node:fs/promises"; import Link from "next/link"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { Changelog } from "yt-dlp-transcript-common/components/Changelog"; import { ScrollToHash } from "./ChangelogAnchorResolver"; import { clampChangelogPage, paginateChangelog, parseChangelogSections, } from "yt-dlp-transcript-common/lib/changelog"; // THE NOTES of /changelog, one page of them, streamed after the page's shell // (the Cut and Amend forms). Async on purpose: its read is the await that lets // the shell flush before the markdown of a page is rendered. // // A page is whole sections up to a size budget (common/lib/changelog.ts, // paginateChangelog); page 1 opens with [Unreleased]. export function pageHref(page: number, anchor?: string): string { const base = page <= 1 ? "/changelog" : `/changelog?page=${page}`; return anchor ? `${base}#${anchor}` : base; } export async function ChangelogNotes({ searchParams, }: { searchParams: Promise>; }) { const [params, source] = await Promise.all([ searchParams, readFile(getPaths().editorChangelogFile, "utf8"), ]); const sections = parseChangelogSections(source); const pages = paginateChangelog(sections); const page = clampChangelogPage(params.page, pages.length); const indexes = pages[page - 1]; const slice = indexes.length > 0 ? source.slice(sections[indexes[0]].start, sections[indexes[indexes.length - 1]].end) : ""; const pageOfSection = new Map(); pages.forEach((p, n) => p.forEach((i) => pageOfSection.set(i, n + 1))); const nav = pages.length > 1 && ( ); return (
{sections.length > 1 && (
All releases ({sections.filter((s) => s.version).length})
)} {nav} {nav}
); }