mirror of
https://github.com/hsjobeki/noogle.git
synced 2024-12-24 14:32:15 +03:00
Make computed data available via a JSON API endpoint
Render a static JSON response at /api/v1/data that returns the exports of @/models/data, namely, { "data": contents of data.json, "builtinTypes": contents of builtins.types.json, "upstreamInfo": contents of meta.json, }. The reason to return this all in a single response is so that clients can atomically get an upstreamInfo that matches data. This can be used by tools that wish to work with the same data as Noogle programmatically, without needing to rerun the build process locally.
This commit is contained in:
parent
6e910a5040
commit
eefe66edf5
5
website/src/app/api/v1/data/route.ts
Normal file
5
website/src/app/api/v1/data/route.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { data, builtinTypes, upstreamInfo } from "@/models/data";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
return Response.json({ data, builtinTypes, upstreamInfo });
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import { HighlightBaseline } from "@/components/HighlightBaseline";
|
||||
import { ShareButton } from "@/components/ShareButton";
|
||||
import { BackButton } from "@/components/BackButton";
|
||||
import { Doc, data, manualLinks } from "@/models/data";
|
||||
import { Doc, data, manualLinks, upstreamInfo } from "@/models/data";
|
||||
import { getPrimopDescription } from "@/models/primop";
|
||||
import { extractExcerpt, extractHeadings, parseMd } from "@/utils";
|
||||
import { Box, Divider, Typography, Link, Chip } from "@mui/material";
|
||||
@ -11,7 +11,6 @@ import React, { Suspense } from "react";
|
||||
import { PositionLink } from "@/components/PositionLink";
|
||||
import { SearchNav } from "@/components/SearchNav";
|
||||
|
||||
import upstreamInfo from "@/models/data/meta.json" assert { type: "json" };
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { Metadata, ResolvingMetadata } from "next";
|
||||
|
@ -1,6 +1,7 @@
|
||||
import all from "./data.json" assert { type: "json" };
|
||||
import types from "./builtins.types.json" assert { type: "json" };
|
||||
import links from "./manual-link.map.json" assert { type: "json" };
|
||||
import meta from "./meta.json" assert { type: "json" };
|
||||
|
||||
export type ManualLink = {
|
||||
id: string;
|
||||
@ -63,3 +64,10 @@ export type BuiltinTypes = {
|
||||
};
|
||||
|
||||
export const builtinTypes = types as BuiltinTypes;
|
||||
|
||||
export type UpstreamInfo = {
|
||||
rev: string;
|
||||
lastModified: number;
|
||||
}
|
||||
|
||||
export const upstreamInfo = meta as UpstreamInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user