Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
danburzo opened this issue Jan 28, 2023 · 8 comments
Labels
breaking-change This will have to be included with a major version as it breaks backwards compatibility. bug: API design misstep Bugs caused by a bad default feature: 🤟 custom template languages eleventyConfig.addExtension API

Comments

@danburzo
Copy link
Contributor

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
Copy link
Contributor Author

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 zachleat added this to the Eleventy 3.0.0 milestone Feb 7, 2023
@zachleat zachleat added bug: API design misstep Bugs caused by a bad default breaking-change This will have to be included with a major version as it breaks backwards compatibility. and removed needs-triage labels Feb 7, 2023
@zachleat
Copy link
Member

zachleat commented Feb 7, 2023

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 zachleat changed the title When replacing built-in Markdown engine, permalinks in frontmatter are processed as Markdown compileOptions.permalink default changed from true to "raw" Jun 11, 2024
@zachleat zachleat added the feature: 🤟 custom template languages eleventyConfig.addExtension API label Jun 11, 2024
@zachleat zachleat changed the title compileOptions.permalink default changed from true to "raw" compileOptions.permalink default changed from true to "raw" for Custom Template Syntaxes Jun 11, 2024
@zachleat zachleat added the needs-documentation Documentation for this issue/feature is pending! label Jun 11, 2024
@zachleat
Copy link
Member

Shipping with 3.0.0-alpha.13

@zachleat
Copy link
Member

@danburzo
Copy link
Contributor Author

Cool, thanks!

@jnv
Copy link

jnv commented Aug 1, 2024

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 }}"

nhoizey added a commit to nhoizey/eleventy-plugin-pack11ty that referenced this issue Aug 9, 2024
@zachleat
Copy link
Member

No @jnv—this change is limited to Custom template languages that did not have a compileOptions.permalink default already set in plugin code.

zachleat added a commit to 11ty/11ty-website that referenced this issue Sep 26, 2024
@zachleat zachleat removed the needs-documentation Documentation for this issue/feature is pending! label Sep 26, 2024
@jnv
Copy link

jnv commented Sep 28, 2024

@zachleat Thanks for clarification, now I realize it's off topic for this issue since the issue I mentioned affects Nunjucks. I will try to investigate it and open a new issue if I manage to reproduce it with built-in template syntax.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This will have to be included with a major version as it breaks backwards compatibility. bug: API design misstep Bugs caused by a bad default feature: 🤟 custom template languages eleventyConfig.addExtension API
Projects
None yet
Development

No branches or pull requests

3 participants