feat(ajustes): adicionar aba changelog com histórico de versões

Parser lê o CHANGELOG.md e exibe as versões com badges por tipo de mudança
(Adicionado, Alterado, Corrigido) na página de ajustes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Felipe Coutinho
2026-02-06 17:45:24 +00:00
parent 95e9a61741
commit 390754c0e8
4 changed files with 124 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import fs from "node:fs";
import path from "node:path";
export type ChangelogSection = {
type: string;
items: string[];
};
export type ChangelogVersion = {
version: string;
date: string;
sections: ChangelogSection[];
};
export function parseChangelog(): ChangelogVersion[] {
const filePath = path.join(process.cwd(), "CHANGELOG.md");
const content = fs.readFileSync(filePath, "utf-8");
const lines = content.split("\n");
const versions: ChangelogVersion[] = [];
let currentVersion: ChangelogVersion | null = null;
let currentSection: ChangelogSection | null = null;
for (const line of lines) {
const versionMatch = line.match(/^## \[(.+?)\] - (.+)$/);
if (versionMatch) {
if (currentSection && currentVersion) {
currentVersion.sections.push(currentSection);
}
currentVersion = {
version: versionMatch[1],
date: versionMatch[2],
sections: [],
};
versions.push(currentVersion);
currentSection = null;
continue;
}
const sectionMatch = line.match(/^### (.+)$/);
if (sectionMatch && currentVersion) {
if (currentSection) {
currentVersion.sections.push(currentSection);
}
currentSection = { type: sectionMatch[1], items: [] };
continue;
}
const itemMatch = line.match(/^- (.+)$/);
if (itemMatch && currentSection) {
currentSection.items.push(itemMatch[1]);
}
}
if (currentSection && currentVersion) {
currentVersion.sections.push(currentSection);
}
return versions;
}