0.0.5 • Published 3 months ago

newmd v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

!CAUTION This project is still in development, the API may change in the future, please use it with caution.

* blog is the default schema with some fields. You can define your own schema in the config file.

Usage

CLI

Run the following command in your terminal:

npx newmd blog "Hello World"

or using pnpx(pnpm dlx):

pnpx newmd blog "Hello World"

Will create a markdown file with the following content:

---
title: Hello World
description: ''
pubDate: 2025-03-09T01:57:00.000Z
---

* The pubDate field will be filled with new Date().

You can install it globally for convenience.

Options

See newmd --help for more details, following is a brief description.

newmd <schemaName> <title>
  • --content <value> Set the content of the markdown file
  • --path <value> Set the output directory
  • --slug <value> Set the slug for the filename, if not provided, it will be generated from the slugified title.
  • --cwd <value> Set the current working directory
  • --toml Whether to use TOML format for frontmatter, default is false
  • --overwrite Whether to overwrite the existing file, default is false

Config file

You need to create a config file to define the schemas for the frontmatter.

The config structure and default values are as follows:

// newmd.config.[js,mjs,ts]
import { defineConfig, z } from 'newmd'

export default defineConfig({
    // The format of the frontmatter.
    format: 'yaml',
    // Root path for the markdown file.
    path: '.',
    // Schemas for the frontmatter.
    schemas: {
        blog: z.object({
            title: z.string(),
            description: z.string().optional(),
            pubDate: z.coerce.date(),
            updatedDate: z.coerce.date().optional(),
        }),
    },
})

Credits

This project won't be possible without @toiroakr's zod-empty and other open-source projects.

License

MIT License © 2024-PRESENT Max Chang

0.0.5

3 months ago

0.0.4

4 months ago

0.0.3

4 months ago

0.0.2

4 months ago

0.0.1

4 months ago