add support from pulling from a Git repo for docs content
Some checks failed
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Failing after 47s
Some checks failed
Deploy / deploy (ubuntu-latest, 2.44.0) (push) Failing after 47s
Took 24 minutes
This commit is contained in:
parent
1614889a62
commit
d364ea83b5
@ -32,6 +32,7 @@
|
||||
"react-dom": "^19.0.0-rc-1460d67c-20241003",
|
||||
"remark-gfm": "^4.0.0",
|
||||
"remote-mdx": "^0.0.8",
|
||||
"simple-git": "^3.27.0",
|
||||
"tailwind-merge": "^2.5.3",
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
|
@ -30,7 +30,7 @@ const DocsPage = async ({
|
||||
);
|
||||
|
||||
// Get the content to display based on the provided slug
|
||||
const pages: DocsContentMetadata[] = getDocsContent();
|
||||
const pages: DocsContentMetadata[] = await getDocsContent();
|
||||
const decodedSlug: string = decodeURIComponent(slug || "");
|
||||
const page: DocsContentMetadata | undefined = pages.find(
|
||||
(metadata: DocsContentMetadata): boolean =>
|
||||
@ -101,7 +101,9 @@ export const generateMetadata = async ({
|
||||
"/"
|
||||
); // The slug of the content
|
||||
if (slug) {
|
||||
const content: DocsContentMetadata | undefined = getDocsContent().find(
|
||||
const content: DocsContentMetadata | undefined = (
|
||||
await getDocsContent()
|
||||
).find(
|
||||
(metadata: DocsContentMetadata): boolean => metadata.slug === slug
|
||||
); // Get the content based on the provided slug
|
||||
if (content) {
|
||||
|
@ -38,12 +38,12 @@ export const viewport: Viewport = {
|
||||
/**
|
||||
* The primary layout for this app.
|
||||
*/
|
||||
const RootLayout = ({
|
||||
const RootLayout = async ({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: ReactNode;
|
||||
}>): ReactElement => {
|
||||
const pages: DocsContentMetadata[] = getDocsContent();
|
||||
}>): Promise<ReactElement> => {
|
||||
const pages: DocsContentMetadata[] = await getDocsContent();
|
||||
return (
|
||||
<html lang="en">
|
||||
<ThemeProvider attribute="class" defaultTheme="dark" enableSystem>
|
||||
|
@ -2,6 +2,8 @@ import * as fs from "node:fs";
|
||||
import { Stats } from "node:fs";
|
||||
import path from "node:path";
|
||||
import config from "@/config";
|
||||
import simpleGit from "simple-git";
|
||||
import os from "node:os";
|
||||
|
||||
/**
|
||||
* The regex to match for metadata.
|
||||
@ -9,20 +11,45 @@ import config from "@/config";
|
||||
const METADATA_REGEX: RegExp = /---\s*([\s\S]*?)\s*---/;
|
||||
|
||||
/**
|
||||
* The directory docs are stored in.
|
||||
* Check if the DOCS_DIR is a Git URL.
|
||||
*/
|
||||
const DOCS_DIR: string = path.join(
|
||||
config.contentSource.replace("{process}", process.cwd())
|
||||
);
|
||||
const isGitUrl = (url: string): boolean => {
|
||||
return /^https?:\/\/|git@|\.git$/.test(url);
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the content to
|
||||
* display in the docs.
|
||||
* The directory docs are stored in.
|
||||
*/
|
||||
export const getDocsContent = (): DocsContentMetadata[] => {
|
||||
const DOCS_DIR: string = isGitUrl(config.contentSource)
|
||||
? config.contentSource
|
||||
: path.join(config.contentSource.replace("{process}", process.cwd()));
|
||||
|
||||
/**
|
||||
* Clone the Git repository if DOCS_DIR is a URL, else use the local directory.
|
||||
* If it's a Git URL, clone it to a cache directory and reuse it.
|
||||
*/
|
||||
const getDocsDirectory = async (): Promise<string> => {
|
||||
if (isGitUrl(DOCS_DIR)) {
|
||||
const repoHash: string = Buffer.from(DOCS_DIR).toString("base64"); // Create a unique identifier based on the repo URL
|
||||
const cacheDir: string = path.join(os.tmpdir(), "docs_cache", repoHash);
|
||||
|
||||
// Pull the latest changes from the repo if we don't have it
|
||||
if (!fs.existsSync(cacheDir) || fs.readdirSync(cacheDir).length < 1) {
|
||||
await simpleGit().clone(DOCS_DIR, cacheDir, { "--depth": 1 });
|
||||
}
|
||||
return cacheDir;
|
||||
}
|
||||
return DOCS_DIR;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the content to display in the docs.
|
||||
*/
|
||||
export const getDocsContent = async (): Promise<DocsContentMetadata[]> => {
|
||||
const docsDir: string = await getDocsDirectory();
|
||||
const content: DocsContentMetadata[] = [];
|
||||
for (const directory of getRecursiveDirectories(DOCS_DIR)) {
|
||||
content.push(...getMetadata<DocsContentMetadata>(DOCS_DIR, directory));
|
||||
for (const directory of getRecursiveDirectories(docsDir)) {
|
||||
content.push(...getMetadata<DocsContentMetadata>(docsDir, directory));
|
||||
}
|
||||
return content.sort((a: DocsContentMetadata, b: DocsContentMetadata) => {
|
||||
const orderA = a.order ?? Number.MAX_SAFE_INTEGER;
|
||||
|
Loading…
x
Reference in New Issue
Block a user