Coder Social home page Coder Social logo

math4youbyusgroupillinois / netlify-plugin-no-more-404 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from swyxio/netlify-plugin-no-more-404

0.0 1.0 0.0 837 KB

Netlify Build plugin to guarantee you preserve your own internal URL structure between builds. Don't break the web! Demo:

Home Page: https://github.com/sw-yx/netlify-plugin-no-more-404-demo

JavaScript 100.00%

netlify-plugin-no-more-404's Introduction

Netlify Plugin No More 404

This build plugin will remember the html files you've built, and either warn or fail your build when you make the next build and accidentally lose some html pages (whether on purpose or intentional). The plugin understands Netlify redirects, so you can add a redirect to resolve missing html.

Note: this is different than https://github.com/munter/netlify-plugin-checklinks which checks the validity of outgoing links.

this plugin focuses entirely on whether your own internal URL structure has been preserved by some combination of your build process (it is agnostic of SSG/framework) and Netlify Redirects

Because this plugin is SSG/framework agnostic, it can be a great aid for migrating between frameworks.

Demo

https://github.com/sw-yx/netlify-plugin-no-more-404-demo

Usage

To install, add the following lines to your netlify.toml file:

[[plugins]]
package = "netlify-plugin-no-more-404"

  # all inputs are optional, we just show you the defaults below
  [plugins.inputs]
  
  # either "warn" or "error"
  on404 = "error" 
  
  # change this key to a new one any time you need to restart from scratch
  cacheKey = "MyCacheKey"
  
  # (for development) turn true for extra diagnostic logging
  debugMode = false

What It Does

On first run, we scan your publish directory and save a manifest of all your html files to a cache. The cache is a simple JSON file using a cacheKey.

On subsequent runs:

  • we read the manifest from the cache
  • read any _redirects or netlify.toml redirects you may have
  • match it against your new publish directory for missing paths (we are agnostic whether you use /foo or /foo.html or /foo/index.html) not covered by a redirect.
  • By default we fail your build if a missing path is found.
  • If no issues found, we save a new manifest to cache for the next run.

This cache is cleared when you "clear cache and deploy site" in the Netlify UI - I dont know how to get around this yet.

You can see the /tests folder for a definitive guide on what we test against.

Note: if your netlify.toml redirects have conditions, we don't account for that since we can't be sure to exhaustively check all conditions. We just ignore conditions for now.

Future plans

WE ARE SEEKING MAINTAINERS. I probably wont have time to attend to this full-time.

  • Local (Netlify Dev) testing as a prepush script?

  • persist through "clear cache and deploy site".

  • Maybe exhaustively check netlify.toml redirect conditions?

  • An option for graceful downgrade when some paths are moved to serverless or clientside rendering (right now you have to bump cacheKey to reindex from scratch)

  • We could add a preserveBuildIds config:

    plugins:
      - package: netlify-plugin-no-more-404
        config:
          on404: 'error'
          cacheKey: 'anystring' 
          preserveBuildIds: # compare vs specific build IDs to ensure no regression
          - abc123
          - def345
          - ghi678

netlify-plugin-no-more-404's People

Contributors

ehmicky avatar swyxio avatar verythorough avatar

Watchers

 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.