Git Product home page Git Product logo

gatsby-plugin-page-progress's Introduction

gatsby-plugin-page-progress

npm npm (tag) npm bundle size npm

Add a page progress indicator to your Gatsby project ๐Ÿ˜Ž The progress bar moves as you scroll down the page.

Page Progress Example

Useful for blog sites and other reading material so users know how far they've read into an article or page.

npm i gatsby-plugin-page-progress

Inside gatsby-config.js

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: ["/", { regex: "^/blog" }],
      excludePaths: ["/blog/beep-beep-lettuce"],
      height: 3,
      prependToBody: false,
      color: `#663399`,
      footerHeight: 500,
    }
  }
];

If you'd like the progression bar to appear on all pages of your project, you can simply add the name of the plugin to your plugins array in gatsby-config.js

plugins: ["gatsby-plugin-page-progress"];

includePaths

Required: โŒ

Accepts: [string | object]

Default: []

Supports multiple paths. This option enables the plugin to include an array of paths. You can use regex to define multiple path inclusions. See examples below

excludePaths

Required: โŒ

Accepts: [string | object]

Default: []

Supports multiple paths. This option enables the plugin to exclude an array of paths. You can use regex to multiple path exclusions. Defining paths to exclude will take precedence over includePath definitions. See examples below

prependToBody

Required: โŒ

Accepts: boolean

Default: false

If false, the bar is appended to the <body>. If true, the bar is prepended to the <body>.

height

Required: โŒ

Accepts: number

Default: 3

Sets the height of the progress bar.

color

Required: โŒ

Accepts: string

Default: #663399

Sets the color of the progress bar.

footerHeight

Required: โŒ

Accepts: number

Default: 0

Sets the height of the footer. The width of the progress bar will be scaled appropriately to reach 100% before reaching the page footer.

Only include the root path:

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: ["/"],
      excludePaths: []
    }
  }
];

Include the root path, plus all paths under the /blog route:

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: ["/", { regex: "^/blog" }],
      excludePaths: []
    }
  }
];

This plugin calls the constructor function for RegExp. That's why we define any regex that we want to use inside an object. For more information on how to write regular expressions using the RegExp constructor use MDN for reference.

Exclude only the root path:

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: [],
      excludePaths: ["/"]
    }
  }
];

Include the root path, plus every path under the /blog route, but exclude a specific path under /blog:

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: ["/", { regex: "^/blog" }],
      excludePaths: ["/blog/awesome/article"]
    }
  }
];

Include the root path, plus all paths under the /blog route, but exclude all paths under /blog that end with 'react'':

plugins: [
  {
    resolve: "gatsby-plugin-page-progress",
    options: {
      includePaths: ["/", { regex: "^/blog" }],
      excludePaths: [{ regex: "^/blog.+react$" }]
    }
  }
];

Remember that exclusions always take precedence over inclusions. In the case above - If the plugin finds any path that begins with /blog and ends with react it will not apply the progress indicator because it already knows to exclude that route ๐Ÿ˜ Inversely, if we were on a route under /blog that didn't end with react, it would apply the progress indicator because the exclusion rule wouldn't apply to that route.

gatsby-plugin-page-progress's People

Contributors

devjmetivier avatar dependabot-preview[bot] avatar dependabot-support avatar sa2812 avatar corradorossi avatar eyalroth avatar lekoarts avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.