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 builds break the plugin #78

Closed
rstacruz opened this issue Oct 11, 2017 · 2 comments
Closed

Multiple builds break the plugin #78

rstacruz opened this issue Oct 11, 2017 · 2 comments

Comments

@rstacruz
Copy link

The plugin isn't idempotent, running it twice will screw up the metadata.

app = metalsmith()
  .use(collections({ articles: { ... } })
  .build(done => ...)
  .build(done => ...)

The workaround is to create a middleware that clears up metadata:

app = metalsmith()
  .use((files, ms, done) => {
    ms.metadata({ articles: [] })
    done()
  })
  .use(collections({ articles: { ... } })
  .build(done => ...)
  .build(done => ...)
@dwightjack
Copy link

dwightjack commented Feb 7, 2018

👍 On this.

I've spent some time on this issue. In my case (using collection: in frontmatter, collections gets populated automatically.

My solution is as follows:

app = metalsmith()
  .use((files, ms, done) => {
    const metadata = ms.metadata()
    const { collections } = metadata
    if (collections) {
      Object.keys(collections).forEach((k) => {
        metadata[k] = [];
      });
    }
    done()
  })
  .use(collections())
  .build(done => ...)
  .build(done => ...)

@webketje
Copy link
Member

webketje commented Feb 2, 2022

Closing as this is a duplicate of #27

@webketje webketje closed this as completed Feb 2, 2022
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