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

Generate new posts from the terminal #257

Open
kirjs opened this issue Jun 28, 2014 · 5 comments
Open

Generate new posts from the terminal #257

kirjs opened this issue Jun 28, 2014 · 5 comments

Comments

@kirjs
Copy link

kirjs commented Jun 28, 2014

Could be used like this: wintersmith article 'Post Title'

A folder can be generated with a name post-title (some kind of a slug)
Index.md can have all default settings and current date as a date in yaml.

Would same some time on copy/paste

@jnordberg
Copy link
Owner

This is out of scope for wintersmith since it does not have any concept of an article. A helper script in the blog example/template could be a compromise. Something like ./bin/new_article "Post title"

@phippg
Copy link

phippg commented Jun 29, 2014

I think @kirjs idea is the most convenient way to do it. Would it be possible to have "plugin commands" as in if Wintersmith receives a command it doesn't natively know it goes and looks in folder X and Y for a script with that name? That would deliver convenience and still not clutter up the Wintersmith executable with "blog-aware" commands and concepts.

Example Time:
I execute wintersmith article "Hello World. Wintersmith doesn't know that command and looks in its current working directory (e.g /home/user/blog/) for a plugins/bin/article.coffee or article.js file. It then goes and passes the original arguments (namely the post title) "Hello World" into the script which creates and populates the necessary directories and files.

@kirjs
Copy link
Author

kirjs commented Jun 29, 2014

@philg, I actually like @jnordberg intention to keep the core clean and simple.

I think all the all the scaffolding functionality can be moved out to some other scaffolding tool, like a yeoman generator, that can build it's functionality on top of wintersmith.

I found a https://github.com/yangpro/generator-logsmith generator, which looks like a good candidate for the task and created an issue there.

@jnordberg
Copy link
Owner

Refs #152

@phippg
Copy link

phippg commented Jun 29, 2014

I indeed understand the problem with adding such functionality to the core of Wintersmith too!

I just think since it "advertises" itself as flexible it would make sense to allow users to easily add subcommands to wintersmith.

argv = optimist.options(globalOptions).argv
  if argv._[0]?
    try
      cmd = require "./#{ argv._[0] }"
    catch error
      if error.code is 'MODULE_NOT_FOUND'
        # requiring plugin command without error checks for readability
        cmd = require "#{ process.cwd() }/plugins/commands/#{ argv._[0] }"
      else
        throw error

This is quite surely the most unelegant way to do it since nested try/catch blocks are absolutely hideous; but I think it gets the point across.

Custom commands can be implemented like the builtin ones, just stored in another directory to not mess up the core functionality. Heck, you would already have examples on how to do custom commands!

Something like this to keep it elegant?

argv = optimist.options(globalOptions).argv
  if argv._[0]?
    try
      cmd = require_command argv._[0]
    catch error
      if error.code is 'MODULE_NOT_FOUND'
        console.log "'#{ argv._[0] }' - no such command"
        process.exit 1
      else
        throw error

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