feat: update README and package.json for version 0.3.0; add titleFormat option to GemtextConfig
This commit is contained in:
@@ -2,10 +2,15 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
`astro-gemtext` is the Astro integration for [gemtext](https://geminiprotocol.net/)
|
||||||
|
documents. gemtext is a hypertext markup language used in the Gemini protocol. This
|
||||||
|
integration allows you to use `.gmi` files as pages in your Astro site. Just install
|
||||||
|
the integration and `.gmi` files in `/src/pages` will be rendered as HTML.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```
|
```shell
|
||||||
bun add --save astro-gemtext
|
npm install astro-gemtext
|
||||||
```
|
```
|
||||||
|
|
||||||
Add to `astro.config.mjs`
|
Add to `astro.config.mjs`
|
||||||
@@ -18,9 +23,13 @@ export default defineConfig({
|
|||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> [!IMPORTANT]
|
||||||
|
> If you do not provide a layout option, Astro's HMR (Hot Module Reloading) and toolbar
|
||||||
|
> will not work.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Create a `/src/pages/example.gmi` file
|
Create a .gmi file in your project, for example:
|
||||||
|
|
||||||
```gmi
|
```gmi
|
||||||
# Hello World
|
# Hello World
|
||||||
@@ -35,5 +44,16 @@ This is a gemtext file.
|
|||||||
### `layout`
|
### `layout`
|
||||||
|
|
||||||
The layout to use for the page. Set to an absolute import path such as
|
The layout to use for the page. Set to an absolute import path such as
|
||||||
`/src/layouts/Layout.astro`. If you do not use a layout, you will not get HMR, or the
|
`/src/layouts/Layout.astro`.
|
||||||
Astro toolbar.
|
Will be provided the `title` prop.
|
||||||
|
If you do not provide a layout option, Astro's HMR (Hot Module Reloading) and toolbar
|
||||||
|
will not work.
|
||||||
|
|
||||||
|
### `titleFormat`
|
||||||
|
|
||||||
|
The format to use for the page title. Can be one of:
|
||||||
|
|
||||||
|
- `first-heading`: The first heading in the document will be used as the title. (default)
|
||||||
|
- `filename`: The filename of the document will be used as the title.
|
||||||
|
|
||||||
|
The title is passed to the layout as the `title` prop.
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "astro-gemtext",
|
"name": "astro-gemtext",
|
||||||
"homepage": "https://github.com/aspizu/astro-gemtext",
|
"homepage": "https://github.com/aspizu/astro-gemtext",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ 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.
|
||||||
* If not provided, HMR and the Astro toolbar will not work. (default: none) */
|
* If not provided, HMR and the Astro toolbar will not work. (default: none) */
|
||||||
layout?: string
|
layout?: string
|
||||||
|
/** The format to use for the page title. Can be one of:
|
||||||
|
* - `first-heading`: The first heading in the document will be used as the title. (default)
|
||||||
|
* - `filename`: The filename of the document will be used as the title.
|
||||||
|
*/
|
||||||
|
titleFormat?: "first-heading" | "filename"
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetupHookParams = HookParameters<"astro:config:setup"> & {
|
type SetupHookParams = HookParameters<"astro:config:setup"> & {
|
||||||
|
|||||||
+13
-1
@@ -5,6 +5,18 @@ import {ext, 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)
|
||||||
|
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 = pathToFileURL(id).pathname.split("/").pop()
|
||||||
|
}
|
||||||
const html = result.generate(HTMLRenderer)
|
const html = result.generate(HTMLRenderer)
|
||||||
return `
|
return `
|
||||||
import {
|
import {
|
||||||
@@ -28,7 +40,7 @@ export function getHeadings() {
|
|||||||
}
|
}
|
||||||
export async function Content() {
|
export async function Content() {
|
||||||
const content = h(Fragment, {"set:html": html});
|
const content = h(Fragment, {"set:html": html});
|
||||||
${config.layout && `return h(Layout, {title: url, children: content});`}
|
${config.layout && `return h(Layout, {title: ${JSON.stringify(title)}}, content);`}
|
||||||
${!config.layout && `return content;`}
|
${!config.layout && `return content;`}
|
||||||
}
|
}
|
||||||
export default Content;
|
export default Content;
|
||||||
|
|||||||
Reference in New Issue
Block a user