only generate type data once

This commit is contained in:
outfoxxed 2024-10-24 19:40:53 -07:00
parent 8fb1408bb4
commit e0a2fb0256
Signed by: outfoxxed
GPG key ID: 4C88A185FB89301E
6 changed files with 21 additions and 11 deletions

View file

@ -1,12 +1,12 @@
---
import { ThemeSelect } from "@components/hooks/ThemeSwitch";
import { generateTypeData } from "@config/io/generateTypeData";
import { getTypeData } from "@config/io/generateTypeData";
import Nav from "@components/navigation/sidebars/Nav.astro";
import TOC from "@components/navigation/sidebars/TOC.astro";
import type { TypeTOC } from "./navigation/sidebars/types";
import Search from "./navigation/Search.astro";
const routes = await generateTypeData();
const routes = await getTypeData();
const url = Astro.url.pathname.split("/");
const currentClass = url[4];

View file

@ -7,11 +7,11 @@ export interface Props {
const { currentRoute, currentModule, currentClass } = Astro.props;
import { generateTypeData } from "@config/io/generateTypeData";
import { getTypeData } from "@config/io/generateTypeData";
import { groupRoutes } from "@config/io/helpers";
import Tree from "./Tree.astro";
const routes = await generateTypeData();
const routes = await getTypeData();
const groupedRoutes = groupRoutes(routes);
const configuration = {

View file

@ -30,7 +30,7 @@ async function readSubdir(subdir: string): Promise<dirData[]> {
return data;
}
export async function generateTypeData(): Promise<RouteData[]> {
async function generateTypeData(): Promise<RouteData[]> {
const mainDir = import.meta.env.SECRET_MODULES_PATH;
if (!mainDir || mainDir == "") {
@ -56,3 +56,13 @@ export async function generateTypeData(): Promise<RouteData[]> {
}
return routes;
}
let globalTypeData: Promise<RouteData[]>;
export function getTypeData(): Promise<RouteData[]> {
if (!globalTypeData) {
globalTypeData = generateTypeData();
}
return globalTypeData;
}

View file

@ -1,7 +1,7 @@
---
import { getQMLTypeLink } from "@config/io/helpers";
import { processMarkdown } from "@config/io/markdown";
import { generateTypeData } from "@config/io/generateTypeData";
import { getTypeData } from "@config/io/generateTypeData";
import DocsLayout from "@layouts/DocsLayout.astro";
import TOC from "@components/navigation/sidebars/TOC.astro";
import Properties from "@components/type/Properties.astro";
@ -11,7 +11,7 @@ import Variants from "@components/type/Variants.astro";
import Badge from "@components/Badge.astro";
export async function getStaticPaths() {
const routes = await generateTypeData();
const routes = await getTypeData();
return routes
.filter(route => route.name !== "index")

View file

@ -1,10 +1,10 @@
---
import DocsLayout from "@layouts/DocsLayout.astro";
import { generateTypeData } from "@config/io/generateTypeData";
import { getTypeData } from "@config/io/generateTypeData";
import { processMarkdown } from "@src/config/io/markdown";
export async function getStaticPaths() {
const routes = await generateTypeData();
const routes = await getTypeData();
return routes
.filter(route => route.name === "index")

View file

@ -1,8 +1,8 @@
---
import DocsLayout from "@layouts/DocsLayout.astro";
import { generateTypeData } from "@config/io/generateTypeData";
import { getTypeData } from "@config/io/generateTypeData";
const routes = await generateTypeData();
const routes = await getTypeData();
const modules = [...new Set(routes.map(route => route.type))];
---