Skip to content

Commit

Permalink
new push strat, new fs strat
Browse files Browse the repository at this point in the history
  • Loading branch information
dredshep committed Apr 25, 2024
1 parent 41e5b3f commit 7928fa7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"remote:add": "git remote add origin https://github.com/AdamantFi/AdamantFiSite.git && git remote add personal https://github.com/dredshep/AdamantFiSite.git",
"push": "git push origin main && git push personal main"
},
"dependencies": {
"@hookform/resolvers": "^3.3.4",
Expand Down
5 changes: 3 additions & 2 deletions pages/docs/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { useEffect } from "react";
import DocumentList from "@/components/doc/DocumentList";
import DocumentDisplay from "@/components/doc/DocumentDisplay";
import { Docs, Doc, getAllDocs, getDocBySlug } from "@/utils/docs/docUtils"; // Ensure these imports are correct
import fs from "fs";
import path from "path";

export async function getStaticProps() {
const docsDirectory = path.join(process.cwd(), "docs");
const docs = getAllDocs(docsDirectory).filter((doc) => doc !== undefined);
const docs = getAllDocs(fs, docsDirectory).filter((doc) => doc !== undefined);
return { props: { docs } };
}

export async function getStaticPaths() {
const docsDirectory = path.join(process.cwd(), "docs");
const docs = getAllDocs(docsDirectory).filter((doc) => doc !== undefined);
const docs = getAllDocs(fs, docsDirectory).filter((doc) => doc !== undefined);
const paths = docs.map((doc) => ({
params: { slug: doc.slug.split("/").filter(Boolean) },
}));
Expand Down
9 changes: 6 additions & 3 deletions utils/docs/docUtils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fs from "fs";
import path from "path";
import matter from "gray-matter";
import { marked } from "marked";
Expand All @@ -12,14 +11,18 @@ export type Doc = {
export type Docs = Doc[];

// Recursively read all markdown files
export function getAllDocs(directory: string, basePath = ""): Docs {
export function getAllDocs(
fs: typeof import("fs"),
directory: string,
basePath = ""
): Docs {
const files = fs.readdirSync(directory);
return files.flatMap((file) => {
const fullPath = path.join(directory, file);
const fileStats = fs.statSync(fullPath);

if (fileStats.isDirectory()) {
return getAllDocs(fullPath, `${basePath}/${file}`);
return getAllDocs(fs, fullPath, `${basePath}/${file}`);
} else {
const content = fs.readFileSync(fullPath, "utf8");
const meta = matter(content);
Expand Down

0 comments on commit 7928fa7

Please sign in to comment.