metalsmith / permalinks

A Metalsmith plugin for permalinks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

v2.5.0 broke the `slug` option

emmercm opened this issue · comments

Describe the bug

Permalinks is ignoring a custom function given via the slug option.

To Reproduce

Given this config:

https://github.com/emmercm/www/blob/6d190e3ee94fa142de6b2377e66e5c8ba24bbdde/index.js#L436-L445

there is something going on with this code:

permalinks/src/index.js

Lines 169 to 171 in c7a1436

if (Array.isArray(options.linksets)) {
options.linksets = options.linksets.map(normalizeLinkset)
}

where the linksets end up using the default slugify function and not the provided one.

Expected behaviour

The custom slug function is called.

Screenshots

N/A

Environment

Should be OS and Node.js agnostic, but this appears on macOS and in Ubuntu CI, on Node.js 16.

Additional context

Nothing that I can think of.

Thx for reporting, I will fix this in a patch release ASAP.

@emmercm would you mind testing temporarily with npm i github:metalsmith/permalinks#bugfix/#135 and if you validate I can publish?
The problem with this plugin is that it has a lot of configuration matrices and some edge cases remain untested and it does so many things that it is a pain to maintain.
Its structure is not optimal, so in 3.0 I will make a distinction between "global" options & "linksets" (e.g. I think there is little use in having per-linkset "slug" or "trailingSlash" or "directoryIndex" options . The default linkset will be added to the end of the linksets array and will define a pattern :dirname/:basename (these vars will be made available by permalinks for the pattern option).

@webketje I agree with all of your thoughts there. I don't mind testing at all! But I'm going to be out of town this weekend and may not get a chance until later next week.

@emmercm any news on this?

I didn't realize npm was able to install from GitHub branches like that, that's awesome.

Looks like index.js wasn't committed, though: https://github.com/metalsmith/permalinks/tree/bugfix/%23135/lib

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../www/node_modules/@metalsmith/permalinks/lib/index.js' imported from .../www/index.js

Ah sorry, I forgot there's a build step indeed (which is not versioned). Here's the built version: permalinks-bugfix-351.zip
(yes you can also npm install zips, download the pkg to your site's repo root and run npm install ./permalinks-bugfix-351.zip)

I'm pretty sure that branch did the trick @webketje , it looks to be using my slug function again. Thank you for the fast turnaround!