summaryrefslogtreecommitdiff
path: root/src/vitePlugin.ts
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-03-21 22:20:38 +0000
committerJoe Carstairs <me@joeac.net>2026-03-21 22:20:38 +0000
commit1248542cc6b509a1b070ed5812ca5c327823a018 (patch)
tree8c1343046f3bf63f25f74a96e845ae900dff11d8 /src/vitePlugin.ts
parent237990619e1f5a4ea9223f603d1ce599bc3b0fd1 (diff)
remove cruft: just a content entry type now!
Diffstat (limited to 'src/vitePlugin.ts')
-rw-r--r--src/vitePlugin.ts64
1 files changed, 0 insertions, 64 deletions
diff --git a/src/vitePlugin.ts b/src/vitePlugin.ts
deleted file mode 100644
index 4546a95..0000000
--- a/src/vitePlugin.ts
+++ /dev/null
@@ -1,64 +0,0 @@
-import {HTMLRenderer, parse} from "gemtext"
-import path from "path"
-import {pathToFileURL} from "url"
-import type {Plugin} from "vite"
-import {type GemtextConfig} from "./index.js"
-
-function transform(code: string, id: string, config: GemtextConfig) {
- const result = parse(code)
- let title
-
- if (config.titleFormat === "first-heading") {
- for (const node of result.data) {
- if (node._ === 4) {
- title = node.text
- break
- }
- }
- } else if (config.titleFormat === "filename") {
- title = path.basename(id)
- }
- const html = result.generate(HTMLRenderer)
- return `
-import {
- createComponent,
- render,
- renderComponent,
- unescapeHTML,
-} from "astro/runtime/server/index.js";
-import { Fragment, jsx as h } from "astro/jsx-runtime";
-${config.layout ? `import Layout from ${JSON.stringify(config.layout)};` : ""}
-export const name = "TypstComponent";
-export const html = ${JSON.stringify(html)};
-export const frontmatter = undefined;
-export const file = ${JSON.stringify(id)};
-export const url = ${JSON.stringify(pathToFileURL(id))};
-export function compiledContent() {
- return html;
-}
-export function getHeadings() {
- return undefined;
-}
-export async function Content() {
- const content = h(Fragment, {"set:html": html});
- ${config.layout ? `return h(Layout, {title: ${JSON.stringify(title)}, children: content});` : ""}
- ${!config.layout ? `return content;` : ""}
-}
-export default Content;
-`
-}
-
-export default function gemtextVitePlugin(config: GemtextConfig): Plugin {
- // let server: ViteDevServer
- return {
- name: "astro-gemtext",
- enforce: "pre",
- transform(code, id) {
- if (!id.endsWith(".gmi")) return
- return {
- code: transform(code, id, config),
- map: null,
- }
- },
- }
-}