-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: use custom slugs for permalinks if set #218
feat: use custom slugs for permalinks if set #218
Conversation
Codecov Report
@@ Coverage Diff @@
## main #218 +/- ##
=======================================
Coverage 98.28% 98.28%
=======================================
Files 13 13
Lines 641 641
=======================================
Hits 630 630
Misses 11 11
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @greatislander for this fix, this fix makes sense; however, we should update the comment in projects.11ty.data about the permalink. With this fix, permalink always get overwritten by output of generatePermaLink util function, even when we don't have to call the function. This fix looks great and we can go with this approach if you think it's better, but I also thought about different approach that's more accurate for what the comment said in projects.11ty.data file, and here's the approach that works:
eleventyComputed: {
langDir: data => data.supportedLanguages[data.locale].dir,
/* Configure navigation */
eleventyNavigation: {
/* Build a permalink using the title and language key if a custom permalink was not supplied. */
...(data => !data.permalink ? {
permalink: data => {
const locale = data.locale;
return generatePermalink(data, "projects", i18n._(locale, "projects"));
}
} : {})
}
@chosww We will definitely update the comment. Your proposed approach gets complex for content editors when working with multiple languages. They need to know to enter the full slug including translated content type and locale slug otherwise it won't match the expected pattern— so if we are allowing a full permalink override then content editors need to know that the French equivalent of |
Thanks for the explanation @greatislander, that makes sense 👍 |
Right now permalinks are ALWAYS generated based on the a slugified version of the title. However, in some instances users may want to specify a different slug, for example to have a page for "Equitable Digital Systems" at
/eds
. This PR modifiesgeneratePermalink
so that it will use aslug
in the front matter data if it exists rather than slugifying the title.