Support multiple versions in technical changelog

- Better handling of article links
- Style improvements
This commit is contained in:
Misode
2021-11-02 02:25:04 +01:00
parent 582d5f4b1e
commit cc20cb7f7a
3 changed files with 70 additions and 17 deletions

View File

@@ -1,33 +1,40 @@
import { isObject } from '../Utils'
const repo = 'https://raw.githubusercontent.com/misode/technical-changes/main'
export type ChangelogEntry = {
group: string,
version: string,
group: ChangelogVersion,
version: ChangelogVersion,
tags: string[],
content: string,
}
export type ChangelogVersion = {
id: string,
article: string | null,
}
let Changelogs: ChangelogEntry[] | Promise<ChangelogEntry[]> | null = null
export async function getChangelogs() {
if (!Changelogs) {
const index = await (await fetch(`${repo}/index.json`)).json() as string[]
Changelogs = (await Promise.all(
index.map(group => fetchGroup(group))
index.map(group => fetchGroup(parseVersion(group)))
)).flat()
}
return Changelogs
}
async function fetchGroup(group: string) {
const index = await (await fetch(`${repo}/${group}/index.json`)).json() as string[]
async function fetchGroup(group: ChangelogVersion) {
const index = await (await fetch(`${repo}/${group.id}/index.json`)).json() as string[]
return (await Promise.all(
index.map(version => fetchChangelog(group, version))
index.map(version => fetchChangelog(group, parseVersion(version)))
)).flat()
}
async function fetchChangelog(group: string, version: string) {
const text = await (await fetch(`${repo}/${group}/${version}.md`)).text()
async function fetchChangelog(group: ChangelogVersion, version: ChangelogVersion) {
const text = await (await fetch(`${repo}/${group.id}/${version.id}.md`)).text()
return parseChangelog(text).map(change => ({
version,
group,
@@ -47,3 +54,15 @@ function parseChangelog(text: string) {
}
})
}
function parseVersion(version: unknown): ChangelogVersion {
if (typeof version === 'string') {
return {
id: version,
article: version.match(/\d\dw\d\d[a-z]/) ? 'minecraft-snapshot-' + version : version.match(/\d+\.\d+(\.\d+)?-pre[0-9]+/) ? 'minecraft-' + version.replaceAll('.', '-').replaceAll('pre', 'pre-release-') : null,
}
} else if (isObject(version)) {
return version as ChangelogVersion
}
return { id: 'unknown', article: null }
}