inlines .gmi
This commit is contained in:
+2
-4
@@ -3,8 +3,6 @@ import {fileURLToPath} from "url"
|
|||||||
import gemtextVitePlugin from "./vitePlugin.js"
|
import gemtextVitePlugin from "./vitePlugin.js"
|
||||||
import { parse as parseYaml } from "yaml";
|
import { parse as parseYaml } from "yaml";
|
||||||
|
|
||||||
export const ext = "gmi"
|
|
||||||
|
|
||||||
/** Gemtext configuration options */
|
/** Gemtext configuration options */
|
||||||
export interface GemtextConfig {
|
export interface GemtextConfig {
|
||||||
/** Absolute import path to the layout to use for all gemtext pages.
|
/** Absolute import path to the layout to use for all gemtext pages.
|
||||||
@@ -39,9 +37,9 @@ export default function gemtext(config: GemtextConfig = {}): AstroIntegration {
|
|||||||
new URL("./renderer.js", import.meta.url),
|
new URL("./renderer.js", import.meta.url),
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
params.addPageExtension(ext)
|
params.addPageExtension('.gmi')
|
||||||
params.addContentEntryType({
|
params.addContentEntryType({
|
||||||
extensions: [`.${ext}`],
|
extensions: ['.gmi'],
|
||||||
getEntryInfo: async ({ fileUrl, contents }) => {
|
getEntryInfo: async ({ fileUrl, contents }) => {
|
||||||
const lines = contents.split('\n');
|
const lines = contents.split('\n');
|
||||||
let data: Record<string, unknown> = {};
|
let data: Record<string, unknown> = {};
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@ import {HTMLRenderer, parse} from "gemtext"
|
|||||||
import path from "path"
|
import path from "path"
|
||||||
import {pathToFileURL} from "url"
|
import {pathToFileURL} from "url"
|
||||||
import type {Plugin} from "vite"
|
import type {Plugin} from "vite"
|
||||||
import {ext, type GemtextConfig} from "./index.js"
|
import {type GemtextConfig} from "./index.js"
|
||||||
|
|
||||||
function transform(code: string, id: string, config: GemtextConfig) {
|
function transform(code: string, id: string, config: GemtextConfig) {
|
||||||
const result = parse(code)
|
const result = parse(code)
|
||||||
@@ -54,7 +54,7 @@ export default function gemtextVitePlugin(config: GemtextConfig): Plugin {
|
|||||||
name: "astro-gemtext",
|
name: "astro-gemtext",
|
||||||
enforce: "pre",
|
enforce: "pre",
|
||||||
transform(code, id) {
|
transform(code, id) {
|
||||||
if (!id.endsWith(`.${ext}`)) return
|
if (!id.endsWith('.gmi')) return
|
||||||
return {
|
return {
|
||||||
code: transform(code, id, config),
|
code: transform(code, id, config),
|
||||||
map: null,
|
map: null,
|
||||||
|
|||||||
Reference in New Issue
Block a user