Merge branch 'main' into basic-example-part-2

This commit is contained in:
Luccas Mateus
2023-04-27 15:42:01 -03:00
committed by GitHub
37 changed files with 612 additions and 37 deletions

View File

@@ -0,0 +1,20 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
import { promises as fs } from 'fs';
import path from 'path';
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<string>
) {
const contentDir = path.join(process.cwd(), '/content');
const datasets = await fs.readdir(contentDir);
const query = req.query;
const { fileName } = query;
const dataFile = path.join(
process.cwd(),
'/content/' + datasets[0] + '/' + fileName
);
const data = await fs.readFile(dataFile, 'utf8');
res.status(200).send(data)
}

View File

@@ -4,7 +4,7 @@ import path from 'path';
import parse from '../lib/markdown';
import DRD from '../components/DRD';
export const getServerSideProps = async (context) => {
export const getStaticProps = async (context) => {
const indexFile = path.join(process.cwd(), '/content/index.md');
const readme = await fs.readFile(indexFile, 'utf8');
let { mdxSource, frontMatter } = await parse(readme, '.mdx');