grunt-assemble-permalinks icon indicating copy to clipboard operation
grunt-assemble-permalinks copied to clipboard

YFM is "cached" between files

Open manuelbieh opened this issue 7 years ago • 4 comments

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 avatar Apr 05 '17 11:04 manuelbieh

@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.

assemblebot avatar Apr 05 '17 11:04 assemblebot

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.

doowb avatar Apr 05 '17 16:04 doowb

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?

manuelbieh avatar Apr 06 '17 06:04 manuelbieh

Just ran into my issue again. Have you had a look at my testcase already? 😉

manuelbieh avatar Aug 15 '17 14:08 manuelbieh