Skip to content

Commit 94fcc72

Browse files
NetdocsCopilot
andcommitted
docs(redirects): document redirect_files bulk JSON option
Explain the new `redirect_files` option, both accepted JSON shapes (object map and array of source/target objects), path resolution, and precedence with inline `redirect_maps`. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 39a5ded commit 94fcc72

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

docs-site/docs/plugins/redirects.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ for vanity links and for preserving inbound links after restructuring.
1111

1212
| Option | Type | Default | Description |
1313
|---|---|---|---|
14-
| `redirect_maps` | object || Map of source path → destination URL. |
14+
| `redirect_maps` | object || Inline map of source path → destination URL. |
15+
| `redirect_files` | string \| array || One or more JSON files holding bulk redirects. |
1516

1617
```json
1718
{
@@ -28,6 +29,49 @@ for vanity links and for preserving inbound links after restructuring.
2829
Each key becomes an HTML page (e.g. `site/discord/index.html`) that immediately redirects
2930
to the mapped destination. Destinations may be absolute URLs or site-relative paths.
3031

32+
## Bulk redirects from JSON file(s)
33+
34+
Inline maps are convenient for a handful of entries, but migration redirect tables can run
35+
to hundreds of rows. Keep those in one or more JSON files and point `redirect_files` at them.
36+
The value may be a single path or an array of paths. Paths resolve against the project root
37+
first, then the docs directory, then as an absolute path.
38+
39+
```json
40+
{
41+
"name": "redirects",
42+
"options": {
43+
"redirect_files": ["redirects/blog.json", "redirects/legacy.json"]
44+
}
45+
}
46+
```
47+
48+
Each file may use either shape:
49+
50+
**Object map** — source path → destination URL:
51+
52+
```json
53+
{
54+
"blog/2018/ls--how-to-turn-on-the-alternator/": "/blog/2018/ls-how-to-turn-on-the-alternator/",
55+
"old/page/": "/new/page/"
56+
}
57+
```
58+
59+
**Array of objects**`source`/`target` (aliases `from`/`to` and `old`/`new` are also
60+
accepted). An optional `status` field is allowed for documentation/tooling but is ignored
61+
by the client-side redirect (a `meta refresh` cannot set an HTTP status code):
62+
63+
```json
64+
[
65+
{ "source": "old/x/", "target": "/new/x/", "status": 308 },
66+
{ "from": "old/y/", "to": "/new/y/" }
67+
]
68+
```
69+
70+
Files load first, then inline `redirect_maps` — so an inline entry overrides a file entry
71+
with the same source. Sources with a leading slash are normalized relative to the site
72+
directory. A missing or malformed file logs a warning and is skipped rather than failing the
73+
build.
74+
3175
## Attribution
3276

3377
Behavior is modeled on [mkdocs-redirects](https://github.com/mkdocs/mkdocs-redirects) (MIT). See [Attributions](../about/attributions.md).

0 commit comments

Comments
 (0)