Asciidoc rendering in backend

This commit is contained in:
2022-11-03 14:49:32 +01:00
parent 55d57d6a80
commit 652d84e296
6 changed files with 92 additions and 36 deletions

View 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();
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {