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

fix: Error creating permalinks with :date #144

Merged
merged 3 commits into from
Nov 6, 2024

Conversation

vctrtvfrrr
Copy link
Contributor

@vctrtvfrrr vctrtvfrrr commented Nov 1, 2024

What has changed?

The date formatting function has been refactored.

The function should not return another function in this case because the parameters are only passed down once. By changing the scope of the function and passing the parameters independently, the error disappears.

Level of change

  • Bug fix

Fix: #143

@webketje
Copy link
Member

webketje commented Nov 4, 2024

Thank you, I knew you were onto something. I didn't completely figure out the issue but it definitely has to do with uncareful reassignment of the format parameter (but you added caching the fn definition as well). I would merge this MR if you could make a small change & have the returned function continue to be a named fn formatDate so that the log shows it nicely (else it will show [Function (anonymous)]):

  @metalsmith/permalinks:info Running with options: {
  @metalsmith/permalinks:info   trailingSlash: false,
  @metalsmith/permalinks:info   duplicates: [Function: error],
  @metalsmith/permalinks:info   linksets: [
  @metalsmith/permalinks:info     {
  @metalsmith/permalinks:info       match: [Object],
  @metalsmith/permalinks:info       pattern: 'first/:title',
  @metalsmith/permalinks:info       date: [Function: formatDate],
  @metalsmith/permalinks:info       slug: [Function: defaultSlugFn]
  @metalsmith/permalinks:info     }

The function you extracted can be named formatDateBody/Inner or sth else (ah and maybe start the commit with Fix #143 to auto-close the issue and link it to this MR).

Your report made me notice there were some enhancements to be made in logging and date handling, so I'll be releasing a patch/minor version soon

@vctrtvfrrr
Copy link
Contributor Author

I made this small improvement to the function name to avoid [Function (anonymous)]).

Feel free to make any other changes you see fit.

@webketje webketje merged commit 7258738 into metalsmith:main Nov 6, 2024
5 checks passed
@vctrtvfrrr vctrtvfrrr deleted the fix-date-pattern branch November 6, 2024 04:19
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

Successfully merging this pull request may close these issues.

Error creating permalinks with :date
2 participants