mirror of
https://github.com/prdlk/leetcode.git
synced 2026-11-02 13:12:44 +00:00
feat(config): tag changelog releases by Topic or Review category
This commit is contained in:
1 parent
d6b483f84e
commit
4548289ecf
1 file changed
+60
-23
+60
-23
@@ -1,21 +1,25 @@
|
|||||||
import { defineConfig } from "blume";
|
import { defineConfig } from "blume";
|
||||||
import type { StandardSchema } from "blume/core/standard-schema.ts";
|
import type { StandardSchema } from "blume/core/standard-schema.ts";
|
||||||
|
import { hashText } from "blume/core/sources/cache.ts";
|
||||||
|
import type { ContentSource } from "blume/core/sources/types.ts";
|
||||||
import { custom, filesystem } from "blume/sources";
|
import { custom, filesystem } from "blume/sources";
|
||||||
import { githubReleasesSource } from "blume/sources/github-releases.ts";
|
import { githubReleasesSource } from "blume/sources/github-releases.ts";
|
||||||
import redirects from "./redirects";
|
import redirects from "./redirects";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GitHub releases → /changelog, dated by the topic's real finish instant.
|
* GitHub releases → /changelog, dated by the real finish instant of the topic
|
||||||
|
* or `Review <N> — <Phase>` issue each release records.
|
||||||
*
|
*
|
||||||
* Blume dates a release entry by `published_at`, which the GitHub API cannot
|
* Blume dates a release entry by `published_at`, which the GitHub API cannot
|
||||||
* backdate — so the topic releases backfilled on one day (apps/cli/
|
* backdate — so the releases backfilled on one day (apps/cli/
|
||||||
* release-topics.ts) would all read that day. Their tags are timever
|
* release-topics.ts) would all read that day. Their tags are timever
|
||||||
* (`YYYYMMDD.HHMMSS.NNNNNNNNN`, UTC) of the moment the topic finished, so this
|
* (`YYYYMMDD.HHMMSS.NNNNNNNNN`, UTC) of the moment the topic or review
|
||||||
* fetch rewrites each timever release's `published_at` to that instant before
|
* finished, so this fetch rewrites each timever release's `published_at` to
|
||||||
* Blume maps it; anything else passes through untouched. The config-level
|
* that instant before Blume maps it; anything else passes through untouched.
|
||||||
* `githubReleases()` accepts no `fetchImpl`, hence the `custom()` wrap of the
|
* The config-level `githubReleases()` accepts no `fetchImpl`, hence the
|
||||||
* underlying source (the `blume/sources/*.ts` path the Blume docs use for
|
* `custom()` wrap of the underlying source (the `blume/sources/*.ts` path the
|
||||||
* custom sources), with the context the built-in adapter would receive.
|
* Blume docs use for custom sources), with the context the built-in adapter
|
||||||
|
* would receive.
|
||||||
*/
|
*/
|
||||||
const TIMEVER = /^(\d{4})(\d{2})(\d{2})\.(\d{2})(\d{2})(\d{2})\.\d{9}$/;
|
const TIMEVER = /^(\d{4})(\d{2})(\d{2})\.(\d{2})(\d{2})(\d{2})\.\d{9}$/;
|
||||||
|
|
||||||
@@ -38,6 +42,37 @@ const releasesDatedByTag: typeof fetch = async (input, init) => {
|
|||||||
return Response.json(releases, { status: res.status });
|
return Response.json(releases, { status: res.status });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The changelog index tags every row with `changelog.category`, which the
|
||||||
|
* GitHub source sets to "Release" for all of them. release-topics.ts names
|
||||||
|
* each release after its issue, so the title prefix says which kind finished
|
||||||
|
* — a topic's core set, or a Review day block — and the row is tagged
|
||||||
|
* `Topic` / `Review` instead. The category lives both in `data` and in the
|
||||||
|
* staged `raw` frontmatter Astro re-parses, so both are rewritten (and the
|
||||||
|
* hash with them). Wrapped around the source Blume rebuilds via
|
||||||
|
* `withContext`, so the rebuilt one is tagged too.
|
||||||
|
*/
|
||||||
|
const RELEASE_KIND = /^(Topic|Review) \d+ — /;
|
||||||
|
|
||||||
|
const releasesByKind = (source: ContentSource): ContentSource => ({
|
||||||
|
...source,
|
||||||
|
load: async () => {
|
||||||
|
const result = await source.load();
|
||||||
|
for (const entry of result.entries) {
|
||||||
|
const kind = typeof entry.data.title === "string" ? entry.data.title.match(RELEASE_KIND)?.[1] : undefined;
|
||||||
|
const changelog = entry.data.changelog;
|
||||||
|
if (!kind || !changelog || typeof changelog !== "object" || !("category" in changelog)) continue;
|
||||||
|
changelog.category = kind;
|
||||||
|
if (entry.raw) {
|
||||||
|
entry.raw = entry.raw.replace(/^( {2}category: ).*$/m, `$1${kind}`);
|
||||||
|
entry.hash = hashText(entry.raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
withContext: source.withContext && ((ctx) => releasesByKind(source.withContext!(ctx))),
|
||||||
|
});
|
||||||
|
|
||||||
// Blume's defaults (`inter`, `ibm-plex-mono`) are fetched from fonts.gstatic.com
|
// Blume's defaults (`inter`, `ibm-plex-mono`) are fetched from fonts.gstatic.com
|
||||||
// on every build, which has timed out on the Pages runner and, fully offline,
|
// on every build, which has timed out on the Pages runner and, fully offline,
|
||||||
// silently ships no fonts at all. The same two families from Fontsource, as
|
// silently ships no fonts at all. The same two families from Fontsource, as
|
||||||
@@ -151,21 +186,23 @@ export default defineConfig({
|
|||||||
sources: [
|
sources: [
|
||||||
filesystem({ root: "content" }),
|
filesystem({ root: "content" }),
|
||||||
custom(
|
custom(
|
||||||
githubReleasesSource(
|
releasesByKind(
|
||||||
{
|
githubReleasesSource(
|
||||||
name: "changelog",
|
{
|
||||||
prefix: "changelog",
|
name: "changelog",
|
||||||
owner: "prdlk",
|
prefix: "changelog",
|
||||||
repo: "leetcode",
|
owner: "prdlk",
|
||||||
fetchImpl: releasesDatedByTag,
|
repo: "leetcode",
|
||||||
},
|
fetchImpl: releasesDatedByTag,
|
||||||
// What resolve.ts hands the built-in adapter: `.blume/cache/<name>/`,
|
},
|
||||||
// and a refresh on every load (the source reads nothing else).
|
// What resolve.ts hands the built-in adapter: `.blume/cache/<name>/`,
|
||||||
{
|
// and a refresh on every load (the source reads nothing else).
|
||||||
projectRoot: import.meta.dirname,
|
{
|
||||||
cacheDir: `${import.meta.dirname}/.blume/cache/changelog`,
|
projectRoot: import.meta.dirname,
|
||||||
mode: "build",
|
cacheDir: `${import.meta.dirname}/.blume/cache/changelog`,
|
||||||
},
|
mode: "build",
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in new issue
Block a user