mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Replace calver (YYYY.MM.DD+sha) with marketing versioning (X.Y.Z), starting at 9.9.0. Add changelog page at /changelog with Keep a Changelog parsing, pre-release banner, and expandable entries linked to GitLab releases. Add VersionCheck component that shows a "What's new" toast when the app version changes. Add release skill for managing versioned releases with changelog and git tagging.
82 lines
2.8 KiB
TypeScript
82 lines
2.8 KiB
TypeScript
/** Category types from Keep a Changelog format. */
|
|
type ChangelogCategory = 'Added' | 'Changed' | 'Deprecated' | 'Removed' | 'Fixed' | 'Security';
|
|
|
|
/** A single version entry in the changelog. */
|
|
interface ChangelogEntry {
|
|
version: string;
|
|
date: string;
|
|
sections: {
|
|
category: ChangelogCategory;
|
|
items: string[];
|
|
}[];
|
|
}
|
|
|
|
/** Apply basic typographic transformations to a changelog item string. */
|
|
function prettify(text: string): string {
|
|
return text
|
|
.replace(/ -- /g, ' \u2014 ') // space-dash-dash-space → em dash
|
|
.replace(/(\w)--(\w)/g, '$1\u2013$2') // word--word → en dash
|
|
.replace(/ (\S+)$/, '\u00A0$1'); // prevent orphaned last word
|
|
}
|
|
|
|
/**
|
|
* Parse a Keep a Changelog formatted markdown string into structured data.
|
|
* @see https://keepachangelog.com/
|
|
*/
|
|
function parseChangelog(markdown: string): ChangelogEntry[] {
|
|
const entries: ChangelogEntry[] = [];
|
|
let current: ChangelogEntry | null = null;
|
|
let currentCategory: ChangelogCategory | null = null;
|
|
|
|
for (const line of markdown.split('\n')) {
|
|
// Match version heading: ## [X.Y.Z] - YYYY-MM-DD
|
|
const versionMatch = line.match(/^## \[([^\]]+)\]\s*-\s*(.+)$/);
|
|
if (versionMatch) {
|
|
current = { version: versionMatch[1], date: versionMatch[2].trim(), sections: [] };
|
|
entries.push(current);
|
|
currentCategory = null;
|
|
continue;
|
|
}
|
|
|
|
// Match category heading: ### Added, ### Changed, etc.
|
|
const categoryMatch = line.match(/^### (.+)$/);
|
|
if (categoryMatch && current) {
|
|
currentCategory = categoryMatch[1].trim() as ChangelogCategory;
|
|
current.sections.push({ category: currentCategory, items: [] });
|
|
continue;
|
|
}
|
|
|
|
// Match list item: - Description
|
|
const itemMatch = line.match(/^- (.+)$/);
|
|
if (itemMatch && current) {
|
|
const section = current.sections[current.sections.length - 1];
|
|
if (section) {
|
|
section.items.push(prettify(itemMatch[1]));
|
|
} else {
|
|
// Item without a category heading — treat as "Changed"
|
|
current.sections.push({ category: 'Changed', items: [prettify(itemMatch[1])] });
|
|
}
|
|
continue;
|
|
}
|
|
|
|
// Lines that don't start with "- " but aren't blank may be a continuation or
|
|
// freeform text after the version heading (e.g. "Initial release of Shakespeare").
|
|
const trimmed = line.trim();
|
|
if (trimmed && current && !trimmed.startsWith('#')) {
|
|
const section = current.sections[current.sections.length - 1];
|
|
if (section) {
|
|
// Append to last item or add new item
|
|
section.items.push(prettify(trimmed));
|
|
} else {
|
|
// Freeform text under version with no category — store in a generic section
|
|
current.sections.push({ category: 'Changed', items: [prettify(trimmed)] });
|
|
}
|
|
}
|
|
}
|
|
|
|
return entries;
|
|
}
|
|
|
|
export { parseChangelog };
|
|
export type { ChangelogEntry, ChangelogCategory };
|