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

Error creating permalinks with :date #143

Closed
vctrtvfrrr opened this issue Nov 1, 2024 · 2 comments · Fixed by #144
Closed

Error creating permalinks with :date #143

vctrtvfrrr opened this issue Nov 1, 2024 · 2 comments · Fixed by #144

Comments

@vctrtvfrrr
Copy link
Contributor

Describe the bug
I always get an error when generating permalinks that include dates, regardless date format and options chosen.

To Reproduce
Sample markdown files:

Technology/Articles/Path/To/HTML Tutorial.md
Technology/Articles/Some Article.md
Technology/Notes/another-article.md

Each markdown file contains the attributes:

---
title: Article title
date: 2024-11-01
---

Metalsmith script config:

  // ...
  .use(
    permalinks({
      linksets: [
        {
          match: { collection: "techArticles" },
          pattern: "technology/articles/:date/:basename",
          date: "YYYY",
        },
        {
          match: { collection: "techNotes" },
          pattern: "technology/notes/:date/:basename",
          date: "YYYY",
        },
      ],
      trailingSlash: true,
      date: "YYYY",
    })
  )
  // ...

Error message:

file:///path/to/project/node_modules/.pnpm/@[email protected][email protected]/node_modules/@metalsmith/permalinks/lib/index.js:398
        return done(new Error(msg));
                    ^

Error: Filepath "Technology/Articles/Some Article.md.html" contains invalid filepath characters (one of :|<>"*?) after resolving as linkset pattern "technology/articles/:date/:basename"
    at file:///path/to/project/node_modules/.pnpm/@[email protected][email protected]/node_modules/@metalsmith/permalinks/lib/index.js:398:21
    at Array.forEach (<anonymous>)
    at Ware.permalinks (file:///path/to/project/node_modules/.pnpm/@[email protected][email protected]/node_modules/@metalsmith/permalinks/lib/index.js:365:104)
    at Ware.<anonymous> (/path/to/project/node_modules/.pnpm/[email protected]/node_modules/wrap-fn/index.js:45:19)
    at next (/path/to/project/node_modules/.pnpm/[email protected]/node_modules/ware/lib/index.js:85:20)
    at /path/to/project/node_modules/.pnpm/[email protected]/node_modules/wrap-fn/index.js:121:18
    at Ware.collections (file:///path/to/project/node_modules/.pnpm/@[email protected][email protected]/node_modules/@metalsmith/collections/lib/index.js:209:5)
    at Ware.<anonymous> (/path/to/project/node_modules/.pnpm/[email protected]/node_modules/wrap-fn/index.js:45:19)
    at next (/path/to/project/node_modules/.pnpm/[email protected]/node_modules/ware/lib/index.js:85:20)
    at /path/to/project/node_modules/.pnpm/[email protected]/node_modules/wrap-fn/index.js:121:18

Environment

  • Ubuntu 24.04
  • Node.js v20.18.0
  • npm 10.9.0
@webketje
Copy link
Member

webketje commented Nov 1, 2024

Hi there, I'd have to set up a minimum repro, I'm failing to reproduce this by altering the "should format a date" unit test.
Tested spaces in path, different configs. It may be an unspotted bug to do with multiple . dots in filename.

Evidently the path should not contain invalid filepath characters when the placeholders (:date) etc are resolved.
image
Is it maybe that not all of the matched files have a :dateproperty? Even then, you should get a different error:

Error: Could not substitute ':date' in pattern ':date/:basename', 'date' is undefined for file 'index.html'

What happens when you make the :date? placeholder optional? (adding a question mark)
Running your script with DEBUG=@metalsmith/permalinks* may give you more info

@vctrtvfrrr
Copy link
Contributor Author

vctrtvfrrr commented Nov 1, 2024

I opened a pull request with a possible fix for this issue. It seems that the error is related to the resolution of the date formatting function.

I also added a new test scenario that reproduces my issue.

#144

vctrtvfrrr added a commit to vctrtvfrrr/permalinks that referenced this issue Nov 5, 2024
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 a pull request may close this issue.

2 participants