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

set global permalink format #1199

Closed
zebapy opened this issue May 20, 2020 · 2 comments
Closed

set global permalink format #1199

zebapy opened this issue May 20, 2020 · 2 comments

Comments

@zebapy
Copy link

zebapy commented May 20, 2020

Trying to set a global permalink format (mainly to NOT create files as path-to/index.html because I'm trying to use 11ty to create html emails and need the file names.)

I'm trying _data/permalink.js

module.exports = '{{slug}}.html';

to set the global data field for this but it doesn't translate the usual {{slug}}.html and I don't know of any args being passed to JS data files.

This results in

Output conflict: multiple input files are writing to `dist/{{slug}}.html`. Use distinct `permalink` values to resolve this conflict.
  1. ./src/emails/febs.md
  2. ./src/emails/febs copy.md

`DuplicatePermalinkOutputError` was thrown:
    (Repeated output has been truncated…)
        at TemplateMap.checkForDuplicatePermalinks (/Users/zpykosz/Sites/11ty-emails/node_modules/@11ty/eleventy/src/TemplateMap.js:533:13)
        at TemplateMap.cache (/Users/zpykosz/Sites/11ty-emails/node_modules/@11ty/eleventy/src/TemplateMap.js:306:10)
        at async TemplateWriter._createTemplateMap (/Users/zpykosz/Sites/11ty-emails/node_modules/@11ty/eleventy/src/TemplateWriter.js:133:5)
        at async TemplateWriter.write (/Users/zpykosz/Sites/11ty-emails/node_modules/@11ty/eleventy/src/TemplateWriter.js:168:5)
        at async Eleventy.write (/Users/zpykosz/Sites/11ty-emails/node_modules/@11ty/eleventy/src/Eleventy.js:659:13)
Wrote 0 files in 0.11 seconds (v0.10.0)

Setting emails/emails.json doesn't work either.

{
  "permalink": "{{slug}}.html"
}

Same error. It doesn't translate the slug into real file name.

As far as I can tell there's no config setting for globally setting the permalinks either.

What's the ideal config for doing this?

@oliverjam
Copy link

Global data files don't get access to page data like that. Also JS data files don't support templating permalinks in a string (I think) since permalinks use whatever templating engine the file uses (JS doesn't have one: you have to use functions for dynamic permalinks).

The new Computed Data feature allows you to do what you're looking for. You can create a global _data/eleventyComputed.js that will have access to template data. You can then use a JS function to return dynamic permalink:

// _data/eleventyComputed.js

module.exports = {
  permalink: data => data.slug + ".html"
}

@zebapy
Copy link
Author

zebapy commented May 26, 2020

Thanks! That mostly worked. I just needed this for exactly what I wanted (in case others find it useful)

module.exports = {
  permalink: (data) => {
    return data.page.filePathStem + '.html';
  }
};

@zebapy zebapy closed this as completed May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants