Skip to content

last modified fixes #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ async function readPages(root: string): Promise<Page[]> {
return pages;
}

let currentDate = new Date();
globalThis.currentDate = new Date();

export function setCurrentDate(date = new Date()): void {
currentDate = date;
globalThis.currentDate = date;
}

export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Promise<Config> {
Expand All @@ -94,8 +94,8 @@ export async function normalizeConfig(spec: any = {}, defaultRoot = "docs"): Pro
head = "",
header = "",
footer = `Built with <a href="https://observablehq.com/" target="_blank">Observable</a> on <a title="${formatIsoDate(
currentDate
)}">${formatLocaleDate(currentDate)}</a>.`
globalThis.currentDate
)}">${formatLocaleDate(globalThis.currentDate)}</a>.`
} = spec;
root = String(root);
output = String(output);
Expand Down
5 changes: 4 additions & 1 deletion src/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function fileReference(name: string, root: string, sourcePath: string): F
name: relativeUrl(sourcePath, name),
mimeType: mime.getType(name),
path: relativeUrl(sourcePath, join("_file", name)),
lastModified: maybeLastModified(join(root, resolvePath(sourcePath, name)))
lastModified:
maybeLastModified(join(root, resolvePath(sourcePath, "/" + name))) ??
maybeLastModified(join(root, ".observablehq", "cache", resolvePath(sourcePath, "/" + name))) ??
+globalThis.currentDate
};
}

Expand Down
20 changes: 10 additions & 10 deletions test/markdown-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe("normalizePieceHtml adds local file attachments", () => {
mimeType: "image/png",
name: "./test.png",
path: "./_file/test.png",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand Down Expand Up @@ -106,13 +106,13 @@ describe("normalizePieceHtml adds local file attachments", () => {
mimeType: "image/jpeg",
name: "./large.jpg",
path: "./_file/large.jpg",
lastModified: undefined
lastModified: 1704963723000
},
{
mimeType: "image/jpeg",
name: "./small.jpg",
path: "./_file/small.jpg",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand All @@ -133,7 +133,7 @@ describe("normalizePieceHtml adds local file attachments", () => {
mimeType: "video/quicktime",
name: "./observable.mov",
path: "./_file/observable.mov",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand All @@ -160,13 +160,13 @@ describe("normalizePieceHtml adds local file attachments", () => {
mimeType: "video/mp4",
name: "./observable.mp4",
path: "./_file/observable.mp4",
lastModified: undefined
lastModified: 1704963723000
},
{
mimeType: "video/quicktime",
name: "./observable.mov",
path: "./_file/observable.mov",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand All @@ -191,13 +191,13 @@ describe("normalizePieceHtml adds local file attachments", () => {
mimeType: "image/png",
name: "./observable-logo-narrow.png",
path: "./_file/observable-logo-narrow.png",
lastModified: undefined
lastModified: 1704963723000
},
{
mimeType: "image/png",
name: "./observable-logo-wide.png",
path: "./_file/observable-logo-wide.png",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand Down Expand Up @@ -238,7 +238,7 @@ describe("normalizePieceHtml only adds local files", () => {
mimeType: "image/jpeg",
name: "./small.jpg",
path: "./_file/small.jpg",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand All @@ -265,7 +265,7 @@ describe("normalizePieceHtml only adds local files", () => {
mimeType: "video/quicktime",
name: "./observable.mov",
path: "./_file/observable.mov",
lastModified: undefined
lastModified: 1704963723000
}
]);
});
Expand Down
14 changes: 7 additions & 7 deletions test/output/build/archives/tar.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,43 @@

import {define} from "./_observablehq/client.js";

define({id: "d5134368", inputs: ["FileAttachment","display"], files: [{"name":"./static-tar/file.txt","mimeType":"text/plain","path":"./_file/static-tar/file.txt"}], body: async (FileAttachment,display) => {
define({id: "d5134368", inputs: ["FileAttachment","display"], files: [{"name":"./static-tar/file.txt","mimeType":"text/plain","path":"./_file/static-tar/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("static-tar/file.txt").text()
))
}});

define({id: "a0c06958", inputs: ["FileAttachment","display"], files: [{"name":"./static-tgz/file.txt","mimeType":"text/plain","path":"./_file/static-tgz/file.txt"}], body: async (FileAttachment,display) => {
define({id: "a0c06958", inputs: ["FileAttachment","display"], files: [{"name":"./static-tgz/file.txt","mimeType":"text/plain","path":"./_file/static-tgz/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("static-tgz/file.txt").text()
))
}});

define({id: "d84cd7fb", inputs: ["FileAttachment","display"], files: [{"name":"./static-tar/does-not-exist.txt","mimeType":"text/plain","path":"./_file/static-tar/does-not-exist.txt"}], body: async (FileAttachment,display) => {
define({id: "d84cd7fb", inputs: ["FileAttachment","display"], files: [{"name":"./static-tar/does-not-exist.txt","mimeType":"text/plain","path":"./_file/static-tar/does-not-exist.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("static-tar/does-not-exist.txt").text()
))
}});

define({id: "86bd51aa", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar/file.txt","mimeType":"text/plain","path":"./_file/dynamic-tar/file.txt"}], body: async (FileAttachment,display) => {
define({id: "86bd51aa", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar/file.txt","mimeType":"text/plain","path":"./_file/dynamic-tar/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic-tar/file.txt").text()
))
}});

define({id: "95938c22", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar/does-not-exist.txt","mimeType":"text/plain","path":"./_file/dynamic-tar/does-not-exist.txt"}], body: async (FileAttachment,display) => {
define({id: "95938c22", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar/does-not-exist.txt","mimeType":"text/plain","path":"./_file/dynamic-tar/does-not-exist.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic-tar/does-not-exist.txt").text()
))
}});

define({id: "7e5740fd", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar-gz/file.txt","mimeType":"text/plain","path":"./_file/dynamic-tar-gz/file.txt"}], body: async (FileAttachment,display) => {
define({id: "7e5740fd", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar-gz/file.txt","mimeType":"text/plain","path":"./_file/dynamic-tar-gz/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic-tar-gz/file.txt").text()
))
}});

define({id: "d0a58efd", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar-gz/does-not-exist.txt","mimeType":"text/plain","path":"./_file/dynamic-tar-gz/does-not-exist.txt"}], body: async (FileAttachment,display) => {
define({id: "d0a58efd", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic-tar-gz/does-not-exist.txt","mimeType":"text/plain","path":"./_file/dynamic-tar-gz/does-not-exist.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic-tar-gz/does-not-exist.txt").text()
))
Expand Down
8 changes: 4 additions & 4 deletions test/output/build/archives/zip.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@

import {define} from "./_observablehq/client.js";

define({id: "d3b9d0ee", inputs: ["FileAttachment","display"], files: [{"name":"./static/file.txt","mimeType":"text/plain","path":"./_file/static/file.txt"}], body: async (FileAttachment,display) => {
define({id: "d3b9d0ee", inputs: ["FileAttachment","display"], files: [{"name":"./static/file.txt","mimeType":"text/plain","path":"./_file/static/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("static/file.txt").text()
))
}});

define({id: "bab54217", inputs: ["FileAttachment","display"], files: [{"name":"./static/not-found.txt","mimeType":"text/plain","path":"./_file/static/not-found.txt"}], body: async (FileAttachment,display) => {
define({id: "bab54217", inputs: ["FileAttachment","display"], files: [{"name":"./static/not-found.txt","mimeType":"text/plain","path":"./_file/static/not-found.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("static/not-found.txt").text()
))
}});

define({id: "11eec300", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic/file.txt","mimeType":"text/plain","path":"./_file/dynamic/file.txt"}], body: async (FileAttachment,display) => {
define({id: "11eec300", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic/file.txt","mimeType":"text/plain","path":"./_file/dynamic/file.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic/file.txt").text()
))
}});

define({id: "ee2310f3", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic/not-found.txt","mimeType":"text/plain","path":"./_file/dynamic/not-found.txt"}], body: async (FileAttachment,display) => {
define({id: "ee2310f3", inputs: ["FileAttachment","display"], files: [{"name":"./dynamic/not-found.txt","mimeType":"text/plain","path":"./_file/dynamic/not-found.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
await FileAttachment("dynamic/not-found.txt").text()
))
Expand Down
4 changes: 2 additions & 2 deletions test/output/build/files/subsection/subfiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

import {define} from "../_observablehq/client.js";

define({id: "ef9a31ef", inputs: ["FileAttachment","display"], files: [{"name":"../file-top.csv","mimeType":"text/csv","path":"../_file/file-top.csv"}], body: async (FileAttachment,display) => {
define({id: "ef9a31ef", inputs: ["FileAttachment","display"], files: [{"name":"../file-top.csv","mimeType":"text/csv","path":"../_file/file-top.csv","lastModified":1729072800000}], body: async (FileAttachment,display) => {
display(await(
FileAttachment("../file-top.csv")
))
}});

define({id: "834ecf9f", inputs: ["FileAttachment","display"], files: [{"name":"./file-sub.csv","mimeType":"text/csv","path":"../_file/subsection/file-sub.csv"}], body: async (FileAttachment,display) => {
define({id: "834ecf9f", inputs: ["FileAttachment","display"], files: [{"name":"./file-sub.csv","mimeType":"text/csv","path":"../_file/subsection/file-sub.csv","lastModified":1729072800000}], body: async (FileAttachment,display) => {
display(await(
FileAttachment("file-sub.csv")
))
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/imports/foo/foo.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import {define} from "../_observablehq/client.js";

define({id: "261e010e", inputs: ["display","FileAttachment"], outputs: ["d3","bar","top"], files: [{"name":"../top.js","mimeType":"application/javascript","path":"../_file/top.js"}], body: async (display,FileAttachment) => {
define({id: "261e010e", inputs: ["display","FileAttachment"], outputs: ["d3","bar","top"], files: [{"name":"../top.js","mimeType":"application/javascript","path":"../_file/top.js","lastModified":1729072800000}], body: async (display,FileAttachment) => {
const [d3, {bar}, {top}] = await Promise.all([import("https://cdn.jsdelivr.net/npm/[email protected]/+esm"), import("../_import/bar/bar.js?sha=2e71da6918681d51fd9e7ed79b03aed514771c2e1583af42783665aff3f5ef5e"), import("../_import/top.js?sha=43e37c2a4fe9ca94e62d0d8acd5dbd8bdd5f0ec845503964f465979c4c82c2a3")]);

display(bar);
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/missing-file/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import {define} from "./_observablehq/client.js";

define({id: "5760fd93", inputs: ["FileAttachment","display"], files: [{"name":"./does-not-exist.txt","mimeType":"text/plain","path":"./_file/does-not-exist.txt"}], body: async (FileAttachment,display) => {
define({id: "5760fd93", inputs: ["FileAttachment","display"], files: [{"name":"./does-not-exist.txt","mimeType":"text/plain","path":"./_file/does-not-exist.txt","lastModified":1704931200000}], body: async (FileAttachment,display) => {
display(await(
FileAttachment("does-not-exist.txt")
))
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/simple/simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import {define} from "./_observablehq/client.js";

define({id: "115586ff", inputs: ["FileAttachment"], outputs: ["result"], files: [{"name":"./data.txt","mimeType":"text/plain","path":"./_file/data.txt"}], body: (FileAttachment) => {
define({id: "115586ff", inputs: ["FileAttachment"], outputs: ["result"], files: [{"name":"./data.txt","mimeType":"text/plain","path":"./_file/data.txt","lastModified":1704931200000}], body: (FileAttachment) => {
let result = FileAttachment("data.txt").text();
return {result};
}});
Expand Down
6 changes: 4 additions & 2 deletions test/output/fetch-parent-dir.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
{
"name": "./NOENT.md",
"mimeType": "text/markdown",
"path": "./_file/NOENT.md"
"path": "./_file/NOENT.md",
"lastModified": 1704963723000
},
{
"name": "./tex-expression.md",
Expand Down Expand Up @@ -88,7 +89,8 @@
{
"name": "./NOENT.md",
"mimeType": "text/markdown",
"path": "./_file/NOENT.md"
"path": "./_file/NOENT.md",
"lastModified": 1704963723000
}
],
"body": "(FileAttachment) => {\nconst fail3 = FileAttachment(\"./NOENT.md\").text()\nreturn {fail3};\n}"
Expand Down
2 changes: 1 addition & 1 deletion test/output/template-file-attachment.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
define({id: "0", inputs: ["FileAttachment"], files: [{"name":"./test.js","mimeType":"application/javascript","path":"./_file/test.js"}], body: (FileAttachment) => {
define({id: "0", inputs: ["FileAttachment"], files: [{"name":"./test.js","mimeType":"application/javascript","path":"./_file/test.js","lastModified":1704963723000}], body: (FileAttachment) => {
FileAttachment(`test.js`);
}});