Skip to content

Commit

Permalink
add index.md demo
Browse files Browse the repository at this point in the history
  • Loading branch information
curly210102 committed Nov 6, 2021
1 parent 31e7499 commit f01f06f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 16 deletions.
16 changes: 0 additions & 16 deletions email/a/template.mjml

This file was deleted.

2 changes: 2 additions & 0 deletions extensions/a/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Hi

README.md
3 changes: 3 additions & 0 deletions extensions/a/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hi

index.md
35 changes: 35 additions & 0 deletions pages/api/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
import { resolve, join } from "path";
import { readFileSync } from "fs";

type Data = {
content: string;
};

type Error = {
error: string;
};

export default function handler(
req: NextApiRequest,
res: NextApiResponse<Data | Error>
) {
if (req.method === "GET") {
const { slugs } = req.query;
const slug = typeof slugs === "string" ? slugs : slugs[0];

const templateDirectory = resolve(process.cwd(), "extensions");
const emailTemplate = readFileSync(
join(templateDirectory, slug, "index.md"),
"utf8"
);
return res.status(200).json({
content: emailTemplate,
});
} else {
return res.status(404).json({
error: "Not Support Method",
});
}
}
3 changes: 3 additions & 0 deletions vercel.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"functions": {
"pages/api/contact.ts": {
"includeFiles": "extensions/**/README.md"
},
"pages/api/info.ts": {
"includeFiles": "extensions/**/index.md"
}
}
}

0 comments on commit f01f06f

Please sign in to comment.