Asciidoc rendering in backend
This commit is contained in:
18
pages/api/contentRendering.ts
Normal file
18
pages/api/contentRendering.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import { generateContent, getContentList } from "../../lib/content/generateBackend";
|
||||
import type { APIReturn } from "../../lib/content/generateBackend";
|
||||
import type { ContentList, Diary, Project } from "../../lib/content/types";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse<string>) {
|
||||
if (!req.query || !req.query.name) return res.status(400).end();
|
||||
|
||||
const list: ContentList = await getContentList();
|
||||
if (!list) return res.status(500).end();
|
||||
|
||||
const content: Project | Diary | undefined = list.find((c) => c.name === req.query.name);
|
||||
if (!content) return res.status(404).end();
|
||||
|
||||
const rendered = await generateContent(content, req.query.page ? parseInt(req.query.page as string) : undefined, true) as APIReturn;
|
||||
res.status(200).json(JSON.stringify(rendered));
|
||||
res.end();
|
||||
}
|
@ -18,7 +18,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
|
||||
if (!contentEntry) return { notFound: true };
|
||||
|
||||
const contentHtml = await generateContent(contentEntry);
|
||||
const contentHtml = await generateContent(contentEntry) as string;
|
||||
const contentPrepared = prepareDOM(contentHtml);
|
||||
|
||||
return {
|
||||
|
@ -18,7 +18,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
|
||||
if (!contentEntry || !page || typeof page !== "string") return { notFound: true };
|
||||
|
||||
const contentHtml = await generateContent(contentEntry, Number.parseInt(page));
|
||||
const contentHtml = await generateContent(contentEntry, Number.parseInt(page)) as string;
|
||||
const contentPrepared = prepareDOM(contentHtml);
|
||||
|
||||
return {
|
||||
|
@ -19,7 +19,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
||||
|
||||
if (!contentEntry) return { notFound: true };
|
||||
|
||||
const contentHtml = await generateContent(contentEntry);
|
||||
const contentHtml = await generateContent(contentEntry) as string;
|
||||
const contentPrepared = prepareDOM(contentHtml);
|
||||
|
||||
return {
|
||||
|
Reference in New Issue
Block a user