11ty / eleventy

A simpler site generator. Transforms a directory of templates (of varying types) into HTML.
https://www.11ty.dev/
MIT License
16.91k stars 491 forks source link

`compileOptions.permalink` default changed from `true` to `"raw"` for Custom Template Syntaxes #2780

Closed danburzo closed 3 months ago

danburzo commented 1 year ago

Operating system

macOS Ventura 13.1

Eleventy

^2.0.0-beta.2 / 1.0.2

Describe the bug

Found while poking around replacing the built-in Markdown engine (see #2777) that when setting a replacement with .addExtension('md', { ... }), as exemplified in the docs, any explicit permalinks present in the frontmatter of .md sources will get processed with the replacement engine, as observed a while back (#1019).

This is a problem because most Markdown processors (including marked and remark) will wrap a plain string such as /path/to/output/ in <p> tags, thus breaking the output. I'm not sure if the default engine skips the Markdown step or whether markdown-it simply doesn't wrap a plain string, but the issue only manifests when changing to a different engine.

Reproduction steps

Eleventy config:

const marked = require('marked');
module.exports = config => {
    config.addExtension("md", {
        compile: inputContent => data => marked.parse(inputContent)
    });
};

Content file:

---
title: Hello world
permalink: hello-world/
---

## Heading

Paragraph.

Running Eleventy outputs the HTML to _site / <p>hello-world / < / p>.

Expected behavior

If permalinks passing through the Markdown engine is inevitable, it would be great to get enough arguments to the compile() function for authors to be able to discern when to skip Markdown processing.

Reproduction URL

No response

Screenshots

No response

danburzo commented 1 year ago

The workaround is to use the compileOptions.permalink option, which can be set to "raw" in case all permalinks in the project are static.

For dynamic permalinks, the solution depends on a fix to #2777, as they are not currently pre-processed with Liquid/Nunjucks when the Markdown template engine is swapped.

zachleat commented 1 year ago

I think a very good case can be made to make the default raw and encourage permalink callback functions in custom syntaxes by default!

zachleat commented 3 months ago

Shipping with 3.0.0-alpha.13

zachleat commented 3 months ago

Docs deep link https://www.11ty.dev/docs/languages/custom/#compileoptions.permalink-to-override-permalink-compilation

danburzo commented 2 months ago

Cool, thanks!

jnv commented 1 month ago

I suppose this change disables permalink templating globally, rendering Use template syntax in Permalink and part of front matter documentation obsolete:

Note that only the permalink and eleventyComputed front matter values can contain variables and shortcodes like you would use in the body of your templates.

The fix here is really to put the permalink under eleventyComputed (or switch compileOptions.permalink back to true). In my case, I keep the path of RSS feed in metadata file and reuse it on various part of the site, including the feed's njk template itself. So I put the following into the template's frontmatter:

---
eleventyComputed:
  permalink: "{{ metadata.feed.path }}"