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

Does not work permalink with interpolation of Pug. #1899

Closed
ksmxxxxxx opened this issue Jul 22, 2021 · 14 comments
Closed

Does not work permalink with interpolation of Pug. #1899

ksmxxxxxx opened this issue Jul 22, 2021 · 14 comments

Comments

@ksmxxxxxx
Copy link

Hi there.

Thanks for develop 11ty.
I’m using very fun.

Describe the bug
I am using Pug. However, the permalinks do not work.
It looks like interpolation is being escaped or recognized as a string.

To Reproduce

I'm write to frontmatter like this.

---
layout: layouts/base
permalink: '| #{page.filePathStem}.html'
dynamicPermalink: false

When I set it up like this, I get the following error

File changed: _sources/_includes/layouts/base.pug
Problem writing Eleventy templates: (more in DEBUG output)
> Output conflict: multiple input files are writing to `_site/| #{page.filePathStem}.html`. Use distinct `permalink` values to resolve this conflict.
  1. ./_sources/blog/postB.md
  2. ./_sources/blog/markdown-sample.md
  3. ./_sources/blog/postA.md
  4. ./_sources/blog/why-did-i-decide-to-create-a-blog.md

`DuplicatePermalinkOutputError` was thrown:
    (Repeated output has been truncated…)
        at TemplateMap.checkForDuplicatePermalinks (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateMap.js:547:13)
        at TemplateMap.cache (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateMap.js:308:10)
        at async TemplateWriter._createTemplateMap (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:170:5)
        at async TemplateWriter.writeTemplates (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:203:5)
        at async TemplateWriter.write (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:254:25)
        at async Eleventy.write (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:743:13)
        at async Eleventy._watch (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:488:5)
        at async Timeout._onTimeout (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:678:11)

I am having trouble deciding if this is a misconfiguration on my part or if it is a problem with the specification.

Expected behavior
I would like it to be written as follows.

_site/blog/why-did-i-decide-to-create-a-blog.html

Environment:

  • OS and Version: [e.g. Windows/Mac/Linux]
    • macOS 10.15.7
  • Eleventy Version [via eleventy --version or npx @11ty/eleventy --version]
    • 0.12.1

My english is not good 😅 , I would be happy to get some advice.

@pdehaan
Copy link
Contributor

pdehaan commented Jul 22, 2021

Sorry, I’ve never used Pug before, but why are you setting the dynamicPermalink: false?

@ksmxxxxxx
Copy link
Author

ksmxxxxxx commented Jul 22, 2021

@pdehaan
Copy link
Contributor

pdehaan commented Jul 22, 2021

I think in this instance you want dynamic permalinks. Try removing that and see if it helps

@ksmxxxxxx
Copy link
Author

Thanks.

I tried remove dynamicpermalinks: false, but does not writing.
I get the following error

File changed: _sources/_includes/layouts/blog.pug
Problem writing Eleventy templates: (more in DEBUG output)
> Output conflict: multiple input files are writing to `_site/<p>| #{page.filePathStem}.html</p>
`. Use distinct `permalink` values to resolve this conflict.
  1. ./_sources/blog/why-did-i-decide-to-create-a-blog.md
  2. ./_sources/blog/postA.md
  3. ./_sources/blog/markdown-sample.md
  4. ./_sources/blog/postB.md

`DuplicatePermalinkOutputError` was thrown:
    (Repeated output has been truncated…)
        at TemplateMap.checkForDuplicatePermalinks (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateMap.js:547:13)
        at TemplateMap.cache (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateMap.js:308:10)
        at async TemplateWriter._createTemplateMap (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:170:5)
        at async TemplateWriter.writeTemplates (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:203:5)
        at async TemplateWriter.write (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/TemplateWriter.js:254:25)
        at async Eleventy.write (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:743:13)
        at async Eleventy._watch (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:488:5)
        at async Timeout._onTimeout (/Users/ksm/dev/github.com/ksmxxxxxx/docs.ksmxxxxxx.page/node_modules/@11ty/eleventy/src/Eleventy.js:678:11)
Wrote 0 files in 0.09 seconds (v0.12.1)

@pdehaan
Copy link
Contributor

pdehaan commented Jul 22, 2021

Do you have a public repo I can try cloning and testing locally?

@ksmxxxxxx
Copy link
Author

Yes, I have already create public repos.
But this code is not push yet.
Please wait a few minutes, I'll tell you my repos after push code.

@ksmxxxxxx
Copy link
Author

@pdehaan

Thank you for waiting.
I have push code to branch of my repos.
It is here.

https://github.com/ksmxxxxxx/docs.ksmxxxxxx.page/tree/try_permalink

@pdehaan
Copy link
Contributor

pdehaan commented Jul 22, 2021

Odd. I just can't figure out how to get this to work.
I did find #286 which has a few pointers, but so far none of them have worked for me with your templates.

@pdehaan
Copy link
Contributor

pdehaan commented Jul 22, 2021

One possible quick workaround is to use a data directory file ./_sources/blog/blog.json which sets the permalink (instead of trying to set the permalink in the pug layout file):

{
  "permalink": "{{ page.filePathStem }}.html"
}

@ksmxxxxxx
Copy link
Author

Thanks :)
I'll try it locally.

@pdehaan
Copy link
Contributor

pdehaan commented Jul 23, 2021

It should work because it’s a directory data file and uses liquidjs templating by default, I believe. There might be a way to change it to use Pug, I haven’t tried that before, so it could be a learning exercise for both of us (if you want to keep everything in Pug).

@ksmxxxxxx
Copy link
Author

Thanks, I get it worked.

However, just changing the data directory file didn't work, so I reviewed the contents of .eleventy.js.
It seems that the problem was caused by the following specification

@@ -30,7 +30,6 @@ module.exports = function (eleventyConfig) {
     dir: {
       input: '_sources',
       data: '_data'
-    },
-    markdownTemplateEngine: 'md'
+    }
   }

@ksmxxxxxx
Copy link
Author

Should I close this issue?

@zachleat
Copy link
Member

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!

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

3 participants