Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

2.8 KB
Raw Blame
// docs/CHANGELOG.md → structure, so Settings can RENDER it instead of dumping it.
//
// The file is generated by scripts/gen-changelog.mjs, so its shape is fixed and
// parsing it is honest rather than fragile:
//
//   ## 2026-08-17          → a day
//   **Fixed**              → a group inside that day
//   - `scope` subject      → an entry, scope optional
//
// It was previously fed to the generic markdown→HTML helper and injected with
// dangerouslySetInnerHTML. That rendered the developer preamble ("Generated — do
// not edit", the path of the script) to a person who wanted to know what changed,
// turned every entry into a `<br/>`-joined line with no hierarchy, and put an HTML
// injection path where structured data would do. None of that is markdown's fault:
// this is a list of records, and it should be typed like one.

export interface ChangelogEntry {
  /** The conventional-commit scope, when the subject had one. */
  scope: string;
  text: string;
}
export interface ChangelogGroup {
  /** "Added", "Fixed", "Docs" … — the generator's own section label. */
  label: string;
  entries: ChangelogEntry[];
}
export interface ChangelogDay {
  date: string;
  groups: ChangelogGroup[];
}

const DAY = /^##\s+(\d{4}-\d{2}-\d{2})\s*$/;
const GROUP = /^\*\*(.+?)\*\*\s*$/;
const ENTRY = /^[-*]\s+(.*)$/;
/** A leading `scope` chip, exactly as the generator emits it. */
const SCOPE = /^`([^`]+)`\s*(.*)$/;

export function parseChangelog(markdown: string): ChangelogDay[] {
  const days: ChangelogDay[] = [];
  let day: ChangelogDay | null = null;
  let group: ChangelogGroup | null = null;

  for (const raw of markdown.split(/\r?\n/)) {
    const line = raw.trim();
    const dayMatch = DAY.exec(line);
    if (dayMatch) {
      // Everything before the first day heading is the file's own preamble, which
      // is addressed to whoever maintains the generator — never to the reader.
      day = { date: dayMatch[1], groups: [] };
      days.push(day);
      group = null;
      continue;
    }
    if (!day) continue;

    const groupMatch = GROUP.exec(line);
    if (groupMatch) {
      group = { label: groupMatch[1], entries: [] };
      day.groups.push(group);
      continue;
    }

    const entryMatch = ENTRY.exec(line);
    if (!entryMatch) continue;
    // An entry before any group heading still belongs to the day; give it a home
    // rather than dropping it, because a dropped line is invisible in the UI.
    if (!group) {
      group = { label: "Changed", entries: [] };
      day.groups.push(group);
    }
    const scoped = SCOPE.exec(entryMatch[1].trim());
    group.entries.push(
      scoped ? { scope: scoped[1], text: scoped[2].trim() } : { scope: "", text: entryMatch[1].trim() },
    );
  }

  // A day whose entries were all preamble noise would render as an empty header.
  return days.filter((d) => d.groups.some((g) => g.entries.length > 0));
}