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

feat: use custom slugs for permalinks if set #218

Merged

Conversation

greatislander
Copy link
Contributor

@greatislander greatislander commented Sep 27, 2023

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 modifies generatePermalink so that it will use a slug in the front matter data if it exists rather than slugifying the title.

@codecov
Copy link

codecov bot commented Sep 27, 2023

Codecov Report

Merging #218 (26034b6) into main (d4f5592) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #218   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files          13       13           
  Lines         641      641           
=======================================
  Hits          630      630           
  Misses         11       11           
Files Coverage Δ
src/utils/generate-permalink.js 100.00% <100.00%> (ø)

Copy link

@chosww chosww left a 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"));
            }
        } : {})
    }

@greatislander
Copy link
Contributor Author

@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 /projects/equitable-digital-systems is /fr/projets/systemes-numeriques-equitables/, not just /projects/systemes-numeriques-equitables. That leaves lots of potential for user error. The part that people need to customize is the title of the content so I think this solution is simplest.

@chosww
Copy link

chosww commented Sep 27, 2023

Thanks for the explanation @greatislander, that makes sense 👍

@greatislander greatislander merged commit e28b6f2 into fluid-project:main Oct 4, 2023
5 checks passed
@greatislander greatislander deleted the feat/check-for-custom-slug branch October 4, 2023 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants