0.1.7 • Published 3 years ago

@tlindgren/gatsby-remark-double-brackets-link v0.1.7

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

gatsby-remark-double-brackets-link

Transform [[Link to page]] into [Link to page](titleToURL('Link to page')).

An example site for using this plugin is at https://mathieudutour.github.io/gatsby-digital-garden/

Installation

npm install gatsby-remark-double-brackets-link

Usage

Add the plugin to your Gatsby config:

{
  resolve: `gatsby-plugin-mdx`,
  options: {
    gatsbyRemarkPlugins: [
      {
        resolve: `gatsby-remark-double-brackets-link`,
      },
    ],
  },
}

Resolving the URL

By default, the plugin will resolve the url with:

(title: string) => `/${slugify(title)}`;

You can override this behavior by passing a titleToURLPath option pointing to a JavaScript exporting a function receiving the title as argument and returning a string.

For example:

// resolve-url.js
const slugify = require('slugify')
module.exports = (title) => `/${slugify(title)}`

// gatsby-config.js
{
  ...
  {
    resolve: `gatsby-plugin-mdx`,
    options: {
      gatsbyRemarkPlugins: [
        {
          resolve: `gatsby-remark-double-brackets-link`,
          options: {
            titleToURLPath: `${__dirname}/resolve-url.js`
          },
        }
      ],
    },
  }
  ...
}

By default, the plugin will keep the brackets in the link name. You can change this behavior by passing a stripBrackets options.