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

Multiple permalinks per collection #17

Closed
totocaster opened this issue Jul 3, 2014 · 3 comments
Closed

Multiple permalinks per collection #17

totocaster opened this issue Jul 3, 2014 · 3 comments

Comments

@totocaster
Copy link

Hello, how do I "map" different permalinks on different collections. For examples I want blog posts to have /YYYY/MM/post-title formatting and regular pages to have /page-title permalink. posts and pages are different collections of course.

Thanks!

@misterdai
Copy link

👍 I need as well and there doesn't appear to be a way available with the plugin currently. However, I've modified my copy to support it when provided options in the following format:

  .use(permalinks({
    {posts: {pattern: '/:collection/:date/:title'}},
    {pages: {pattern: '/:collection/:title'}},
    {"*": {pattern: '/:title'}}
  })

Gist: https://gist.github.com/misterdai/84fa94cd382e66262357

The modification simply checks for a permalink rule that matches the collection name or it'll default to the wildcard * for any other file or unmatched collection. If there's no global rule or matching collection, it'll skip creating the permalink for the file.

I think collection based permalinks may be better as a separate plugin, but I'll leave it up to @ianstormtaylor to decide that :)

@patdavid
Copy link

Just came here on a somewhat related issue and noticed this. I had problems with it for a while, but the solution I went with was to use metalsmith-branch to branch my blog posts separately (they're nested under a different src/ folder. relevant section:

.use( branch('blog/posts/**')
    .use( permalinks({
        pattern: 'blog/:date/:title',
        date: 'YYYY/MM',
    }))
)

My problem now is how to handle relative files to bring them over in nested folders, but I'll open another issue for that.

@totocaster
Copy link
Author

Hello, so it's been a while since I asked that question and digging deeper into Metalsmith just gave me indication that I didn't treat it as it supposed to be. Here is what I've done to solve my problem.

  .use(copy({
    pattern: 'pages/*',
    directory: '/'
  }))
  .use(ignore(['pages/*',".DS_Store"]))
  .use(permalinks({
    pattern: ':date/:title',
    date: 'YYYY/MM'
  }))

Thus, this plugins does it's job correctly, and it is job of other similarly simple and straightforward plugins to do the rest. Simplicity is a king in Metalsmith, I'm loving it..

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

No branches or pull requests

3 participants