Socket
Socket
Sign inDemoInstall

gatsby-remark-extract-keywords

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-remark-extract-keywords

Extract keywords (for SEO, display, etc) on all remark nodes.


Version published
Maintainers
1
Weekly downloads
5
increased by150%

Weekly downloads

Readme

Source

gatsby-remark-extract-keywords

MIT License

All Contributors

Extract most important keywords from your content using Natural tf-idf. From their docs:

Term Frequency–Inverse Document Frequency (tf-idf) is implemented to determine how important a word (or words) is to a document relative to a corpus. The following formulas are used for calculating tf and idf:

  • tf(t, d) is a so-called raw count, so just the count of the term in the document
  • idf(t, D) uses the following formula: 1 + ln(N / (1 + n*t)) where N is the number of documents, and n_t the number of documents in which the term appears. The 1 + in the denominator is for handling the possibility that n_t is 0.

In our context, N is just 1, your page/post content.

Supports both MD and MDX format.

Table of Contents

Installation

npm install --save gatsby-remark-extract-keywords

or

yarn add gatsby-remark-extract-keywords

It has gatsby as peerDependency.

Usage

In your gatsby-config.js:

plugins: [
    {
        resolve: `gatsby-transformer-remark`,
        options: {
            plugins: [`gatsby-remark-extract-keywords`],
        },
    },
];

This creates a new field on each MD/MDX node called keywords, you can use it on your GraphQL query:

query ListingQuery {
  allMarkdownRemark(sort: {fields: [frontmatter___date], order: DESC}) {
    edges {
      node {
        id
        frontmatter {
          title
        }
        fields {
          keywords
        }
      }
    }
  }
}

blacklist option as function

This will only return keywords with keyword length higher than 5.

const filterKeywords = term => term.length > 5;

plugins: [
    {
        resolve: `gatsby-transformer-remark`,
        options: {
            plugins: [
                {
                    resolve: `gatsby-remark-extract-keywords`,
                    options: {
                        blacklist: filterKeywords,
                    },
                },
            ],
        },
    },
];

Options

OptionDescription
maxMaximum number of keywords to return
blacklistString, array of strings or function to blacklist terms. If function, is used as filter parameter.

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Eduardo Reveles

💻 📖 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Last updated on 14 Feb 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc