studiocms
Version:
Astro Native CMS for AstroDB. Built from the ground up by the Astro community.
55 lines (54 loc) • 1.75 kB
JavaScript
import { loadChangelog, semverCategories } from "@withstudiocms/internal_helpers/utils";
import { addVirtualImports, defineUtility } from "astro-integration-kit";
import { toMarkdown } from "mdast-util-to-markdown";
const changelogHelper = defineUtility("astro:config:setup")(
(params, resolvedPath) => {
const changelog = loadChangelog({ path: resolvedPath });
const output = [];
const ast = {
type: "root",
children: []
};
const latestVersion = changelog.versions[0];
const latestVersionChanges = { type: "list", children: [] };
if (latestVersion) {
for (const semverCategory of semverCategories) {
for (const listItem of latestVersion.changes[semverCategory].children) {
latestVersionChanges.children.push(listItem);
}
}
if (latestVersion.includes.size) {
latestVersionChanges.children.push({
type: "listItem",
children: [
{
type: "paragraph",
children: [
{ type: "text", value: `Includes: ${[...latestVersion.includes].join(", ")} ` }
]
}
]
});
}
ast.children.push({
type: "heading",
depth: 2,
children: [{ type: "text", value: `${latestVersion.version}` }]
});
}
if (latestVersionChanges.children.length) {
ast.children.push(latestVersionChanges);
}
output.push(toMarkdown(ast, { bullet: "-" }));
const markdownString = output.join("\n");
addVirtualImports(params, {
name: "studiocms/changelog",
imports: {
"studiocms:changelog": `export default ${JSON.stringify(markdownString)};`
}
});
}
);
export {
changelogHelper
};