grunt-assemble-permalinks
grunt-assemble-permalinks copied to clipboard
YFM is "cached" between files
Hey,
I was trying to use replacements to make it possible to optionally define alternative filenames just for certain pages or otherwise fallback to basename. This is my config:
permalinks: {
structure: ':file.html',
replacements: [{
pattern: ':file',
replacement: function() {
console.log(this.file);
return this.file || this.basename;
}
}]
}
Now I got the problem that subsequent files which are not explicitly specifying a file
property in frontmatter this.file
is still set to the value of the last file.
a.hbs: no yfm
b.hbs: sets file
to z
in yfm
c.hbs: no yfm
d.hbs: no yfm
e.hbs: sets file
to y
in yfm
results in:
- a.html
- y.html
- z.html
z.html contains the content from d.hbs as it instantly overwrites b.hbs and c.hbs. e.hbs has its own file
prop so it gets correctly written to y.html.
Anything I can do about that? Any workarounds or alternatives?
Assemble version: 0.23.0 Grunt-Assemble-Permalinks version: 0.1.1
@manuelbieh Thanks for the issue! If you're reporting a bug, please be sure to include:
- The version of
assemble
you are using. - Your assemblefile.js (This can be in a gist)
- The commandline output. (Screenshot or gist is fine)
- What you expected to happen instead.
This looks like a bug in an old dependency.
I'm curious to see how you're using grunt-assemble-permalinks
with the latest version of assemble
. This should only work with grunt-assemble
.
In either case, will you make a repository with the minimum amount of configuration that demonstrates the bug? It probably just needs to be those 5 files listed above with the gruntfile or assemblefile and a package.json with the necessary dependencies. This will help us debug quicker.
Ah, sorry, I had assemble and grunt-assemble installed and I'm using grunt-assemble to assemble my files. Sorry for that!
Here is a testcase: https://github.com/manuelbieh/assemble-permalinks-testcase
What I was actually trying to do was to get localized filenames for different languages, using a (translated) metadata json similar to here: http://assemble.io/docs/YAML-front-matter.html#metadata-conduit-
(<%= page.about.file %>
in my example) and a custom permalinks pattern.
I don't know if there's an easier way to do that. However, it doesnt work due to the problem I described initially.
Plus: I have another problem: if I use <%= page.about.file %> in YFM, I get another error:
Warning: Unable to write "dist/de/<%= page.about.file %>.html" file (Error code: ENOENT).
Which is probably because permalinks receives the unparsed YFM data, right?
Just ran into my issue again. Have you had a look at my testcase already? 😉