mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 20:59:59 +00:00
23 lines
724 B
TypeScript
23 lines
724 B
TypeScript
import { compareVersions } from 'compare-versions';
|
|
|
|
export function getVersionFromPath(path: string) {
|
|
return path.split('/').pop()?.split('.md').shift()!;
|
|
}
|
|
|
|
export function getAllChangelogs() {
|
|
const changelogImports = import.meta.glob("/changelogs/*.md");
|
|
|
|
const sortedVersions = Object.keys(changelogImports)
|
|
.map(path => [path, getVersionFromPath(path)])
|
|
.sort(([, a], [, b]) => compareVersions(a, b));
|
|
|
|
const sortedChangelogs = sortedVersions.reduce(
|
|
(obj, [path, version]) => ({
|
|
[version]: changelogImports[path],
|
|
...obj
|
|
}), {} as typeof changelogImports
|
|
);
|
|
|
|
return sortedChangelogs;
|
|
}
|