metalsmith / permalinks

A Metalsmith plugin for permalinks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

permalinks generates unbrowseable urls

oupala opened this issue · comments

Describe the bug
permalinks goal is to generate browseable urls, I've updated the plugin from version 0.5.0 to version 2.1.0 and the plugin is now generating some une browseable urls.

To Reproduce
Steps to reproduce the behaviour:

  1. create some markdown document whose title should be stripped from wrong characters ("user guide (en)", "Cahier d'orientations")
  2. Build the static website
  3. See the generated folder, path are not browseable: user-guide-(en), cahier-d'orientations

Expected behaviour

A browseable path, such as user-guide-en/index.html or cahier-d_orientations/index.html

Environment

  • linux
  • node v10.15.1
  • npm 6.4.1
  • metalsmith 2.3.0
  • metalsmith-permalinks 2.1.0

This new behaviour seems to appear with version 2.0.0, and the use of slugify to fix security issues.

But default options are not working correctly.

The behaviour changed with v2.0.0 with the use of slugify. We're keeping to a vanilla config for slugify as much as possible but it is easily configured to your requirements.

v2.2.0 allows you to configure slugify appropriately. See the second example in slug options which shows the config you're after.

That's a good news and I had seen this possibility of configuring slugify.

But in my opinion, the default configuration of metalsmith-permalinks should generate browseable url by default.

Don't you share this opinion?

Why do you want to keep the slugify config vanilla?

The main drawback is that the plugin does not work out-of-the-box because of the generation a invalid url.

The second drawback is that I am forced to reverse engineer the previous behaviour of the plugin, then to post-configure the new behaviour of the plugin so that my old well known urls don't change while upgrading the plugin.

That's why it would be very very very useful if the default configuration of the new release of the plugin:

  • generate valid url
  • have the same behaviour as the previous release (pre-2.x.x)

@woodyrew Can you please share your opinion about the futur of this issue?

Do you plan to change the default behavior of the plugin to be compatible with the web, and with the previous behavior of this plugin?

Or do you plan to leave it as is and let each user to tweak the configuration?

Thanks.

Maybe I should open a new issue so that you can see it. Tell me if you read that.

In fact, the default configuration of slugify is the following:

slugify('some string', {
  replacement: '-',    // replace spaces with replacement
  remove: null,        // regex to remove characters
  lower: true          // result in lower case
})

And the line just after the default configuration explains how to remove invalid characters:

For example, to remove +~.()'"!:@ from the result slug, you can use slugify('..', {remove: /[+~.()'"!:@]/g}).

So the default configuration used by metalsmith-permalinks should be:

slugify('some string', {
  replacement: '-',         // replace spaces with replacement
  remove: /[*+~.()'"!:@]/g, // regex to remove characters
  lower: true               // result in lower case
})

This restore the previous - and correct - behaviour of metalsmith-permalinks.