mkdocs / mkdocs-redirects

Open source plugin for Mkdocs page redirects
MIT License
176 stars 25 forks source link

Frontmatter-based redirects? #53

Open Andre601 opened 1 year ago

Andre601 commented 1 year ago

Personally, I feel like it could be a nice feature to allow defining redirects in a file's yaml frontmatter.

As an example:

---
title: Title
description: Some page.

redirects:
  - old/location/index.md
---

# Title

Content

The benefits I see:

It's just a random idea that came to mind.

kamilkrzyskow commented 1 year ago

I'll re-post the answer I've given here: https://github.com/mkdocs/mkdocs/discussions/3134

Here you go, https://github.com/kamilkrzyskow/gmc/commits/redirect-plugin?since=2023-02-24 that was my previous approach with another hook and old_nav meta list of old paths. However, I decided against it because moving a whole directory of files into another location requires modifying all of those files, and this just sullies the Git Blame imo, and is rather tedious to do (trust me, I took it till the end and modified 40 files by hand).

The idea came from the solution here https://github.com/squidfunk/mkdocs-material/discussions/3758 the difference here, which is VERY important is that the ContextID is static, possibly managed by some outside tooling and database, so the files can move however they want and the redirection will always point to the correct path, this doesn't go well with manually readjusting the "ContextID" equivalent after each move.