Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manovotny/remark-mdx-metadata
Remark transformer for modifying MDX metadata.
https://github.com/manovotny/remark-mdx-metadata
markdown mdx mdx-js meta metadata remark remark-plugin
Last synced: about 1 month ago
JSON representation
Remark transformer for modifying MDX metadata.
- Host: GitHub
- URL: https://github.com/manovotny/remark-mdx-metadata
- Owner: manovotny
- License: mit
- Created: 2019-01-11T21:57:49.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-03T03:01:41.000Z (about 5 years ago)
- Last Synced: 2024-10-01T05:21:43.453Z (about 2 months ago)
- Topics: markdown, mdx, mdx-js, meta, metadata, remark, remark-plugin
- Language: JavaScript
- Homepage:
- Size: 272 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# remark-mdx-metadata
> [Remark](https://remark.js.org/) transformer for modifying MDX metadata.
This is a [remark](https://remark.js.org/) plugin for externally modifying an MDX's metadata, which is useful for when you want to add or update properties like a last edited datetime or a link to edit on GitHub.
## Installation
### NPM
```
$ npm i remark-mdx-metadata
```### Yarn
```
$ yarn add remark-mdx-metadata
```## Usage
> This plugin requires [remark-mdx](https://github.com/mdx-js/mdx/tree/master/packages/remark-mdx) to parse mdx correctly,
Say we have the following file, `example.mdx`:
```
export const meta = {
existingProp: 'existing value'
};# Title
Content.
```And our script, `example.js`, looks as follows:
```js
const vfile = require('to-vfile');
const remark = require('remark');
const mdx = require('remark-mdx');
const mdxMetadata = require('remark-mdx-metadata');(async () => {
const file = await vfile.read('example.mdx');
const result = await remark()
.use(mdx)
.use(mdxMetadata, {
meta: {
lastEdited: `${new Date().toISOString()}`
}
})
.process(file);console.log(result.toString());
})();
```Now, running `node example` yields:
```
export const meta = {
existingProp: 'existing value',
lastEdited: '2018-09-02T18:58:18.000Z'
};# Title
Content.
```You can try this yourself by downloading or cloning the project, installing dependencies, and running `yarn example`.
## API
### `remark().use(mdxMetadata[, options])`
Adds or updates MDX metadata with the metadata supplied.
- Adds new metadata property if it doesn't exist.
- Updates existing metadata property if it does exist.
- Intelligently merges new and existing metadata.
- Will update the MDX metadata, in place, if there is existing metadata.
- Will appropriately insert metadata if there isn't any existing metadata.#### Options
##### `meta`
Type: `Object`
Specifies the metadata to add or update.
## License
MIT © [Michael Novotny](https://manovotny.com)