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 page with one command.
In my case, I use this CLI tool in the project's CI pipelines before publishing the site to the gh-pages branch.
Getting started
Requirements
- Python >= 3.7
- pip
Installation
pip install redirects_cli
Quickstart
redirects-cli --help
Usage
Generate redirects from a static file
To generate static redirects from a YAML file:
-
Define the redirects in a new file named
redirects.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 -
Run the command:
redirects-cli fromfile --yaml-file redirects.yaml --output-dir htmlThe CLI creates the static redirects you have defined in the
redirects.yamlfile within the folderhtml. For this example, it creates the following folder structure:my-project/ ├─ html/ │ ├─ original-path/page-a.html │ ├─ original-path/page-b.html ├─ redirects.yaml
Create a single redirect
To create a single redirect, you can run the command:
redirects-cli --output-file index.html --redirect-to https://davidgarcia.dev
This command creates a 301 redirect to https://davidgarcia.devin the file index.html.
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.
Release files for redirects_cli 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| redirects_cli-0.1.3.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| redirects_cli-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / redirects_cli-0.1.3.tar.gz
| Download URL | redirects_cli-0.1.3.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0cc6f35ae372d087d56bc03cfc639d6e2eac0771454c3c173ac6f3dc233969bc
|
|
BLAKE2b-256 checksum How to use checksums |
f03e942a3d5322f05aa75c903de1bdc101800cc0627e4c6c371768ef9070fa28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.1
|
Release files / redirects_cli-0.1.3-py3-none-any.whl
| Download URL | redirects_cli-0.1.3-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a7a548d5f45b98db7d110fd8affbbb44b966cf250e35b5f4c9bd6541622272d
|
|
BLAKE2b-256 checksum How to use checksums |
3ea4829d6901e0c2c492d0d46190aadf3f4b9c6db6594b4e14a814f844014b28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-requests/2.25.1
|