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

docpad-plugin-cleanurls

v2.12.1

Published

Adds support for clean URLs to DocPad

Downloads

88

Readme

Adds support for clean URLs to DocPad

Usage

static

In non-static environments we work by setting the document's url to it's clean url. This means that redirection occurs on the dynamic server level.

For the static environment (i.e. when running DocPad with the --env static flag, e.g. running docpad generate --env static) we will set the static plugin configuration option to true. This will in addition to performing redirections via the built-in dynamic server within DocPad for speed, we will also write special static redirection HTML files to the output directory, that will redirect the user to the new clean location (e.g. the document pages/welcome.html will now be outputted to pages/welcome/index.html, with pages/welcome.html now being a special HTML redirect document to the clean location).

If you would like to always use the static mode, you can set the static plugin configuration option to true with:

plugins:
	cleanurls:
		static: true

If you would like to disable the static mode for the static environment, you can do so with:

environments:
	static:
		plugins:
			cleanurls:
				static: false

If you would like to disable clean urls completely (not just the static mode) in the static environment, you can do so with:

environments:
	static:
		plugins:
			cleanurls:
				enabled: false

trailingSlashes

Enable this plugin configuration option to generate document.urls like '/beep/' instead of /beep. Defaults to false.

collectionName

You can use this plugin configuration option (defaults to html) to tell the cleanurls plugin to use your own custom collection for which documents to apply clean URLs to.

For instance, if you are wanting to remove all clean URLs for all documents that have cleanurls: false in the meta data, then you could do the following in your DocPad configuration file:

# Define a custom collection for cleanurls that ignores the documents we don't want
collections:
	cleanurls: ->
		@getCollection('html').findAllLive(cleanurls: $ne: false)

# Tell our clean urls plugin to use this collection
plugins:
	cleanurls:
		collectionName: 'cleanurls'

getRedirectTemplate

You can customise the HTML template that is used for the redirect pages by specifying the getRedirectTemplate option which is a function that accepts url argument and an option title argument and returns a string.

simpleRedirects

Simple redirects work via routes in dynamic environments, and on static environments work via generating redirect HTML pages at the location of the source relative URL. They can be defined like so:

plugins:
	cleanurls:
		simpleRedirects:
			'/relative-url': '/somewhere-else'
			'/other-relative-url': 'http://somehere.else'

advancedRedirects

Advanced redirects work via routes in dynamic environments, and on static environments work via a client-side javascript injection into the Script Block on your 404 Page document. They can be defined like so:

plugins:
	cleanurls:
		advancedRedirects: [
			# Regular expressions redirects are possible too
			[/^\/github\/?(.*)$/, 'https://github.com/docpad/$1']
			[/^\/plugin\/(.+)$/, 'https://github.com/docpad/docpad-plugin-$1']

			# Absolute URL redirects are even possible
			['http://production.com/favourite-website', 'http://wikipedia.org']
			['http://localhost:9778/favourite-website', 'http://facebook.com']
		]

To ensure they work, you must make sure that your 404 Page document calls @getBlock('scripts').toHTML() to output the Script Block, which we inject the client-side javascript into. Here is an example of such a document using eco and location at src/documents/404.html.eco:

<!DOCTYPE html>
<html>
    <head>
        <!-- Standard Meta -->
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />

        <!-- Site Properties -->
        <title>404 Page Not Found</title>

        <!-- DocPad Meta -->
        <%- @getBlock('meta').toHTML() %>

        <!-- DocPad Styles -->
        <%- @getBlock('styles').add('/vendor/404.css').toHTML() %>
    </head>
    <body>
        <!-- 404 Page Content -->
        <div class="container">
            <h1>Not Found 😲</h1>
            <p>Sorry, but the page you were trying to view does not exist.</p>
            <p>It looks like this was the result of either:</p>
            <ul>
                <li>a mistyped address</li>
                <li>an out-of-date link</li>
            </ul>
            <script>
                var GOOG_FIXURL_LANG = (navigator.language || '').slice(0, 2),
                    GOOG_FIXURL_SITE = location.host
            </script>
            <script src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script>
        </div>

        <!-- DocPad Scripts -->
        <%- @getBlock('scripts').toHTML() %>
    </body>
</html>

You can modify the client-side javascript by providing the option getRedirectScript` which is a function that accepts the advancedRedirects value as the first and only argument and returns a string which is the script to be injected.

Install this DocPad plugin by entering docpad install cleanurls into your terminal.

Discover the release history by heading on over to the HISTORY.md file.

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

These amazing people are maintaining this project:

No sponsors yet! Will you be the first?

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

Unless stated otherwise all works are:

and licensed under: