Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions apps/website/app/(home)/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import fs from "fs/promises";
import path from "path";
import { notFound } from "next/navigation";
import { Metadata } from "next";
import { getProcessedMarkdownFile } from "~/utils/getProcessedMarkdownFile";
import { BLOG_PATH } from "~/data/constants";
import { getFileMetadata } from "~/utils/getFileMetadata";
import { BLOG_DIRECTORY } from "~/(home)/blog/blogDirectory";

type Params = {
params: Promise<{
Expand All @@ -17,7 +16,7 @@ const BlogPost = async ({ params }: Params) => {
const { slug } = await params;
const { data, contentHtml } = await getProcessedMarkdownFile({
slug,
directory: BLOG_PATH,
directory: BLOG_DIRECTORY,
});

return (
Expand Down Expand Up @@ -46,9 +45,8 @@ const BlogPost = async ({ params }: Params) => {

export const generateStaticParams = async () => {
try {
const blogPath = path.resolve(process.cwd(), BLOG_PATH);
const directoryExists = await fs
.stat(blogPath)
.stat(BLOG_DIRECTORY)
.then((stats) => stats.isDirectory())
.catch(() => false);

Expand All @@ -59,7 +57,7 @@ export const generateStaticParams = async () => {
return [];
}

const files = await fs.readdir(blogPath);
const files = await fs.readdir(BLOG_DIRECTORY);

const mdFiles = files.filter((filename) => filename.endsWith(".md"));

Expand All @@ -68,7 +66,7 @@ export const generateStaticParams = async () => {
try {
const { published } = await getFileMetadata({
filename,
directory: BLOG_PATH,
directory: BLOG_DIRECTORY,
});
return { filename, published };
} catch (error) {
Expand Down Expand Up @@ -100,7 +98,7 @@ export const generateMetadata = async ({
const { slug } = await params;
const { data } = await getProcessedMarkdownFile({
slug,
directory: BLOG_PATH,
directory: BLOG_DIRECTORY,
});

return {
Expand Down
9 changes: 9 additions & 0 deletions apps/website/app/(home)/blog/blogDirectory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import path from "node:path";
import { fileURLToPath } from "node:url";

const BLOG_MODULE_PATH = fileURLToPath(import.meta.url);

export const BLOG_DIRECTORY = path.join(
path.dirname(BLOG_MODULE_PATH),
"posts",
);
4 changes: 1 addition & 3 deletions apps/website/app/(home)/blog/readBlogs.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import path from "path";
import fs from "fs/promises";
import matter from "gray-matter";
import { BLOG_PATH } from "~/data/constants";
import { PageSchema, type PageData } from "~/types/schema";

const BLOG_DIRECTORY = path.join(process.cwd(), BLOG_PATH);
import { BLOG_DIRECTORY } from "./blogDirectory";

async function validateBlogDirectory(): Promise<boolean> {
try {
Expand Down
1 change: 0 additions & 1 deletion apps/website/app/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const DESCRIPTION =
"Discourse Graphs are a tool and ecosystem for collaborative knowledge synthesis, enabling researchers to map ideas and arguments in a modular, composable graph format.";
export const SHORT_DESCRIPTION =
"A tool and ecosystem for collaborative knowledge synthesis";
export const BLOG_PATH = "app/(home)/blog/posts";

export const TEAM_MEMBERS: TeamMember[] = [
{
Expand Down
Loading