-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4464c6a
commit 5b63610
Showing
10 changed files
with
174 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Plugin } from "../src/lib/types.ts"; | ||
|
||
const plugin: Plugin = () => { | ||
return { | ||
header: { | ||
left: <a href="/demo.png">Demo</a>, | ||
right: <a href="/" class="hover:bg-red-500">Home</a>, | ||
}, | ||
routes: ["/demo.png"], | ||
handle: async () => { | ||
const req = await fetch( | ||
"https://github.com/lino-levan/pyro/raw/main/www/static/icon.png", | ||
); | ||
return req; | ||
}, | ||
}; | ||
}; | ||
|
||
export default plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import { extract } from "std/encoding/front_matter/any.ts"; | |
import { renderToString } from "preact-render-to-string"; | ||
import { page } from "./page.tsx"; | ||
import { get_route_map, resolve_file } from "./route_map.ts"; | ||
import type { Config, Magic } from "./types.ts"; | ||
import type { Config, Magic, PluginResult } from "./types.ts"; | ||
|
||
import { | ||
consume, | ||
|
@@ -13,6 +13,7 @@ import { | |
tw, | ||
} from "https://esm.sh/@twind/[email protected]"; | ||
import presetTailwind from "https://esm.sh/@twind/[email protected]"; | ||
import { getHeaderElements } from "../utils.ts"; | ||
|
||
install(defineConfig({ | ||
presets: [presetTailwind()], | ||
|
@@ -22,6 +23,7 @@ export async function render( | |
config: Config, | ||
magic: Magic, | ||
path: string, | ||
plugins: PluginResult[], | ||
dev = false, | ||
) { | ||
const [file_type, markdown] = resolve_file(resolve("pages", path)); | ||
|
@@ -43,6 +45,7 @@ export async function render( | |
magic, | ||
file_type, | ||
dev, | ||
header: getHeaderElements(plugins), | ||
}, | ||
}), | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import remarkGfm from "https://esm.sh/[email protected]"; | |
import rehypeHighlight from "https://esm.sh/@mapbox/[email protected]"; | ||
import { compile } from "https://esm.sh/@mdx-js/[email protected]"; | ||
import { render } from "gfm"; | ||
import type { FileTypes } from "./lib/types.ts"; | ||
import type { FileTypes, JSX, Plugin, PluginResult } from "./lib/types.ts"; | ||
|
||
import "https://esm.sh/[email protected]/components/prism-json?no-check"; | ||
import "https://esm.sh/[email protected]/components/prism-bash?no-check"; | ||
|
@@ -49,3 +49,28 @@ export async function renderMD(data: string) { | |
disableHtmlSanitization: true, | ||
}); | ||
} | ||
|
||
export function loadPlugins(plugins: string[]) { | ||
return Promise.all( | ||
plugins.map(async (plugin) => ((await import(plugin)).default as Plugin)()), | ||
); | ||
} | ||
|
||
export function getHeaderElements(plugins: PluginResult[]) { | ||
const header = { | ||
left: [] as JSX.Element[], | ||
right: [] as JSX.Element[], | ||
}; | ||
|
||
for (const plugin of plugins) { | ||
if (!plugin.header) continue; | ||
if (plugin.header.left) { | ||
header.left = [...header.left, plugin.header.left]; | ||
} | ||
if (plugin.header.right) { | ||
header.right = [...header.right, plugin.header.right]; | ||
} | ||
} | ||
|
||
return header; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Plugins | ||
description: Pyro was designed from the ground up to be no-config and incredibly fast. | ||
index: 3 | ||
--- | ||
|
||
While Pyro is designed to have all of the basic features you will need built-in, | ||
there are some cases where one would want to extend the feature set. This can be | ||
achieved with plugins. | ||
|
||
A simple plugin will look like so: | ||
|
||
```tsx | ||
import { Plugin } from "https://deno.land/x/pyro/src/lib/types.ts"; | ||
|
||
const plugin: Plugin = () => { | ||
return { | ||
header: { | ||
left: <a href="/demo.png">Demo</a>, | ||
right: <a href="/" class="hover:bg-red-500">Home</a>, | ||
}, | ||
routes: ["/demo.png"], | ||
handle: async () => { | ||
const req = await fetch( | ||
"https://github.com/lino-levan/pyro/raw/main/www/static/icon.png", | ||
); | ||
return req; | ||
}, | ||
}; | ||
}; | ||
|
||
export default plugin; | ||
``` | ||
|
||
More examples can be found in | ||
[the official plugins](https://github.com/lino-levan/pyro/tree/main/plugins). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters