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:
parent
5848d97867
commit
7f956f0795
4 changed files with 36 additions and 1 deletions
16
.changeset/funny-cats-sell.md
Normal file
16
.changeset/funny-cats-sell.md
Normal 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.
|
|
@ -29,7 +29,8 @@ export function print(
|
|||
' '.repeat(inputSpaces) +
|
||||
definition.target +
|
||||
' '.repeat(Math.abs(targetSpaces)) +
|
||||
definition.status;
|
||||
definition.status +
|
||||
(definition.force ? '!' : '');
|
||||
}
|
||||
|
||||
return _redirects;
|
||||
|
|
|
@ -9,6 +9,7 @@ export type RedirectDefinition = {
|
|||
// a priority once inserted.
|
||||
weight: number;
|
||||
status: number;
|
||||
force?: number;
|
||||
};
|
||||
|
||||
export class Redirects {
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue