Skip to main content

Generates static redirections from a YAML file.

Project description

redirects-cli

A CLI to create static redirections from a YAML file.

Why?

You are relying on GitHub Pages to host your site. However, whenever you move a page from one folder to another, your users get the 404 page.

With redirects-cli, you can define 301 redirects for the pages you have moved in a YAML file. Then, you can generate static redirects for each path with one command.

In my case, I use this command in the project's CI pipelines before publishing the site to the gh-pages branch. If I define the redirections correctly, that means no more 404 errors!

Getting started

Requirements

  • Python >= 3.7
  • pip

Installation

pip install redirects_cli

Quickstart

redirects-cli fromfile --help

Usage

To generate static redirections from a YAML file:

  1. Define the redirects in a new file named redirections.yaml. This file must follow this syntax:
# old_path: new_path
# Example

# internal link example
/original-path/page-a.html: /new-path/page-a.html

# external link example
/original-path/page-b.html: https://example.local
  1. Run the command:
redirects-cli fromfile --yaml-file redirects.yaml --output-dir html

The CLI creates the static redirections you have defined in the redirections.yaml file within the folder html. For this example, it creates the following folder structure:

my-app/
├─ html/
│  ├─ original-path/page-a.html
│  ├─ original-path/page-b.html
├─ redirects.yaml

Contributing

Contributions are welcome and appreciated! If you want to enhance the CLI, please read CONTRIBUTING.md file first.

License

Copyright (c) 2022-present David Garcia (@dgarcia360). 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

redirects_cli-0.1.2.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

redirects_cli-0.1.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file redirects_cli-0.1.2.tar.gz.

File metadata

  • Download URL: redirects_cli-0.1.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.25.1

File hashes

Hashes for redirects_cli-0.1.2.tar.gz
Algorithm Hash digest
SHA256 a51a78c0895ca9e30ba1ed58089a336bcae2c39d0febed6ad849073939445a5f
MD5 4588252ff6bc23874e46b876a535b4ab
BLAKE2b-256 16a41efeaa8bb2382d4f3bc69c5f99dc2a4a3a39f2b0d4a4a2bdf7cab6b269e7

See more details on using hashes here.

Provenance

File details

Details for the file redirects_cli-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for redirects_cli-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8cd3cfef3b2cef71b62a7152b0ae7aee3bde8c9f73c830f9e25e75e7fcaa41be
MD5 a3db712a392a3bbf582c5aea2c36cef0
BLAKE2b-256 02e03d23cd03637c91e04da878c68643de716f5d1911b318766fdde5cc22ac7d

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