https://github.com/lightpohl/node-md-meta-cataloger
A module and CLI for parsing Markdown files (including YAML Front Matter metadata).
https://github.com/lightpohl/node-md-meta-cataloger
Last synced: about 1 month ago
JSON representation
A module and CLI for parsing Markdown files (including YAML Front Matter metadata).
- Host: GitHub
- URL: https://github.com/lightpohl/node-md-meta-cataloger
- Owner: lightpohl
- Created: 2018-08-18T03:35:49.000Z (almost 8 years ago)
- Default Branch: main
- Last Pushed: 2023-08-09T02:43:07.000Z (almost 3 years ago)
- Last Synced: 2025-10-10T17:11:33.547Z (9 months ago)
- Language: JavaScript
- Size: 137 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# node-md-meta-cataloger
## Easily generate a JSON array of markdown files and their inline metadata.
## Installation
`npm install --save node-md-meta-cataloger`
## How to Use
### CLI Tool
`node-md-meta-cataloger -i -o `
`node-md-meta-cataloger -i /path/to/folder -o /another/path/catalog.json`
`node-md-meta-cataloger --help`
| Option | Short Flag | Required | Description |
| --------------------- | ---------- | -------- | ------------------------------------- |
| --input \ | -i | true | input directory path |
| --output \ | -o | true | output path of JSON result |
| --delete-filename-ext | -d | false | remove ".md" from filenames in result |
| --config | -c | false | path to .js config file |
| --version | -v | false | output the version number |
| --help | -h | false | output usage information |
#### Config File (--config)
- Using the `--config` option you can specify a path to a JS config file (an ES module) that should return a default object exported with "camelCased" versions of the existing CLI options (plus any extra).
- If an option exists in both the config file and as a CLI option, then the CLI option will receive priority.
| Option | Type | Required | Description |
| ----------------- | -------- | -------- | -------------------------------------------------------- |
| input | String | true | input directory path |
| output | String | true | output path of JSON result |
| normalize | Function | false | receives results as param, returned object is new result |
| sort | Function | false | function for `sort` |
| deleteFilenameExt | Boolean | false | remove ".md" from filenames in result if true |
### Node Module
#### `readMarkdown(path: String): Promise`
Path parameter may reference a markdown file or folder containing markdown files.
1. If passed a path to a folder, it returns a promise that resolves to an array of objects containing all markdown file content and their associated metadata.
2. If passed a path to a file, it return a promise that resolves to an object containing the markdown content and its metadata.
```js
import {readMarkdown} from 'node-md-meta-cataloger';
const result = await readMarkdown('path/to/folder');
```
Example value of `result` above:
```js
[
{
content: '
markdown content
',
filename: 'example.md',
filepath: 'path/to/folder/example.md',
metadata: {
title: 'Title',
author: 'Joshua',
},
},
];
```