guide page versioning
This commit is contained in:
parent
d23bfbfd00
commit
e7c807ac85
12 changed files with 54 additions and 10 deletions
|
@ -6,10 +6,10 @@ export interface Props {
|
||||||
}
|
}
|
||||||
|
|
||||||
import { getVersionsData } from "@config/io/generateTypeData";
|
import { getVersionsData } from "@config/io/generateTypeData";
|
||||||
|
import { getGuideCollection } from "@config/io/guides";
|
||||||
import type { TreeEntry } from "./Tree.astro";
|
import type { TreeEntry } from "./Tree.astro";
|
||||||
import Tree from "./Tree.astro";
|
import Tree from "./Tree.astro";
|
||||||
import Link from "./Link.astro";
|
import Link from "./Link.astro";
|
||||||
import { getCollection } from "astro:content";
|
|
||||||
|
|
||||||
const versions = await getVersionsData();
|
const versions = await getVersionsData();
|
||||||
const versionName = Astro.params.version;
|
const versionName = Astro.params.version;
|
||||||
|
@ -17,7 +17,7 @@ const modules = versions.versions.find(version => version.name === versionName)?
|
||||||
|
|
||||||
const currentPath = Astro.url.pathname.split('/').filter(s => s !== "");
|
const currentPath = Astro.url.pathname.split('/').filter(s => s !== "");
|
||||||
|
|
||||||
const guidePages = await getCollection("guide");
|
const guidePages = await getGuideCollection(versionName ?? "");
|
||||||
|
|
||||||
interface NavTree {
|
interface NavTree {
|
||||||
title: string,
|
title: string,
|
||||||
|
|
35
src/config/io/guides.ts
Normal file
35
src/config/io/guides.ts
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
import { type CollectionEntry, getCollection } from "astro:content";
|
||||||
|
import { getVersionsData } from "@config/io/generateTypeData";
|
||||||
|
|
||||||
|
// load latest version of each page for version
|
||||||
|
async function buildGuideCollection(version: string): Promise<CollectionEntry<'guide'>[]> {
|
||||||
|
const { versions } = await getVersionsData();
|
||||||
|
const guidePages = await getCollection("guide");
|
||||||
|
|
||||||
|
const pages: { [key: string]: CollectionEntry<'guide'> } = {};
|
||||||
|
|
||||||
|
for (const currentVersion of versions.toReversed()) {
|
||||||
|
for (const page of guidePages) {
|
||||||
|
let [guideVersion, id] = page.id.split('/');
|
||||||
|
guideVersion = guideVersion.replaceAll('_', '.');
|
||||||
|
id = id ?? "index";
|
||||||
|
if (guideVersion !== currentVersion.name) continue;
|
||||||
|
|
||||||
|
pages[id] = { ...page, id };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentVersion.name === version) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Object.values(pages);
|
||||||
|
}
|
||||||
|
|
||||||
|
let guideCollections: { [key: string]: Promise<CollectionEntry<'guide'>[]> } = {};
|
||||||
|
|
||||||
|
export async function getGuideCollection(version: string): Promise<CollectionEntry<'guide'>[]> {
|
||||||
|
if (!(version in guideCollections)) {
|
||||||
|
guideCollections[version] = buildGuideCollection(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
return guideCollections[version];
|
||||||
|
}
|
|
@ -2,7 +2,7 @@ import { defineCollection, z } from "astro:content";
|
||||||
import { glob } from "astro/loaders";
|
import { glob } from "astro/loaders";
|
||||||
|
|
||||||
const guide = defineCollection({
|
const guide = defineCollection({
|
||||||
loader: glob({ pattern: "**/*", base: "src/guide" }),
|
loader: glob({ pattern: "**/*.md", base: "src/guide" }),
|
||||||
schema: z.object({
|
schema: z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
index: z.number(),
|
index: z.number(),
|
||||||
|
|
4
src/guide/v0_1_0/lists-models.mdx
Normal file
4
src/guide/v0_1_0/lists-models.mdx
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
title: "Lists and Models"
|
||||||
|
index: 2
|
||||||
|
---
|
|
@ -1,19 +1,24 @@
|
||||||
---
|
---
|
||||||
import GuideLayout from "@layouts/GuideLayout.astro";
|
import GuideLayout from "@layouts/GuideLayout.astro";
|
||||||
import { getVersionsData } from "@config/io/generateTypeData";
|
import { getVersionsData } from "@config/io/generateTypeData";
|
||||||
|
import { getGuideCollection } from "@config/io/guides";
|
||||||
import { processMarkdown } from "@config/io/markdown";
|
import { processMarkdown } from "@config/io/markdown";
|
||||||
|
|
||||||
import { getCollection, render } from "astro:content";
|
import { render } from "astro:content";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const { versions } = await getVersionsData();
|
const { versions } = await getVersionsData();
|
||||||
const guidePages = await getCollection("guide");
|
|
||||||
|
|
||||||
// versioned guides unhandled for now
|
let pages = await Promise.all(versions.map(async version => {
|
||||||
return versions.flatMap(version => guidePages.map(page => ({
|
const pages = await getGuideCollection(version.name);
|
||||||
params: { version: version.name, id: page.id == "index" ? "/" : page.id },
|
|
||||||
props: { version, page },
|
return pages.map(page => ({
|
||||||
})));
|
params: { version: version.name, id: page.id === "index" ? "/" : page.id },
|
||||||
|
props: { version, page },
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
|
||||||
|
return pages.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { version, page } = Astro.props;
|
const { version, page } = Astro.props;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue