-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: redirects.yaml #11085
Comments
I've been using Ghost for over a year, it's probably time to give something back; I'll take this on! |
…as a fallback refs TryGhost#11085 No migration tool, that will still take some doing.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This feature has almost been finished with #11218, easy candidate for somebody from the community to pick up 😉 |
Yeah, that's my bad; winter got weird IRL. If nobody else picks it up I'll see where I can get this weekend. |
I'm getting a bit caught up on the unit testing framework, although the configuration work went OK. |
@Assisting let me know if I could help with any guidance and feel free to ask any related questions 😉 |
@sainthkh to be clear, think it would be best if we wrap up current PR with the scope it already touched. We can add the aliasing proposed here and more improvements in future iterations. Wanted to avoid bloating with features as the branch has been running for long enough already :) |
Right. I agree with you. It seems that we can organize leftover todos in this way. Current PRs
Future PRs
Maybe
|
issue TryGhost#11085 startGhost test util function copies yaml file when a redirectsFileExt option is given.
issue TryGhost#11085 The parsing code inside custom-redirects.js has been moved to frontend/services/redirects/seetings.js. I found that it was already imported in the file.
@naz all things clear. Waiting for review and merge. |
closes #11085 - Ghost has been using YAML format for other configurations (e.g. routes). The plan is to move to this format for all user-edited settings files. By default JSON format is still used in Ghost Admin API v2/v3, but will be changed to YAML in API v4. Check referenced issue for more context. - New format supports all the features available before. The main noticeable change is the structure of config file. It is now grouped by redirect HTTP code instead of specifying `"permanent": true | false` attribute for each config property. Example format for YAML config: ``` 302: /from-url/: /to-url/ 301: /category/([a-z0-9\-]+)/i: /tag/$1/ /v([0-9\.]+)/docs/([a-z0-9\-]+)/i: /docs/$2/ ``` - Added 2 new endpoints: `POST redirects/upload` and `GET redirects/download`. These serve as an alias to current GET/POST `/redirects/json. "upload/download" naming pattern is introduced to match the convention with other resources that can be uploaded and downloaded (images, themes etc.). `/redirects/json` endpoints will be removed in Admin API v4 - The parsing code from `custom-redirects.js` has been moved to `frontend/services/redirects/settings.js`. This location is more appropriate for this logic and eventually `custom-redirects.js` middlewear might be moved into "frontend" as this middlewear plays a role mostly effecting that area.
refs #11085 - The logic which uses this error deals with an input yaml file thus the change. - Related discussion here - #12187 (comment)
refs #11085 - Incorrect usage error was logged to the output when there was no recirecst configuration file present in the system. Previously an empty string was returned in such situation, resulting in "ENOENT" error, which was ignored through special handling. - The fix resembles logic in redirects async getter function where empty array is returned when the config file does not exits. - Attempting to read unexistent config should not ever happen and will be handled on the config service layer, this is why special "ENOENT" handling has been removed
refs TryGhost/Ghost#11085 refs TryGhost/Ghost#12187 - YAML file support has been added to Ghost's API through referenced above PR. YAML will become a default supported file in the next version of Ghost replacing JSON redirects
Our redirect feature is cool and powerful, but having to correctly format a JSON file by hand is HORRIBLE.
We are now using YAML for user-edited settings files, we should do that for redirects as well.
Ref material
Our current JSON redirects format looks like:
from
fieldto
field.i
flag to the end of thefrom
path, e.g."from": "/my-url/i"
which makes it do a case insensitive match.Statamic have a similar feature, provided in YAML: https://docs.statamic.com/routing#redirects
Netlify use a tab separated values style: https://www.netlify.com/docs/redirects/
Spec
We will add support for uploading a redirects file called
redirects.yaml
. The file must contain valid YAML.Redirects will apply to the web application of Ghost only (same as now).
This new file will support all the same features as the old redirects.json format but in an easier to write and maintain style. The main change is that instead of a property, the type of redirect is specified via one of two top-level keys.
Full example:
Migration
For now we should just support both formats. In the next major version we can drop support for uploading the JSON format.
We may be able to write a migration for a major upgrade using something like https://www.npmjs.com/package/json2yaml
However JSON is valid YAML 🤔
The text was updated successfully, but these errors were encountered: