GitXplorerGitXplorer
d

redirects-cli

public
1 stars
0 forks
1 issues

Commits

List of commits on branch main.
Unverified
0716c1750df15081363a0a5c4bad4e713e0f03c2

Raise warning if file does not exist

ddgarcia360 committed 2 years ago
Verified
abb913bfe8a9db2da28400f605080338a3282290

Update README.md

ddgarcia360 committed 2 years ago
Verified
d2e95639ccfd9341b0f3f76247dcd8cdc77041a1

Update README.md

ddgarcia360 committed 3 years ago
Verified
75385a52fb53f4916525c3057025d2111f9e2cb1

Merge pull request #1 from dgarcia360/dependabot/github_actions/actions/setup-python-4

ddgarcia360 committed 3 years ago
Verified
7f6b30075db877bd42535a7d1dd121acb1550020

Bump actions/setup-python from 3 to 4

ddependabot[bot] committed 3 years ago
Unverified
e197f621e66df73e1edc4ee6af806d89817bda4c

Add redirects-cli

ddgarcia360 committed 3 years ago

README

The README file for this repository.

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:

  1. 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
    
  2. Run the command:

    redirects-cli fromfile --yaml-file redirects.yaml --output-dir html
    

    The CLI creates the static redirects you have defined in the redirects.yaml file within the folder html. 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 create --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.