Skip to content

Commit 5e29919

Browse files
fix: provide either (prefixed) preview or (unprefixed) live content keys
1 parent 24dbd2b commit 5e29919

File tree

7 files changed

+38
-80
lines changed

7 files changed

+38
-80
lines changed

src/json-pipe.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,10 @@ async function fetchJsonContent(state, req, res) {
6363
res.headers.set('location', redirectLocation);
6464
const keys = [];
6565
if (state.content.sourceBus === 'content') {
66-
keys.push(await computeSurrogateKey(`${contentBusId}${info.path}`));
67-
keys.push(contentBusId);
66+
// provide either (prefixed) preview or (unprefixed) live content keys
6867
const contentKeyPrefix = partition === 'preview' ? 'p_' : '';
69-
if (partition === 'preview') {
70-
// temporarily provide additional preview content keys
71-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
72-
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${contentBusId}${info.path}`)}`);
73-
keys.push(`${contentKeyPrefix}${contentBusId}`);
74-
}
68+
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${contentBusId}${info.path}`)}`);
69+
keys.push(`${contentKeyPrefix}${contentBusId}`);
7570
} else {
7671
keys.push(`${ref}--${repo}--${owner}_code`);
7772
keys.push(await computeSurrogateKey(`${ref}--${repo}--${owner}${info.path}`));
@@ -109,15 +104,10 @@ async function computeSurrogateKeys(state) {
109104
keys.push(`${state.ref}--${state.repo}--${state.owner}_code`);
110105
}
111106
if (state.content.sourceBus.includes('content')) {
112-
keys.push(await computeSurrogateKey(`${state.contentBusId}${state.info.path}`));
113-
keys.push(state.contentBusId);
107+
// provide either (prefixed) preview or (unprefixed) live content keys
114108
const contentKeyPrefix = state.partition === 'preview' ? 'p_' : '';
115-
if (state.partition === 'preview') {
116-
// temporarily provide additional preview content keys
117-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
118-
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${state.contentBusId}${state.info.path}`)}`);
119-
keys.push(`${contentKeyPrefix}${state.contentBusId}`);
120-
}
109+
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${state.contentBusId}${state.info.path}`)}`);
110+
keys.push(`${contentKeyPrefix}${state.contentBusId}`);
121111
}
122112

123113
return keys;

src/steps/fetch-404.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,21 @@ export default async function fetch404(state, req, res) {
4040

4141
// set 404 keys in any case
4242
const pathKey = await getPathKey(state);
43+
// provide either (prefixed) preview or (unprefixed) live content keys
44+
const contentKeyPrefix = partition === 'preview' ? 'p_' : '';
4345
const keys = [
44-
pathKey,
45-
contentBusId,
46+
`${contentKeyPrefix}${pathKey}`,
47+
`${contentKeyPrefix}${contentBusId}`,
4648
`${ref}--${repo}--${owner}_404`,
4749
`${ref}--${repo}--${owner}_code`,
4850
];
49-
const contentKeyPrefix = partition === 'preview' ? 'p_' : '';
50-
if (partition === 'preview') {
51-
// temporarily provide additional preview content keys
52-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
53-
keys.push(`${contentKeyPrefix}${pathKey}`);
54-
keys.push(`${contentKeyPrefix}${contentBusId}`);
55-
}
5651

5752
if (state.info.unmappedPath) {
5853
const unmappedPathKey = await getPathKey({
5954
contentBusId,
6055
info: { path: state.info.unmappedPath },
6156
});
62-
keys.push(unmappedPathKey);
63-
if (partition === 'preview') {
64-
// temporarily provide additional preview content key
65-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content key
66-
keys.push(`${contentKeyPrefix}${unmappedPathKey}`);
67-
}
57+
keys.push(`${contentKeyPrefix}${unmappedPathKey}`);
6858
}
6959

7060
res.headers.set('x-surrogate-key', keys.join(' '));

src/steps/fetch-content.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,10 @@ export default async function fetchContent(state, req, res) {
4646
keys.push(await computeSurrogateKey(`${ref}--${repo}--${owner}${info.path}`));
4747
keys.push(`${ref}--${repo}--${owner}_code`);
4848
} else {
49-
keys.push(await computeSurrogateKey(`${contentBusId}${info.path}`));
50-
keys.push(contentBusId);
49+
// provide either (prefixed) preview or (unprefixed) live content keys
5150
const contentKeyPrefix = partition === 'preview' ? 'p_' : '';
52-
if (partition === 'preview') {
53-
// temporarily provide additional preview content keys
54-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
55-
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${contentBusId}${info.path}`)}`);
56-
keys.push(`${contentKeyPrefix}${contentBusId}`);
57-
}
51+
keys.push(`${contentKeyPrefix}${await computeSurrogateKey(`${contentBusId}${info.path}`)}`);
52+
keys.push(`${contentKeyPrefix}${contentBusId}`);
5853
}
5954
res.headers.set('x-surrogate-key', keys.join(' '));
6055
res.error = 'moved';

src/steps/set-x-surrogate-key-header.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,27 @@ export default async function setXSurrogateKeyHeader(state, req, res) {
4747

4848
const isCode = state.content.sourceBus === 'code';
4949

50+
// provide either (prefixed) preview or (unprefixed) live content keys
5051
const contentKeyPrefix = partition === 'preview' ? 'p_' : '';
5152
const keys = [];
5253
const hash = await getPathKey(state);
5354
if (isCode) {
5455
keys.push(await computeSurrogateKey(`${ref}--${repo}--${owner}${state.info.path}`));
5556
keys.push(`${ref}--${repo}--${owner}_code`);
5657
} else {
57-
keys.push(hash);
58-
keys.push(`${contentBusId}_metadata`);
58+
keys.push(`${contentKeyPrefix}${hash}`);
59+
keys.push(`${contentKeyPrefix}${contentBusId}_metadata`);
5960
keys.push(`${ref}--${repo}--${owner}_head`);
60-
keys.push(contentBusId);
61-
if (partition === 'preview') {
62-
// temporarily provide additional preview content keys
63-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
64-
keys.push(`${contentKeyPrefix}${hash}`);
65-
keys.push(`${contentKeyPrefix}${contentBusId}_metadata`);
66-
keys.push(`${contentKeyPrefix}${contentBusId}`);
67-
}
61+
keys.push(`${contentKeyPrefix}${contentBusId}`);
6862
}
6963
// for folder-mapped resources, we also need to include the surrogate key of the mapped metadata
7064
if (state.mapped) {
71-
keys.push(`${hash}_metadata`);
65+
keys.push(`${contentKeyPrefix}${hash}_metadata`);
7266
if (state.info.unmappedPath) {
73-
keys.push(await getPathKey({
67+
keys.push(`${contentKeyPrefix}${await getPathKey({
7468
contentBusId,
7569
info: { path: state.info.unmappedPath },
76-
}));
77-
}
78-
if (partition === 'preview') {
79-
// temporarily provide additional preview content keys
80-
// TODO: eventually provide either (prefixed) preview or (unprefixed) live content keys
81-
keys.push(`${contentKeyPrefix}${hash}_metadata`);
82-
if (state.info.unmappedPath) {
83-
keys.push(`${contentKeyPrefix}${await getPathKey({
84-
contentBusId,
85-
info: { path: state.info.unmappedPath },
86-
})}`);
87-
}
70+
})}`);
8871
}
8972
}
9073
res.headers.set('x-surrogate-key', keys.join(' '));

test/json-pipe.test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe('JSON Pipe Test', () => {
148148
});
149149
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
150150
'content-type': 'application/json',
151-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
151+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
152152
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
153153
});
154154
// live (code coverage)
@@ -175,7 +175,7 @@ describe('JSON Pipe Test', () => {
175175
assert.strictEqual(resp.status, 404);
176176
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
177177
'x-error': 'failed to load /config.json: 404',
178-
'x-surrogate-key': 'U_NW4adJU7Qazf-I pzrU-nNKQOUYNTEf ref--repo--owner_code kz8SoCaNqfp4ohQo foobar p_kz8SoCaNqfp4ohQo p_foobar',
178+
'x-surrogate-key': 'U_NW4adJU7Qazf-I pzrU-nNKQOUYNTEf ref--repo--owner_code p_kz8SoCaNqfp4ohQo p_foobar',
179179
});
180180
});
181181

@@ -192,7 +192,7 @@ describe('JSON Pipe Test', () => {
192192
assert.strictEqual(resp.status, 200);
193193
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
194194
'content-type': 'application/json',
195-
'x-surrogate-key': 'U_NW4adJU7Qazf-I pzrU-nNKQOUYNTEf ref--repo--owner_code kz8SoCaNqfp4ohQo foobar p_kz8SoCaNqfp4ohQo p_foobar',
195+
'x-surrogate-key': 'U_NW4adJU7Qazf-I pzrU-nNKQOUYNTEf ref--repo--owner_code p_kz8SoCaNqfp4ohQo p_foobar',
196196
});
197197
assert.deepStrictEqual(await resp.json(), {
198198
public: {
@@ -220,7 +220,7 @@ describe('JSON Pipe Test', () => {
220220
});
221221
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
222222
'content-type': 'application/json',
223-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
223+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
224224
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
225225
});
226226
});
@@ -241,7 +241,7 @@ describe('JSON Pipe Test', () => {
241241
'access-control-allow-origin': '*',
242242
'content-security-policy': 'default-src \'self\'',
243243
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
244-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
244+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
245245
'content-type': 'application/json',
246246
});
247247
});
@@ -256,7 +256,7 @@ describe('JSON Pipe Test', () => {
256256
'access-control-allow-origin': '*',
257257
'content-security-policy': 'default-src \'self\'',
258258
'x-error': 'failed to load /en/index.json: 404',
259-
'x-surrogate-key': 'SIMSxecp2CJXqGYs ref--repo--owner_code Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
259+
'x-surrogate-key': 'SIMSxecp2CJXqGYs ref--repo--owner_code p_Atrz_qDg26DmSe9a p_foobar',
260260
});
261261
});
262262

@@ -286,7 +286,7 @@ describe('JSON Pipe Test', () => {
286286
assert.strictEqual(resp.status, 301);
287287
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
288288
'location': '/de/index.json',
289-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
289+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
290290
});
291291
// live (code coverage)
292292
state.partition = 'live';
@@ -346,7 +346,7 @@ describe('JSON Pipe Test', () => {
346346
const headers = Object.fromEntries(resp.headers.entries());
347347
assert.deepStrictEqual(headers, {
348348
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
349-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
349+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
350350
'content-type': 'application/json',
351351
});
352352
});
@@ -378,7 +378,7 @@ describe('JSON Pipe Test', () => {
378378
const headers = Object.fromEntries(resp.headers.entries());
379379
assert.deepStrictEqual(headers, {
380380
'last-modified': 'Wed, 12 Oct 2009 15:50:00 GMT',
381-
'x-surrogate-key': 'Atrz_qDg26DmSe9a foobar p_Atrz_qDg26DmSe9a p_foobar',
381+
'x-surrogate-key': 'p_Atrz_qDg26DmSe9a p_foobar',
382382
'content-type': 'application/json',
383383
});
384384
});

test/rendering.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ describe('Rendering', () => {
602602
'content-type': 'text/html; charset=utf-8',
603603
link: '</scripts/scripts.js>; rel=modulepreload; as=script; crossorigin=use-credentials',
604604
'x-error': 'failed to load /not-a-page.md from content-bus: 404',
605-
'x-surrogate-key': 'gPHXKWdMY_R8KV2Z foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code p_gPHXKWdMY_R8KV2Z p_foo-id QJqsV4atnOA47sHc p_QJqsV4atnOA47sHc',
605+
'x-surrogate-key': 'p_gPHXKWdMY_R8KV2Z p_foo-id super-test--helix-pages--adobe_404 super-test--helix-pages--adobe_code p_QJqsV4atnOA47sHc',
606606
});
607607
assert.strictEqual(resp.body.trim(), '');
608608
});
@@ -615,7 +615,7 @@ describe('Rendering', () => {
615615
// preview (code coverage)
616616
resp = await render(new URL('https://localhost/one-section'), '', 301, 'preview');
617617
assert.strictEqual(resp.headers.get('location'), 'https://www.adobe.com');
618-
assert.strictEqual(resp.headers.get('x-surrogate-key'), 'oHjg_WDu20CBS4rD foo-id p_oHjg_WDu20CBS4rD p_foo-id');
618+
assert.strictEqual(resp.headers.get('x-surrogate-key'), 'p_oHjg_WDu20CBS4rD p_foo-id');
619619
});
620620

621621
it('appends .plain.html in redirects', async () => {

test/sitemap-pipe.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Sitemap Pipe Test', () => {
7474
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
7575
'content-type': 'text/plain; charset=utf-8',
7676
'x-error': 'failed to load /sitemap.xml from content-bus: 404',
77-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
77+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
7878
});
7979
});
8080

@@ -92,7 +92,7 @@ describe('Sitemap Pipe Test', () => {
9292
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
9393
'content-type': 'text/plain; charset=utf-8',
9494
'x-error': 'Failed to parse /sitemap.json: Unexpected token \'h\', "this is not JSON" is not valid JSON',
95-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
95+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
9696
});
9797
});
9898

@@ -110,7 +110,7 @@ describe('Sitemap Pipe Test', () => {
110110
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
111111
'content-type': 'text/plain; charset=utf-8',
112112
'x-error': "Expected 'data' array not found in /sitemap.json",
113-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
113+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
114114
});
115115
});
116116

@@ -128,7 +128,7 @@ describe('Sitemap Pipe Test', () => {
128128
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
129129
'content-type': 'application/xml; charset=utf-8',
130130
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
131-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
131+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
132132
});
133133
assert.strictEqual(resp.body, `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
134134
<url>
@@ -154,7 +154,7 @@ describe('Sitemap Pipe Test', () => {
154154
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
155155
'content-type': 'application/xml; charset=utf-8',
156156
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
157-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
157+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
158158
});
159159
assert.strictEqual(resp.body, `<?xml version="1.0" encoding="utf-8"?>
160160
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
@@ -191,7 +191,7 @@ describe('Sitemap Pipe Test', () => {
191191
assert.deepStrictEqual(Object.fromEntries(resp.headers.entries()), {
192192
'content-type': 'application/xml; charset=utf-8',
193193
'last-modified': 'Fri, 30 Apr 2021 03:47:18 GMT',
194-
'x-surrogate-key': 'RXei-6EcTEMTEIqi foobar_metadata ref--repo--owner_head foobar p_RXei-6EcTEMTEIqi p_foobar_metadata p_foobar',
194+
'x-surrogate-key': 'p_RXei-6EcTEMTEIqi p_foobar_metadata ref--repo--owner_head p_foobar',
195195
});
196196
assert.strictEqual(resp.body, `<?xml version="1.0" encoding="utf-8"?>
197197
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">

0 commit comments

Comments
 (0)