Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Å Ä and Ö does not work in directory names #94

Closed
enjikaka opened this issue May 3, 2021 · 8 comments
Closed

Å Ä and Ö does not work in directory names #94

enjikaka opened this issue May 3, 2021 · 8 comments

Comments

@enjikaka
Copy link

enjikaka commented May 3, 2021

I renamed my /posts folder/path to be /inlägg as I wish to have https://example.com/inlägg/bla-bla. Lume rewrites the ä to an a.

@valtlai
Copy link
Contributor

valtlai commented May 3, 2021

You can disable that by setting slugifyUrls: false in your Lume config:

const site = lume({
  slugifyUrls: false,
});

@enjikaka
Copy link
Author

enjikaka commented May 3, 2021

But then I lose the actual slugify logic?

@enjikaka
Copy link
Author

enjikaka commented May 3, 2021

lume/utils.js

Lines 97 to 102 in 22717d5

export function slugify(string) {
return string.toLowerCase()
.normalize("NFKD")
.replaceAll(/[\s_-]+/g, "-")
.replaceAll(/[^\w\/-]/g, (char) => slugChars.get(char) || "");
}

Can a config key to disable just the L101 step be made?

@oscarotero
Copy link
Member

@valtlai Maybe the regex could ignore all characters defined in slugChars map, so users can enable any character with:

import { slugChars } from "https://deno.land/x/lume@v0.18.1/utils.js";

slugChars.set("ä", "ä");

@valtlai
Copy link
Contributor

valtlai commented May 3, 2021

Yeah, that’s one possibility.

And/or maybe the slugifyUrls option could take an object of options to configure the slugifier: slugifyUrls: { nonAscii: true } (maybe there’s a better name?) would preserve non-ASCII letters (and maybe numbers too) in slugs as it.

Or maybe it could take a string: "ascii" (the current default), "unicode" (to preserve non-ASCII letters, and maybe numbers, too) or "off" (to disable the slugifier).

@oscarotero
Copy link
Member

oscarotero commented May 3, 2021

I like the idea of an object with options. For example:

  • separator (By default -)
  • lowercase (By default true)
  • replacements (The object/map with the characters to replace)
  • onlyAlfanumeric (By default true)
  • onlyFilenames (slugify only the last part of the url, not the directories)

oscarotero added a commit that referenced this issue May 4, 2021
@oscarotero
Copy link
Member

I just added options to configure the slugifyUrls. To keep the ä character, use the replace option:

const site = lume({
  slugifyUrls: {
    replace: {
        "ä": "ä"
    }
  },
});

If you want to keep all non-alphanumeric characters:

const site = lume({
  slugifyUrls: {
    alphanumeric: false
  },
});

@enjikaka
Copy link
Author

enjikaka commented May 4, 2021

That should cover my case at least it seems. Thanks. :)

@enjikaka enjikaka closed this as completed May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants