shishkin/astro-asciidoc

Handle includes in the document frontmatter

Closed this issue · 4 comments

I'd like to do the following:

= Document Title
include::./attributes-settings.adoc[]
include::./attributes-urls.adoc[]

include::./chapter/chapter-1.adoc

There's two problems here:

  1. Document frontmatter isn't loaded
  2. The nested ./chapter/chapter-1.adoc isn't found when rendering the webpage

I've hardcoded the :layout: @layouts/Layout.astro in the chapter-1.adoc file to ensure it knows how to render, though I'd rather get the frontmatter includes to work there too. VSCode is able to preview the .adoc includes properly.

Document frontmatter isn't loaded

It should be part of the asciidoc attribute of the page though.

The nested ./chapter/chapter-1.adoc isn't found when rendering the webpage

This is strange because normal includes work as in the example and are handled completely by AsciiDoctor. Maybe you can try to tweak asciidoc options in the extension config to make it work?

Would you be able to provide a pure AsciiDoctor.js example (without Astro and this extension) that demonstrates support for your use case in vanilla AsciiDoctor?

Here's a repo with a minimal working example without Astro.

I think this'll be more Astro or plugin specific though.

For the first issue it's the Asciidoc frontmatter that isn't being considered somewhere in the processing. Specifically, the expectation is that I should be able to perform an include in the main document frontmatter that holds the attributes-settings.adoc (all of the stuff that should exist across all of my .adoc files) and attributes-urls.adoc (all of the reusable links). If that stuff doesn't load, then the rest of the processing will fail. To be clear, I don't need the Asciidoc frontmatter to be sent to Astro (except for the special layout key), but I'd like that key to be found within attributes-settings.adoc which should be loaded in every .adoc where it is included. And that isn't happening.

For the second problem, this will have to do with Astro most likely. Basically, if I visit localhost:4321/book I'll get the index, but since the includes aren't working properly, they just show up as links. That include link is pointing to ./chapters/chapter-1.adoc which is the URL localhost:4321/chapters/chapter-1.adoc. This is incorrect, as the file is actually at localhost:4321/book/chapters/chapter-1.adoc. This wouldn't be a problem right now if the includes were behaving, but might be when I start pointing at images.

In the meantime, I'm also going to try to reduce the content in the repo I'm working on. Maybe there's something funny I'm doing in there. This is my first time working with Asciidoc afterall.

Welp, I found a solution.

import { defineConfig } from "astro/config";
import asciidoc from "astro-asciidoc";

// https://astro.build/config
export default defineConfig({
  site: "https://books.ds.house",
  integrations: [
    asciidoc({
      options: {
+        safe: "server",
      },
    }),
  ],
});

That makes everything work in my full repo.

Ah yes, default safety setting of asciidoctor forbids includes. I'll close this issue as resolved for now. Feel free to reopen or create a new one if anything is still not working.