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(slugs): allow filters in template strings #6690

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stormwarning
Copy link

@stormwarning stormwarning commented Feb 10, 2023

Process template filters first, then strip ' and . characters from slug strings.

Fixes #4783

Summary

Provides greater control over field values used in entry slug strings.

Test plan

Added a new formatters test which failed under the existing setup. Updated compileStringTemplate() function such that new test and all existing tests pass.

Checklist

  • I have read the contribution guidelines.
  • Code is formatted via running yarn format.
  • Tests are passing via running yarn test.
  • The status checks are successful (continuous integration). Those can be seen below.

image

@stormwarning stormwarning requested a review from a team February 10, 2023 04:27
Comment on lines +193 to +199
const filterFunction = getFilterFunction(filter);
if (filterFunction) {
replacement = filterFunction(replacement);
}

if (processor) {
return processor(replacement);
} else {
const filterFunction = getFilterFunction(filter);
if (filterFunction) {
replacement = filterFunction(replacement);
}
replacement = processor(replacement);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of the the early return if the processor arg is passed in, check for filters first and apply them.

Moved the processor call after filters since it looks like that is used to make the slugs safer for URL/filenames.

@stormwarning
Copy link
Author

Also happy to update the docs if the rest of the code looks good 👍

@netlify
Copy link

netlify bot commented Mar 8, 2023

Deploy Preview for decap-www canceled.

Name Link
🔨 Latest commit 2645e07
🔍 Latest deploy log https://app.netlify.com/sites/decap-www/deploys/648a76a5465c0e000830810b

@jenniferbhampton
Copy link

Could really use this feature, hopefully it gets approved and merged!

Process template filters first, then strip `'` and `.` characters from
slug strings.

Fixes decaporg#4783
@nhoizey
Copy link

nhoizey commented Mar 16, 2024

If this allows use setting for example our own slug filter, it would be awesome.

For example:

slug: {{title | my_own_slugify}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter date for a field entry to use in the slug
4 participants