mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 16:16:50 +00:00
Support multiple versions in technical changelog
- Better handling of article links - Style improvements
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user