npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-remark-orphans

v1.0.7

Published

Gatsby plugin for removing orphans in markdown text.

Downloads

98

Readme

Gatsby Remark Orphans

This plugin aims to combat widows and orphans on pages generated from markdown files. It can be used with both gatsby-transformer-remark and gatsby-plugin-mdx via its gatsbyRemarkPlugins option.

By default it supports polish language. Plugin can be configured to support other languages too.

Installation

Install with npm:

npm install gatsby-remark-orphans

Install with yarn:

yarn add gatsby-remark-orphans

How to use

After installing gatsby-remark-orphans you can add it to your plugins list in your gatsby-config.js.

Configure with gatsby-transformer-remark:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [`gatsby-remark-orphans`],
    },
  },
],

Configure with gatsby-plugin-mdx:

// In your gatsby-config.js
plugins: [
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [`gatsby-remark-orphans`],
      },
    },
],

Configuration

gatsby-remark-orphans exposes a set of options that can be used to control and extend the behavior of the plugin.

| Key | Default | Description | | ---------------------------- | ------- | ---------------------------------------------------------------------------------------------------- | | disableDefaultLocaleResolver | false | Disables extension of custom locale resolver with default behavior. | | customLocaleResolver | - | Function that accepts a markdown node and returns a locale or undefined. | | disableBuiltInHandlers | false | Disables usage of default orphan handlers when custom ones are specified. | | customHandlers | - | An object of key value pairs for locale and array of handlers that should be used to remove orphans. | | silenceReporting | false | Disables reporting in console, which primarily happens in case of missing locale or handlers. |

Providing custom locale resolver.

By default gatsby-remark-orphans looks for locale in fields and frontmatter properties of the markdown node object. If you use a different marking system for you files you can use the customLocaleResolver option.

// In your gatsby-config.js
plugins: [
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-orphans`,
            options: {
              customLocaleResolver: (markdownNode) => markdownNode.frontmatter.language
              // You can additionally disable the default locale resolver.
              // If that is done the default lookup for `local` in `fields` and `frontmatter`
              // will not be performed if the custom locale resolver fails to identify the language
              disableDefaultLocaleResolver: true,
            }
          }
        ],
      },
    },
],

Providing custom handlers for languages

If you want to use the plugin with other languages than polish you can provide custom handler via plugin options.

// In your gatsby-config.js
plugins: [
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-orphans`,
            options: {
              customHandlers: {
                en: [{
                  regex: new RegExp(" and ", "g") // It is advised to use the global flag,
                  replacer: (match) => `${match.slice(0, -1)}\u00a0`
                }]
              }
              // You can additionally disable default handlers for a language if you want
              // to take full control over the orphan removal.
              disableBuiltInHandlers: true,
            }
          }
        ],
      },
    },
],

Silencing build logs

By default the plugin will warn about missing locales or missing handlers so you can catch what is not being processed. If you're using some languages that do not require any handling you can disable reporting to get rid of the logs.

// In your gatsby-config.js
plugins: [
    {
      resolve: `gatsby-plugin-mdx`,
      options: {
        gatsbyRemarkPlugins: [
          {
            resolve: `gatsby-remark-orphans`,
            options: {
              silenceReporting: true
            }
          }
        ],
      },
    },
],