Skip to content
Remark transformer for modifying MDX metadata.
Branch: master
Clone or download
Latest commit c0f8bef Mar 17, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.vscode Renames project and rearranges files. Jan 30, 2019
__tests__ Removes baked in `remark-mdx` in favor of officially released version. ( Feb 12, 2019
example
.editorconfig Adds project structure. Jan 21, 2019
.eslintignore Removes lingering embedded `remark-mdx` references. Feb 14, 2019
.eslintrc.js Adds project structure. Jan 21, 2019
.gitattributes Adds project structure. Jan 21, 2019
.gitignore Adds tests. (#3) Feb 8, 2019
.npmignore Removes lingering embedded `remark-mdx` references. Feb 14, 2019
.npmrc Adds project structure. Jan 21, 2019
.nvmrc Adds project structure. Jan 21, 2019
.prettierignore Adds tests. (#3) Feb 8, 2019
.prettierrc.js Adds project structure. Jan 21, 2019
LICENSE Adds project structure. Jan 21, 2019
README.md Removes baked in `remark-mdx` in favor of officially released version. ( Feb 12, 2019
index.js Updates dependencies. Mar 18, 2019
jest.config.js Adds tests. (#3) Feb 8, 2019
package.json v1.0.1 Mar 18, 2019
yarn.lock Updates dependencies. Mar 18, 2019

README.md

remark-mdx-metadata

Remark transformer for modifying MDX metadata.

This is a remark 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 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:

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

You can’t perform that action at this time.