-
Notifications
You must be signed in to change notification settings - Fork 155
relative fetch and FileAttachments #193
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
07dce39
relative fetch and FileAttachments
Fil 73052eb
Merge branch 'main' into fil/relative-file
Fil a4a9bfc
merge main
Fil 07c69ba
relative prev/next
Fil 0e3c901
fix public path to _file
Fil b4d81ea
render-side file attachment urls
Fil 9348c12
Update src/files.ts
mbostock d571157
sourcePath, not root
mbostock b6df78e
Merge branch 'main' into fil/relative-file
mbostock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import {type RuleInline} from "markdown-it/lib/parser_inline.js"; | |
import {type RenderRule, type default as Renderer} from "markdown-it/lib/renderer.js"; | ||
import MarkdownItAnchor from "markdown-it-anchor"; | ||
import mime from "mime"; | ||
import {relativeUrl} from "../src/url.js"; | ||
import {getLocalPath} from "./files.js"; | ||
import {computeHash} from "./hash.js"; | ||
import {parseInfo} from "./info.js"; | ||
|
@@ -330,7 +331,7 @@ function normalizePieceHtml(html: string, root: string, sourcePath: string, cont | |
const path = getLocalPath(sourcePath, href); | ||
if (path) { | ||
context.files.push({name: href, mimeType: mime.getType(href)}); | ||
element.setAttribute("href", `/_file/${path}`); | ||
element.setAttribute("href", relativeUrl(sourcePath, `/_file/${path}`)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rewriting |
||
} | ||
} | ||
return isSingleElement(document) ? String(document) : `<span>${document}</span>`; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color: pink; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello,world | ||
1,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<link rel=stylesheet href="custom-styles.css" /> | ||
<link rel=stylesheet href="subsection/additional-styles.css" /> | ||
|
||
```js | ||
fetch("./file-top.csv") | ||
``` | ||
|
||
```js | ||
fetch("./subsection/file-sub.csv") | ||
``` | ||
|
||
```js | ||
FileAttachment("file-top.csv") | ||
``` | ||
|
||
```js | ||
FileAttachment("subsection/file-sub.csv") | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color: green; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Bonjour,monde | ||
1,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<link rel=stylesheet href="../custom-styles.css" /> | ||
<link rel=stylesheet href="additional-styles.css" /> | ||
|
||
```js | ||
fetch("../file-top.csv") | ||
``` | ||
|
||
```js | ||
fetch("./file-sub.csv") | ||
``` | ||
|
||
```js | ||
FileAttachment("../file-top.csv") | ||
``` | ||
|
||
```js | ||
FileAttachment("file-sub.csv") | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color: pink; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Hello,world | ||
1,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
a { color: green; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Bonjour,monde | ||
1,2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap"> | ||
<link rel="stylesheet" type="text/css" href="./_observablehq/style.css"> | ||
<link rel="modulepreload" href="./_observablehq/runtime.js"> | ||
<script type="module"> | ||
|
||
import {define} from "./_observablehq/client.js"; | ||
globalThis._FileAttachmentDir = "./_file/"; | ||
|
||
define({id: "a7808707", inputs: ["display"], files: [{"name":"./file-top.csv","mimeType":"text/csv"}], body: (display) => { | ||
display(( | ||
fetch("./_file/file-top.csv") | ||
)) | ||
}}); | ||
define({id: "03b99abc", inputs: ["display"], files: [{"name":"./subsection/file-sub.csv","mimeType":"text/csv"}], body: (display) => { | ||
display(( | ||
fetch("./_file/subsection/file-sub.csv") | ||
)) | ||
}}); | ||
define({id: "10037545", inputs: ["FileAttachment","display"], files: [{"name":"file-top.csv","mimeType":"text/csv"}], body: (FileAttachment,display) => { | ||
display(( | ||
FileAttachment("file-top.csv") | ||
)) | ||
}}); | ||
define({id: "453a8147", inputs: ["FileAttachment","display"], files: [{"name":"subsection/file-sub.csv","mimeType":"text/csv"}], body: (FileAttachment,display) => { | ||
display(( | ||
FileAttachment("subsection/file-sub.csv") | ||
)) | ||
}}); | ||
|
||
</script> | ||
<input id="observablehq-sidebar-toggle" type="checkbox"> | ||
<nav id="observablehq-sidebar"> | ||
<ol> | ||
<li class="observablehq-link observablehq-link-active"><a href="./files">Untitled</a></li> | ||
<li class="observablehq-link"><a href="./subsection/subfiles">Untitled</a></li> | ||
</ol> | ||
</nav> | ||
<script>{ | ||
const toggle = document.querySelector("#observablehq-sidebar-toggle"); | ||
const initialState = localStorage.getItem("observablehq-sidebar"); | ||
if (initialState) toggle.checked = initialState === "true"; | ||
else toggle.indeterminate = true; | ||
}</script> | ||
<div id="observablehq-center"> | ||
<main id="observablehq-main" class="observablehq"> | ||
<span><link rel="stylesheet" href="./_file/custom-styles.css"> | ||
<link rel="stylesheet" href="./_file/subsection/additional-styles.css"> | ||
</span><div id="cell-a7808707" class="observablehq observablehq--block"></div> | ||
<div id="cell-03b99abc" class="observablehq observablehq--block"></div> | ||
<div id="cell-10037545" class="observablehq observablehq--block"></div> | ||
<div id="cell-453a8147" class="observablehq observablehq--block"></div> | ||
</main> | ||
<footer id="observablehq-footer"> | ||
<nav><a class="next" href="/subsection/subfiles"><span>Untitled</span></a></nav> | ||
<div>© 2023 Observable, Inc.</div> | ||
</footer> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> | ||
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+Pro:ital,wght@0,400;0,600;0,700;1,400;1,600;1,700&display=swap"> | ||
<link rel="stylesheet" type="text/css" href="../_observablehq/style.css"> | ||
<link rel="modulepreload" href="../_observablehq/runtime.js"> | ||
<script type="module"> | ||
|
||
import {define} from "../_observablehq/client.js"; | ||
globalThis._FileAttachmentDir = "../_file/"; | ||
|
||
define({id: "62f1fd0c", inputs: ["display"], files: [{"name":"../file-top.csv","mimeType":"text/csv"}], body: (display) => { | ||
display(( | ||
fetch("../_file/file-top.csv") | ||
)) | ||
}}); | ||
define({id: "94d347ec", inputs: ["display"], files: [{"name":"./file-sub.csv","mimeType":"text/csv"}], body: (display) => { | ||
display(( | ||
fetch("../_file/subsection/file-sub.csv") | ||
)) | ||
}}); | ||
define({id: "ef9a31ef", inputs: ["FileAttachment","display"], files: [{"name":"../file-top.csv","mimeType":"text/csv"}], body: (FileAttachment,display) => { | ||
display(( | ||
FileAttachment("../file-top.csv") | ||
)) | ||
}}); | ||
define({id: "834ecf9f", inputs: ["FileAttachment","display"], files: [{"name":"file-sub.csv","mimeType":"text/csv"}], body: (FileAttachment,display) => { | ||
display(( | ||
FileAttachment("file-sub.csv") | ||
)) | ||
}}); | ||
|
||
</script> | ||
<input id="observablehq-sidebar-toggle" type="checkbox"> | ||
<nav id="observablehq-sidebar"> | ||
<ol> | ||
<li class="observablehq-link"><a href="../files">Untitled</a></li> | ||
<li class="observablehq-link observablehq-link-active"><a href="./subfiles">Untitled</a></li> | ||
</ol> | ||
</nav> | ||
<script>{ | ||
const toggle = document.querySelector("#observablehq-sidebar-toggle"); | ||
const initialState = localStorage.getItem("observablehq-sidebar"); | ||
if (initialState) toggle.checked = initialState === "true"; | ||
else toggle.indeterminate = true; | ||
}</script> | ||
<div id="observablehq-center"> | ||
<main id="observablehq-main" class="observablehq"> | ||
<span><link rel="stylesheet" href="../_file/custom-styles.css"> | ||
<link rel="stylesheet" href="../_file/subsection/additional-styles.css"> | ||
</span><div id="cell-62f1fd0c" class="observablehq observablehq--block"></div> | ||
<div id="cell-94d347ec" class="observablehq observablehq--block"></div> | ||
<div id="cell-ef9a31ef" class="observablehq observablehq--block"></div> | ||
<div id="cell-834ecf9f" class="observablehq observablehq--block"></div> | ||
</main> | ||
<footer id="observablehq-footer"> | ||
<nav><a class="prev" href="/files"><span>Untitled</span></a></nav> | ||
<div>© 2023 Observable, Inc.</div> | ||
</footer> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this also fixes a bug where fetch rewrites didn't work for files in subdirectories:
If you had this in javascript/files.md:
it would have been compiled to
fetch(".._file//file.csv")
👎(with this PR it becomes
fetch("../_file/file.csv")
👍); tested in input/build/files/