https://github.com/codingstark-dev/markdown-blog-post-generator-node.js-cli
This Node.js command line tool automates creating Markdown blog posts by handling filename generation, frontmatter templates, and post scaffolding. It prompts for a title, populates template frontmatter fields, and writes the file to the /content/blog folder. Handy for bootstrapping drafts and eliminating repetitive setup tasks.
https://github.com/codingstark-dev/markdown-blog-post-generator-node.js-cli
cli markdown md mdx nodejs
Last synced: 12 months ago
JSON representation
This Node.js command line tool automates creating Markdown blog posts by handling filename generation, frontmatter templates, and post scaffolding. It prompts for a title, populates template frontmatter fields, and writes the file to the /content/blog folder. Handy for bootstrapping drafts and eliminating repetitive setup tasks.
- Host: GitHub
- URL: https://github.com/codingstark-dev/markdown-blog-post-generator-node.js-cli
- Owner: codingstark-dev
- License: mit
- Created: 2023-09-30T12:31:47.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-09-30T12:35:21.000Z (over 2 years ago)
- Last Synced: 2025-01-16T00:22:58.784Z (about 1 year ago)
- Topics: cli, markdown, md, mdx, nodejs
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Markdown Post Generator CLI in Node.js
## Overview
This CLI allows generating a new Markdown post with frontmatter metadata for a blog or website. It prompts the user for a post title, then generates a filename and populates template frontmatter with title, date, author etc. The Markdown file is created in a `content/blog` directory.
## Usage
To use the CLI:
1. Clone the repo and install dependencies with `npm install`
2. Run `node index.cjs`
3. Enter a title when prompted
4. The Markdown file will be created in `content/blog`
## Code Overview
The main dependencies are:
- `readline` - for prompting user input
- `child_process` - to get Git author name
- `fs` - for file system operations
- `path` - for resolving file paths
The key functions are:
- `textToSlug()` - generates a URL-friendly slug from a string
- `rl.question()` - prompts user for title
- `rl.on('close')` - generates file name and frontmatter after title entered
- `fs.writeFileSync()` - writes new Markdown file
The frontmatter is populated from a template string with title, date, author etc.
Error handling is included for cases like existing file.
## Contributing
Pull requests are welcome to add features or fix bugs!
Some ideas:
// TODO
- [ ] Support different frontmatter formats (YAML etc)
- [ ] Add prompt for categories, tags
- [ ] Allow passing filename on CLI instead of prompt
- [ ] Wordpress to Markdown converter