Skip to content

Commit

Permalink
fix: append .plain.html in redirects if needed (#452)
Browse files Browse the repository at this point in the history
fixes #451
  • Loading branch information
tripodsan authored Nov 9, 2023
1 parent be10e93 commit d3035a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/steps/fetch-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ export default async function fetchContent(state, req, res) {
const ret = await state.s3Loader.getObject(bucketId, key);

// check for redirect
const redirectLocation = ret.headers.get('x-amz-meta-redirect-location');
let redirectLocation = ret.headers.get('x-amz-meta-redirect-location');
if (redirectLocation) {
res.status = 301;
res.body = '';
if (redirectLocation.startsWith('/') && state.info.selector === 'plain') {
redirectLocation += '.plain.html';
}
res.headers.set('location', redirectLocation);
res.headers.set('x-surrogate-key', await computeSurrogateKey(`${contentBusId}${info.path}`));
res.error = 'moved';
Expand Down
6 changes: 6 additions & 0 deletions test/rendering.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ describe('Rendering', () => {
assert.strictEqual(ret.headers.get('location'), 'https://www.adobe.com');
});

it('appends .plain.html in redirects', async () => {
loader.headers('one-section.md', 'x-amz-meta-redirect-location', '/foo');
const ret = await render(new URL('https://localhost/one-section'), '.plain', 301);
assert.strictEqual(ret.headers.get('location'), '/foo.plain.html');
});

it('respect folder mapping: skip if no config', async () => {
loader.rewrite('helix-config.json', 'helix-config-no-head.json');
loader.status('products.md', 404);
Expand Down

0 comments on commit d3035a1

Please sign in to comment.