Skip to content

Asciidoc

This library is called @forastro/asciidoc. It's tool that allows developers to render asciidoc pages in Astro. It's main use is to use the Asciidoc Loader. This library also support's Syntax Highlighting and the Best CSS Generators for styling.

To install this library you must use one of these methods:

Terminal window
pnpm add @forastro/asciidoc

After installing this library make sure you create a content.config.ts file. When you do you should import the loader from @forastro/asciidoc. Then write the config like this.

import { asciidocLoader } from "@forastro/asciidoc"
import {defineCollection, z} from "astro:content"
export const collections = {
blog: defineCollection({
loader: asciidocLoader("content")
schema: z.object({
doctitle: z.string(),
author: z.string()
}).transform(
({ doctitle, ...rest })=> ({ title:doctitle,...rest })
)
})
}

This library also comes with two schemas that are recommended to use. The first one is called the asciidocBaseSchema. The second one is called the asciidocDraftSchema.

To use the asciidocBaseSchema you configure the app like this.

import { asciidocLoader, asciidocBaseSchema } from "@forastro/asciidoc"
import {defineCollection } from "astro:content"
export const collections = {
blog: defineCollection({
loader: asciidocLoader("content")
schema: asciidocBaseSchema
})
}

This Schema makes it so that you write the title author, and description in each page. In return you get these props from each file:

  • title
  • authorInitials
  • firstName
  • middleName
  • lastName
  • createdAt
  • updatedAt