0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

feat(underscore-redirects): add support for force (#11271)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
Florian Lefebvre 2024-06-20 16:18:39 +02:00 committed by GitHub
parent 5848d97867
commit 7f956f0795
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,16 @@
---
'@astrojs/underscore-redirects': patch
---
Adds support for forced redirects
Redirects can be forced by setting `force` to `true`:
```ts
redirects.add({
// ...
force: true
})
```
It will append a `!` after the status.

View file

@ -29,7 +29,8 @@ export function print(
' '.repeat(inputSpaces) +
definition.target +
' '.repeat(Math.abs(targetSpaces)) +
definition.status;
definition.status +
(definition.force ? '!' : '');
}
return _redirects;

View file

@ -9,6 +9,7 @@ export type RedirectDefinition = {
// a priority once inserted.
weight: number;
status: number;
force?: number;
};
export class Redirects {

View file

@ -47,4 +47,21 @@ describe('Printing', () => {
const expectedParts = ['/pets/:cat', '/pets/:cat/index.html', '200'];
assert.deepEqual(parts, expectedParts);
});
it('Properly handles force redirects', () => {
const _redirects = new Redirects();
_redirects.add({
dynamic: false,
input: '/a',
target: '/b',
status: 200,
weight: 1,
force: true
});
let out = _redirects.print();
let parts = out.split(/\s+/);
const expectedParts = ['/a', '/b', '200!'];
assert.deepEqual(parts, expectedParts);
})
});