Skip to content

Commit

Permalink
fix public path to _file
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Nov 17, 2023
1 parent 07c69ba commit 0e3c901
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export function define(cell) {
v.define(outputs.length ? `cell ${id}` : null, inputs, body);
variables.push(v);
for (const o of outputs) variables.push(main.define(o, [`cell ${id}`], (exports) => exports[o]));
for (const f of files) attachedFiles.set(f.name, {url: globalThis._FileAttachmentDir + `${(new URL(f.name, location)).pathname}`, mimeType: f.mimeType}); // prettier-ignore
const fadir = new URL(globalThis._FileAttachmentBase, location).href;
for (const f of files) attachedFiles.set(f.name, {url: new URL(f.name, fadir).pathname, mimeType: f.mimeType});
for (const d of databases) databaseTokens.set(d.name, d);
}

Expand Down
2 changes: 1 addition & 1 deletion src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ ${Array.from(getImportPreloads(parseResult, path))
<script type="module">
import {${preview ? "open, " : ""}define} from "${relativeUrl(path, "/_observablehq/client.js")}";
globalThis._FileAttachmentDir = ${JSON.stringify(relativeUrl(path, "/_file/"))};
globalThis._FileAttachmentBase = ${JSON.stringify(relativeUrl(path, "/_file" + dirname(path) + "/"))};
${preview ? `open({hash: ${JSON.stringify(hash)}});\n` : ""}${parseResult.cells
.map(resolver)
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="module">

import {define} from "./_observablehq/client.js";
globalThis._FileAttachmentDir = "./_file/";
globalThis._FileAttachmentBase = "./_file/";


</script>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/one.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="module">

import {define} from "./_observablehq/client.js";
globalThis._FileAttachmentDir = "./_file/";
globalThis._FileAttachmentBase = "./_file/";


</script>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/config/sub/two.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="module">

import {define} from "../_observablehq/client.js";
globalThis._FileAttachmentDir = "../_file/";
globalThis._FileAttachmentBase = "../_file/sub/";


</script>
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/files/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script type="module">

import {define} from "./_observablehq/client.js";
globalThis._FileAttachmentDir = "./_file/";
globalThis._FileAttachmentBase = "./_file/";

define({id: "a7808707", inputs: ["display"], files: [{"name":"./file-top.csv","mimeType":"text/csv"}], body: (display) => {
display((
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/files/subsection/subfiles.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script type="module">

import {define} from "../_observablehq/client.js";
globalThis._FileAttachmentDir = "../_file/";
globalThis._FileAttachmentBase = "../_file/subsection/";

define({id: "62f1fd0c", inputs: ["display"], files: [{"name":"../file-top.csv","mimeType":"text/csv"}], body: (display) => {
display((
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 @@ -13,7 +13,7 @@
<script type="module">

import {define} from "../_observablehq/client.js";
globalThis._FileAttachmentDir = "../_file/";
globalThis._FileAttachmentBase = "../_file/foo/";

define({id: "a9220fae", inputs: ["display"], outputs: ["d3","bar"], body: async (display) => {
const d3 = await import("https://cdn.jsdelivr.net/npm/d3/+esm");
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/multi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="module">

import {define} from "./_observablehq/client.js";
globalThis._FileAttachmentDir = "./_file/";
globalThis._FileAttachmentBase = "./_file/";

define({id: "1bcb5df5", inputs: ["FileAttachment"], outputs: ["f1"], files: [{"name":"file1.csv","mimeType":"text/csv"}], body: (FileAttachment) => {
const f1 = FileAttachment("file1.csv").csv();
Expand Down
2 changes: 1 addition & 1 deletion test/output/build/multi/subsection/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script type="module">

import {define} from "../_observablehq/client.js";
globalThis._FileAttachmentDir = "../_file/";
globalThis._FileAttachmentBase = "../_file/subsection/";


</script>
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 @@ -9,7 +9,7 @@
<script type="module">

import {define} from "./_observablehq/client.js";
globalThis._FileAttachmentDir = "./_file/";
globalThis._FileAttachmentBase = "./_file/";

define({id: "115586ff", inputs: ["FileAttachment"], outputs: ["result"], files: [{"name":"data.txt","mimeType":"text/plain"}], body: (FileAttachment) => {
let result = FileAttachment("data.txt").text();
Expand Down

0 comments on commit 0e3c901

Please sign in to comment.