Code Monkey home page Code Monkey logo

metalsmith-redirect's Introduction

metalsmith-redirect Build Status NPM version

A Metalsmith plugin to create HTTP redirections.

Installation

$ npm install metalsmith-redirect

Usage

CLI

{
  "plugins": {
    "metalsmith-redirect": {
      "/from/foo.html": "/to/bar.html"
    }
  }
}

JavaScript

var MetalSmith = require('metalsmith');
var redirect = require('metalsmith-redirect');

Metalsmith(__dirname)
  .use(redirect({
    '/foo': '/img/foo.png',
    '/bar.html': '/img/'
  }));

This plugin can be configured by passing an object. Each key/value will be used to create a redirection. Each key corresponds to the source and the associated value to the destination.

Due to restrictions in the way this plugin proceeds, the source must be either:

  • a HTML file path
  • a folder path, in such a case '/index.html' will be appended

The destination can be any kind of path.

A relative path in the source will be resolved from '/'.

A relative path in the destination will be resolved from the source directory.

Examples

Some examples of user configurations and how they are resolved by this plugin. For each example, the first object is the user configuration, and the second object is what is resolved by the plugin.

{ 'foo': 'hidden.html' }
{ '/foo/index.html': '/foo/hidden.html' }
{ '/foo/bar.html': 'baz' }
{ '/foo/bar.html': '/foo/baz' }
// It is possible to do external redirections.
{ '/github': 'https://github.com/segmentio' }
{ '/github/index.html': 'https://github.com/segmentio' }
// A Markdown file is not a valid source
{ 'foo.md': 'hidden.html' } // throw error

Changelog

  • 1.0.1

    • Strip leading slash to support latest Metalsmith major release (1.0.0)
  • 1.0.0

    • Bump stable
  • 0.0.3

    • Now use rel=canonical in the redirection template
  • 0.0.2

    • Automatic NPM deployment from Travis
    • Fix the normalize.relativeTo() method
  • 0.0.1

    • Internal redirections (both absolute and relative)
    • External redirections (toward other websites)

License

MIT © Aymeric Beaumet

metalsmith-redirect's People

Contributors

aymericbeaumet avatar blakeembrey avatar misterdai avatar

Watchers

 avatar  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.