Skip to content

Commit

Permalink
Nextjs config issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ujaandas committed Apr 2, 2024
1 parent fc6fb9f commit 45f87f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"search.useIgnoreFiles": true
}
5 changes: 4 additions & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import withMDX from "@next/mdx";

const isProd = process.env.NODE_ENV === "production";

/** @type {import('next').NextConfig} */
const config = withMDX()({
assetPrefix: isProd ? "./" : undefined,
pageExtensions: ["ts", "js", "tsx", "jsx", "md", "mdx"],
images: {
domains: ["picsum.photos"],
},
output: "export",
basePath: "/ujaandas.github.io",
// basePath: "/ujaandas.github.io",
images: {
unoptimized: true,
},
Expand Down
13 changes: 8 additions & 5 deletions src/app/lib/data.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { promises as fs } from "fs";
import { MDXRemote } from "next-mdx-remote/rsc";
import path from "path";

const readFile = async (path: string) => {
const post = await fs.readFile(path, "utf-8");
return <MDXRemote source={post} />;
};

const basePath = path.join(process.cwd(), "public/data/posts");

const readBasePath = async () => {
const dirs = await fs.readdir("../../public/data/posts");
const posts = await fs.readdir(basePath);
const categories = await Promise.all(
dirs.map(async (category) => {
const files = await fs.readdir(`../../public/data/posts/${category}`);
posts.map(async (category) => {
const files = await fs.readdir(`${basePath}/${category}`);
return { category, files };
})
);
Expand All @@ -25,7 +28,7 @@ export const fetchPosts = async () => {
const posts = await Promise.all(
category.files.map(async (file) => {
const post = await readFile(
`../../public/data/posts/${category.category}/${file}`
`${basePath}/${category.category}/${file}`
);
return post;
})
Expand Down Expand Up @@ -56,7 +59,7 @@ export const fetchSlugs = async () => {
const posts = await Promise.all(
category.files.map(async (file) => {
const post = await fs.readFile(
`../../public/data/posts/${category.category}/${file}`,
`${basePath}/${category.category}/${file}`,
"utf-8"
);
return post;
Expand Down
2 changes: 1 addition & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AboutMe from "@/components/Sidebar";
import SectionSelector from "@/components/SectionSelector";
import { fetchPosts, fetchSlugs } from "./lib/data";
import { fetchPosts } from "./lib/data";

export default async function Home() {
const postData = await fetchPosts();
Expand Down

0 comments on commit 45f87f0

Please sign in to comment.