Skip to main content

This Pelican plugin creates an nginx-compatible map between the final page locations and prior locations, defined in the `Alias` attribute for any article or page.

Project description

nginx_alias_map: A Plugin for Pelican

Build Status PyPI Version License

This Pelican plugin creates an nginx-compatible map between the final page locations and prior locations, defined in the "Alias" attribute for any article or page.

Loosely based on pelican-alias by Chris Williams, which itself was inspired by jekyll_alias_generator.

Installation

This plugin can be installed via:

python -m pip install pelican-nginx-alias-map

Usage

Add the directory to the base plugins directory to PLUGIN_PATHS in pelicanconf.py, and then add nginx_alias_map to the PLUGINS list. For example,

PLUGIN_PATHS = ["plugins"]
PLUGINS = ['nginx_alias_map']

Definable parameters (with defaults in brackets) allow some configuration of the output of the plugin.

There are two definable parameters, one from Chris's code (ALIAS_DELIMITER), which defines the delimiter for multiple aliases for the same item; and ALIAS_FILE, which defines the final name of the output file containing the map; and

ALIAS_DELIMITER : Delimeter between multiple aliases for the same item [","]
ALIAS_FILE : Name of map file to be placed in `output` ['alias_map.txt']
ALIAS_MAP : Name of the map used in the alias file ['redirect_uri']
ALIAS_MAP_TEMP: Name of the map used in the alias file when 2-stage lookup is needed ['redirect_uri_1']

Support for URLs with query strings

In the event that you need to redirect a URI that contains a query string, a separate map block will be created to map the $request_uri against an re.escaped version of your alias that contains the ? character. Otherwise, when no query string is present, the test is made against $uri, which has much more processing done with it (query string removal, removal of unnecessary '/'s, and so forth).

NGINX configuration

The resulting file (stored in output/$(ALIAS_FILE)) is ready to be included into your nginx configuration file (in an http stanza). Once the map is created, use the ALIAS_MAP variable in your processing.

include /opt/web/output/alias_map.txt;

server {
  listen       *:80 ssl;
  server_name  example.server;


    # Redirection logic
    if ( $redirect_uri ) {
        return 301 $redirect_uri;
    }

    location / {
        alias /opt/web/output;
    }
}

This configuration uses the evil if statement, but it's concise. If you have a better approach, please create a pull request, and I'll add it to this doc (or replace it if it makes more sense).

I've chosen to use a 301 redirect here, because I'm confident of the permanency. During testing, you may want to use a 302.

Contributing

Contributions are welcome and much appreciated. Every little bit helps. You can contribute by improving the documentation, adding missing features, and fixing bugs. You can also help out by reviewing and commenting on existing issues.

To start contributing to this plugin, review the Contributing to Pelican documentation, beginning with the Contributing Code section.

License

This project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pelican-nginx-alias-map-0.1.0.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

pelican_nginx_alias_map-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file pelican-nginx-alias-map-0.1.0.tar.gz.

File metadata

  • Download URL: pelican-nginx-alias-map-0.1.0.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.6 Darwin/20.6.0

File hashes

Hashes for pelican-nginx-alias-map-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f96c80bf27cf0f68223270171860dde4ac117cc490859725a13b1f58595c8e21
MD5 f839bcd086178ddae579a80273b79ace
BLAKE2b-256 82647cdd0ab109011224a38f70b4ed671254ad61f72c2cdea0446aaf0db0ca48

See more details on using hashes here.

Provenance

File details

Details for the file pelican_nginx_alias_map-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pelican_nginx_alias_map-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1458e80e8066d3b0f18eb666affb515729b3ad21d43722993f676212643eb4b1
MD5 3f3a1b6d4c4cf910022c44e2bd42425b
BLAKE2b-256 c1a5650d7db16931da038627e6378bb53b66ec4370ce8997ba2fbc244977852e

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page