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

@helloample/netlify-plugin-redirects

v1.3.0

Published

Read a CSV file, parse the rows and write them to `_redirects` _before_ Netlify processes your build.

Downloads

536

Readme

netlify-plugin-redirects

build status npm version

Read a CSV file, parse the rows and write them to _redirects before Netlify processes your build. Check out an example implementation here.

Why?

Netlify's _redirects file does not support environment variables or context. With this build, you can specify environmentally specific redirect rules in a CSV file and then dynamically write those rules to _redirects before your site is deployed.

Setup

Create a new file called redirects.csv and put it in the root of your application directory (example). Each row in your CSV file should contain the following columns:

| Source | Destination | Status | Context | | ---------------------------------- | ------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | | This is the path you want to match | This is the destination for your rule | The status code associated with the rule, eg. 301, 200!, etc. | Comma delimited string of branch names for your deployment context, leave this column blank for "no context" |

If you have defined a context for a rule, it will only be rendered for when the current branch name is included within that column; if you have not defined a context, that rule will be deployed everywhere.

When referring to exported environment variables, you need to use the following convention in your CSV...

${env:SOME_ENV_VARIABLE}

Install

Add the plugin to your package.json file...

$ npm i @helloample/netlify-plugin-redirects -D

Create a new file at the root of your project called redirects.csv with your redirect rules (see setup for more information on formatting your rules)...

$ echo "/redirect-me,https://ample.co,301!" > ./redirects.csv

And add the plugin to your netlify.toml file (see configuration for available options)...

[[plugins]]
  package = "@helloample/netlify-plugin-redirects"

Commit & push changes back to your repository. Now go watch the next build on Netlify.

Configuration

You can tell the plugin where to source your rules and where to write the parsed redirects via the following options, in your netlify.toml file...

  • source: Specifies the location of your CSV file.
  • destination: Specifies the file to which the parsed rules will be written.
  • defaultBranch: The default branch for your repo. This value is used when context cannot be determined.

The default configuration, if none is specified, is:

[[plugins]]
  package = "@helloample/netlify-plugin-redirects"
  [plugins.inputs]
    source = "./redirects.csv"
    destination = "./_redirects"
    defaultBranch = "master"

License

This project is licensed under the MIT License.