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

Pass all config in constructor #280

Open
kievechua opened this issue Mar 2, 2017 · 6 comments
Open

Pass all config in constructor #280

kievechua opened this issue Mar 2, 2017 · 6 comments
Labels

Comments

@kievechua
Copy link

Is there a plan to pass config as following?

var Metalsmith = require('metalsmith');
Metalsmith({
  "source": "src",
  "destination": "build",
  "plugins": [
    {"metalsmith-drafts": true},
    {"metalsmith-markdown": true},
    {"metalsmith-permalinks": "posts/:title"},
    {"metalsmith-templates": "handlebars"}
  ]
})
.build()
@Ajedi32
Copy link
Member

Ajedi32 commented Mar 2, 2017

Hmm, yeah it does seem like a good idea to expose an API for building a Metalsmith object from the config file format used by the CLI. Not sure we'd be able to implement this the exact same way though, as the constructor function currently requires a directory argument, which isn't provided in that example.

Seems like a pretty reasonable request though. Also probably worth mentioning #205 here, since that's somewhat related...

@kievechua
Copy link
Author

Maybe we can just introduce options parameter?

var Metalsmith = require('metalsmith');
Metalsmith(directory, {
  "source": "src",
  "destination": "build",
  "plugins": [
    {"metalsmith-drafts": true},
    {"metalsmith-markdown": true},
    {"metalsmith-permalinks": "posts/:title"},
    {"metalsmith-templates": "handlebars"}
  ]
})
.build()

This way it's backward compatible and nothing have to change for the Metalsmith config.

@Ajedi32
Copy link
Member

Ajedi32 commented Mar 23, 2017

@kievechua Something like that could work. Though as I alluded to in my previous comment, if we're splitting the CLI out from Metalsmith it might be better to include this API in that project instead. I'm not completely sure though.

What's the use-case for this? Are you just looking for a cleaner API?

@kievechua
Copy link
Author

We're thinking of building it with build system like fly or etc.
That's the only use case now.

Let me know if there's a better way to do it.

@Ajedi32
Copy link
Member

Ajedi32 commented Mar 28, 2017

Well for now you can always just use the existing API right?

This feature wouldn't really add any new functionality, it'd just be an extra way of configuring Metalsmith using a different API.

@kievechua
Copy link
Author

No worry on it, I'm using existing method to call on it.
Since the cli already can pass all the config in 1 shot, just wondering why not reuse it.
I don't want to have a duplicate config, just want to share it when using cli or programatic.

@webketje webketje added the to revisit To be tackled shortly label Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants