diff --git a/build/markdownPlugin.js b/build/markdownPlugin.js new file mode 100644 index 0000000..3fa79ef --- /dev/null +++ b/build/markdownPlugin.js @@ -0,0 +1,17 @@ +import matter from "gray-matter"; +import { markdownToHtml } from "./markdownToHtml"; +import path from "path"; + +export const markdownPlugin = { + name: "markdown-plugin", + enforce: "pre", + transform(code, id) { + if (id.endsWith(".md")) { + const { data, content } = matter(code); + const filename = path.basename(id, ".md"); + const html = markdownToHtml(filename, content); + const htmlString = JSON.stringify({ html }); + return `export default ${htmlString};`; + } + }, +}; diff --git a/build/markdownToHtml.js b/build/markdownToHtml.js new file mode 100644 index 0000000..5ffd8f5 --- /dev/null +++ b/build/markdownToHtml.js @@ -0,0 +1,39 @@ +import MarkdownIt from "markdown-it"; + +const md = new MarkdownIt({ + html: true, + breaks: true, + linkify: true, +}); + +const mediaSrc = (folderName, fileName) => { + return `/posts/${folderName}/${fileName}`; +}; + +// Customize Markdown-to-HTML mapping here +// md.renderer.rules.paragraph_open = () => '
';
+md.renderer.rules.code_block = (tokens, idx, options, env, self) => {
+ console.log("tokens", tokens);
+ return `${tokens[idx].content}`;
+};
+md.renderer.rules.image = (tokens, idx, options, env, self) => {
+ // console.log('env', env)
+ const token = tokens[idx];
+ const src = token.attrGet("src");
+ const alt = token.content;
+ const postName = env.postName;
+ const formattedSrc = mediaSrc(postName, src);
+
+ if (src.endsWith(".mp4")) {
+ return ``;
+ }
+
+ return ``;
+};
+
+export function markdownToHtml(postName, content) {
+ return md.render(content, { postName: postName });
+}
diff --git a/src/utils/markdownPlugin.ts b/src/utils/markdownPlugin.ts
deleted file mode 100644
index 17d45c1..0000000
--- a/src/utils/markdownPlugin.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { Plugin } from 'vite'
-import matter from 'gray-matter';
-import { markdownToHtml } from './markdownToHtml';
-import path from 'path';
-
-export const markdownPlugin: Plugin = {
- name: 'markdown-plugin',
- enforce: 'pre',
- transform(code, id) {
- if (id.endsWith('.md')) {
- const { data, content } = matter(code);
- const filename = path.basename(id, '.md');
- const html = markdownToHtml(filename, content);
- const htmlString = JSON.stringify({ html });
- return `export default ${htmlString};`;
- }
- },
-};
\ No newline at end of file
diff --git a/src/utils/markdownToHtml.ts b/src/utils/markdownToHtml.ts
deleted file mode 100644
index 6396d85..0000000
--- a/src/utils/markdownToHtml.ts
+++ /dev/null
@@ -1,40 +0,0 @@
-import MarkdownIt from 'markdown-it';
-
-const md = new MarkdownIt({
- html: true,
- breaks: true,
- linkify: true,
-});
-
-const mediaSrc = (folderName: string, fileName: string) => {
- return `/posts/${folderName}/${fileName}`
-}
-
-// Customize Markdown-to-HTML mapping here
-// md.renderer.rules.paragraph_open = () => '
';
-md.renderer.rules.code_block = (tokens, idx, options, env, self) => {
- console.log('tokens', tokens)
- return `${tokens[idx].content}`;
-}
-md.renderer.rules.image = (tokens, idx, options, env, self) => {
- // console.log('env', env)
- const token = tokens[idx];
- const src = token.attrGet('src');
- const alt = token.content
- const postName = env.postName
- const formattedSrc = mediaSrc(postName, src)
-
- if (src.endsWith('.mp4')) {
- return ``;
- }
-
- return ``;
-
-};
-
-export function markdownToHtml(postName: string, content: string): string {
- return md.render(content, { postName: postName });
-}
\ No newline at end of file
diff --git a/tsconfig.node.json b/tsconfig.node.json
index bf67dd4..eca6668 100644
--- a/tsconfig.node.json
+++ b/tsconfig.node.json
@@ -6,5 +6,5 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
- "include": ["vite.config.ts", "src/utils/*"]
+ "include": ["vite.config.ts"]
}
diff --git a/vite.config.ts b/vite.config.ts
index 4f297d4..16e1695 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,4 +1,4 @@
-import { markdownPlugin } from './src/utils/markdownPlugin';
+import { markdownPlugin } from './build/markdownPlugin';
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import wasm from "vite-plugin-wasm";