assemble / grunt-assemble-permalinks

Permalinks middleware for Assemble, the static site generator for Grunt.js and Yeoman. This plugin enables powerful and configurable URI replacement patterns, presets, uses Moment.js for parsing dates, and much more.
MIT License
43 stars 11 forks source link

YFM is "cached" between files #69

Open manuelbieh opened 7 years ago

manuelbieh commented 7 years ago

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:

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

assemblebot commented 7 years ago

@manuelbieh Thanks for the issue! If you're reporting a bug, please be sure to include:

doowb commented 7 years ago

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.

manuelbieh commented 7 years ago

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 commented 7 years ago

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