feat: add project and email service
This commit is contained in:
parent
99715f6105
commit
f48390b15e
29 changed files with 2631 additions and 63 deletions
32
vite-plugin-markdown.ts
Normal file
32
vite-plugin-markdown.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import matter from "gray-matter";
|
||||
import { marked } from "marked";
|
||||
import type { Plugin } from "vite";
|
||||
|
||||
export default function markdownPlugin(): Plugin {
|
||||
const virtualModuleId = "virtual:projects";
|
||||
const resolvedId = "\0" + virtualModuleId;
|
||||
const projectsDir = path.resolve("src/content/projects");
|
||||
|
||||
return {
|
||||
name: "vite-plugin-markdown",
|
||||
resolveId(id) {
|
||||
if (id === virtualModuleId) return resolvedId;
|
||||
},
|
||||
load(id) {
|
||||
if (id !== resolvedId) return;
|
||||
|
||||
const files = fs.readdirSync(projectsDir).filter((f) => f.endsWith(".md"));
|
||||
const projects = files.map((file) => {
|
||||
const raw = fs.readFileSync(path.join(projectsDir, file), "utf-8");
|
||||
const { data, content } = matter(raw);
|
||||
const html = marked(content);
|
||||
const slug = file.replace(".md", "");
|
||||
return { slug, ...data, html };
|
||||
});
|
||||
|
||||
return `export default ${JSON.stringify(projects)};`;
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue