Skip to content

Commit 340b291

Browse files
authored
fix: respect last-modified from mapped metadata
fixes #737
1 parent 69dc34f commit 340b291

File tree

13 files changed

+104
-27
lines changed

13 files changed

+104
-27
lines changed

src/html-pipe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export async function htmlPipe(state, req) {
131131
state.timer?.update('metadata-fetch');
132132
await Promise.all([
133133
contentPromise,
134-
fetchMappedMetadata(state),
134+
fetchMappedMetadata(state, res),
135135
]);
136136

137137
if (res.error) {

src/steps/fetch-mapped-metadata.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import { PipelineStatusError } from '../PipelineStatusError.js';
1414
import { Modifiers } from '../utils/modifiers.js';
15+
import { extractLastModified, updateLastModified } from '../utils/last-modified.js';
1516

1617
/**
1718
* Loads metadata for a mapped path and puts it into `state.mappedMetadata`. If path is not
@@ -20,9 +21,10 @@ import { Modifiers } from '../utils/modifiers.js';
2021
*
2122
* @type PipelineStep
2223
* @param {PipelineState} state
24+
* @param {PipelineResponse} res
2325
* @returns {Promise<void>}
2426
*/
25-
export default async function fetchMappedMetadata(state) {
27+
export default async function fetchMappedMetadata(state, res) {
2628
state.mappedMetadata = Modifiers.EMPTY;
2729
if (!state.mapped) {
2830
return;
@@ -51,6 +53,7 @@ export default async function fetchMappedMetadata(state) {
5153
state.mappedMetadata = Modifiers.fromModifierSheet(
5254
data,
5355
);
56+
updateLastModified(state, res, extractLastModified(ret.headers));
5457
return;
5558
}
5659
if (ret.status !== 404) {

test/FileS3Loader.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,14 @@ export class FileS3Loader {
5353
if (!dir) {
5454
throw Error(`unknown bucketId: ${bucketId}`);
5555
}
56-
// eslint-disable-next-line no-console
57-
let fileName = key.split('/').pop();
56+
let fileName = key.split('/').slice(2).join('/');
5857

5958
fileName = this.rewrites.reduce((result, rewrite) => rewrite(key) || result, null) || fileName;
6059
const status = this.statusCodeOverrides[fileName];
6160
const headers = this.headerOverride[fileName] ?? new Map();
6261
if (status) {
6362
// eslint-disable-next-line no-console
64-
console.log(`FileS3Loader: loading ${bucketId}/${key} -> ${status}`);
63+
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> ${status}`);
6564
return {
6665
status,
6766
body: '',
@@ -73,7 +72,7 @@ export class FileS3Loader {
7372
try {
7473
const body = await readFile(file, 'utf-8');
7574
// eslint-disable-next-line no-console
76-
console.log(`FileS3Loader: loading ${bucketId}/${key} -> 200`);
75+
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> 200`);
7776
return {
7877
status: 200,
7978
body,
@@ -86,7 +85,7 @@ export class FileS3Loader {
8685
};
8786
} catch (e) {
8887
// eslint-disable-next-line no-console
89-
console.log(`FileS3Loader: loading ${bucketId}/${key} -> 404 (${e.message})`);
88+
console.log(`FileS3Loader: loading ${bucketId}/${fileName} -> 404 (${e.message})`);
9089
return {
9190
status: 404,
9291
body: '',

test/fixtures/content/blog/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- this is a test document -->
2+
# Hello
3+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
":version": 3,
3+
":type": "multi-sheet",
4+
":names": [
5+
"default"
6+
],
7+
"default": {
8+
"total": 2,
9+
"offset": 0,
10+
"limit": 2,
11+
"data": [
12+
{
13+
"URL": "/page-*",
14+
"Category": "rendering-test"
15+
},
16+
{
17+
"url": "**/page-*-blocks",
18+
"Glob Test": "match ** and * combo"
19+
},
20+
{
21+
"Url": "**/marketing/**",
22+
"Category": "Marketing"
23+
},
24+
{
25+
"URL": "/page-metadata-json.html",
26+
"Image": "/media_cf867e391c0b433ec3d416c979aafa1f8e4aae9c.png",
27+
"Keywords": "Baz, Bar, Foo",
28+
"og:publisher": "Adobe"
29+
},
30+
{
31+
"URL": "/page-metadata-json",
32+
"Image": "/media_cf867e391c0b433ec3d416c979aafa1f8e4aae9c.png",
33+
"Keywords": "Baz, Bar, Foo",
34+
"og:publisher": "Adobe"
35+
},
36+
{
37+
"URL": "/exact-match.html",
38+
"Keywords": "Exactomento",
39+
"og:publisher": "Adobe",
40+
"Short Title": "E"
41+
},
42+
{
43+
"URL": "/page-metadata-block",
44+
"Short Title": "global-meta"
45+
},
46+
{
47+
"URL": "/exact-match",
48+
"Keywords": "Exactomento",
49+
"og:publisher": "Adobe",
50+
"Short Title": "E"
51+
},
52+
{
53+
"URL": "/exact-folder/",
54+
"Keywords": "Exactomento Folder",
55+
"og:publisher": "Adobe",
56+
"Short Title": "E"
57+
},
58+
{
59+
"URL": "/products**",
60+
"Keywords": "Exactomento Mapped Folder",
61+
"og:publisher": "Adobe",
62+
"Short Title": "E"
63+
}
64+
]
65+
}
66+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<!-- this is a test document -->
2+
# Hello
3+

0 commit comments

Comments
 (0)