-
Notifications
You must be signed in to change notification settings - Fork 193
remove _file #257
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
remove _file #257
Changes from 5 commits
fad6fd5
d906ef4
8a92435
5fafaa8
9e12205
73cb6d5
71a6f63
e28c2d5
453d0cf
e7998b2
3dfe78f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,8 +72,9 @@ export async function build({sourceRoot, outputRoot, verbose = true, addPublic = | |
|
|
||
| // Copy over the referenced files. | ||
| for (const file of files) { | ||
| let sourcePath = join(sourceRoot, file); | ||
| const outputPath = join(outputRoot, file); | ||
| if (existsSync(outputPath) || existsSync(outputPath + ".html")) continue; // skip pages | ||
|
Member
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. I don’t think we always want to add |
||
| let sourcePath = join(sourceRoot, file); | ||
| if (!existsSync(sourcePath)) { | ||
| const loader = Loader.find(sourceRoot, file); | ||
| if (!loader) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -323,6 +323,7 @@ function renderIntoPieces(renderer: Renderer, root: string, sourcePath: string): | |||||
| } | ||||||
|
|
||||||
| const SUPPORTED_PROPERTIES: readonly {query: string; src: "href" | "src" | "srcset"}[] = Object.freeze([ | ||||||
| {query: "a[href]", src: "href"}, | ||||||
|
Member
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.
Suggested change
Seems to me that we shouldn’t promote links to file attachments unless they are explicitly marked as downloads. Philosophically, I don’t expect this functionality to work transparently. Meaning: we have to document which elements get this special treatment, and users will have to read the documentation to know which elements are handled automatically and which aren’t — we can’t guarantee that this will work. The only way to guarantee that it will work is for the user to declare the file attachment statically using <object
type="video/mp4"
data="path/flower.webm"
width="600"
height="140">
<img src="path/image.jpg" alt="useful image description">
</object>I don’t think we should try to get everything here, and I don’t think we should feel “forced” to removing
Member
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. And come to think of it, a more practical and reliable solution would to be have a
Contributor
Author
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. Not sure about limiting to
Member
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. FWIW I think the most useful incarnation of |
||||||
| {query: "audio[src]", src: "src"}, | ||||||
| {query: "audio source[src]", src: "src"}, | ||||||
| {query: "img[src]", src: "src"}, | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,9 +127,8 @@ export class PreviewServer { | |
| return; | ||
| } | ||
|
|
||
| // This handles a static file. | ||
| // Handle a static file. | ||
| try { | ||
| await access(path, constants.R_OK); | ||
| if ((await stat(path)).isFile()) { | ||
|
Contributor
Author
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. this test is new… otherwise javascript was detected as the javascript/ directory |
||
| send(req, pathname, {root: this.root}).pipe(res); | ||
| return; | ||
|
|
@@ -150,7 +149,7 @@ export class PreviewServer { | |
| } | ||
|
|
||
| // Otherwise, serve the corresponding Markdown file, if it exists. | ||
| // Anything else should 404; static files should be matched above. | ||
| // Anything else should 404. | ||
| try { | ||
| const config = await readConfig(this.root); | ||
| const {html} = await renderPreview(await readFile(path + ".md", "utf-8"), { | ||
|
|
||
|
Member
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. Normally we name test files to match the source file that they are testing. It seems to me this should be in |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,8 +9,8 @@ describe("file attachments", () => { | |
| const sourcePath = "/attachments.md"; | ||
|
|
||
| it("img[src]", () => { | ||
| const htmlStr = html`<img src="./test.png">`; | ||
| const expected = html`<img src="./_file/test.png">`; | ||
| const htmlStr = html`<img src="./test.png"><img src="test.png">`; | ||
| const expected = html`<span><img src="./test.png"><img src="./test.png"></span>`; | ||
|
Member
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. Is this testing that file paths are normalized and not listed twice? This is a good thing to mention in the test description so that we remember the intent of this test going forward. |
||
| const context = mockContext(); | ||
| const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
|
||
|
|
@@ -19,7 +19,7 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "image/png", | ||
| name: "./test.png", | ||
| path: "./_file/test.png" | ||
| path: "./test.png" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -35,8 +35,8 @@ describe("file attachments", () => { | |
| /> | ||
| `; | ||
| const expected = html` | ||
| <img srcset="./_file/small.jpg 480w, ./_file/large.jpg 800w" sizes="(max-width: 600px) 480px, | ||
| 800px" src="./_file/large.jpg" alt="Image for testing"> | ||
| <img srcset="./small.jpg 480w, ./large.jpg 800w" sizes="(max-width: 600px) 480px, | ||
| 800px" src="./large.jpg" alt="Image for testing"> | ||
| `; | ||
| const context = mockContext(); | ||
| const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
|
@@ -46,12 +46,12 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "image/jpeg", | ||
| name: "large.jpg", | ||
| path: "./_file/large.jpg" | ||
| path: "./large.jpg" | ||
| }, | ||
| { | ||
| mimeType: "image/jpeg", | ||
| name: "small.jpg", | ||
| path: "./_file/small.jpg" | ||
| path: "./small.jpg" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -60,7 +60,7 @@ describe("file attachments", () => { | |
| const htmlStr = html`<video src="observable.mov" controls> | ||
| Your browser doesn't support HTML video. | ||
| </video>`; | ||
| const expected = html`<video src="./_file/observable.mov" controls> | ||
| const expected = html`<video src="./observable.mov" controls> | ||
| Your browser doesn't support HTML video. | ||
| </video>`; | ||
| const context = mockContext(); | ||
|
|
@@ -71,7 +71,7 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "video/quicktime", | ||
| name: "observable.mov", | ||
| path: "./_file/observable.mov" | ||
| path: "./observable.mov" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -84,8 +84,8 @@ describe("file attachments", () => { | |
| </video>`; | ||
|
|
||
| const expected = html`<video width="320" height="240" controls> | ||
| <source src="./_file/observable.mp4" type="video/mp4"> | ||
| <source src="./_file/observable.mov" type="video/mov"> | ||
| <source src="./observable.mp4" type="video/mp4"> | ||
| <source src="./observable.mov" type="video/mov"> | ||
| Your browser doesn't support HTML video. | ||
| </video>`; | ||
|
|
||
|
|
@@ -97,12 +97,12 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "video/mp4", | ||
| name: "observable.mp4", | ||
| path: "./_file/observable.mp4" | ||
| path: "./observable.mp4" | ||
| }, | ||
| { | ||
| mimeType: "video/quicktime", | ||
| name: "observable.mov", | ||
| path: "./_file/observable.mov" | ||
| path: "./observable.mov" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -114,8 +114,8 @@ describe("file attachments", () => { | |
| </picture>`; | ||
|
|
||
| const expected = html`<picture> | ||
| <source srcset="./_file/observable-logo-wide.png" media="(min-width: 600px)"> | ||
| <img src="./_file/observable-logo-narrow.png"> | ||
| <source srcset="./observable-logo-wide.png" media="(min-width: 600px)"> | ||
| <img src="./observable-logo-narrow.png"> | ||
| </picture>`; | ||
|
|
||
| const context = mockContext(); | ||
|
|
@@ -126,12 +126,12 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "image/png", | ||
| name: "observable-logo-narrow.png", | ||
| path: "./_file/observable-logo-narrow.png" | ||
| path: "./observable-logo-narrow.png" | ||
| }, | ||
| { | ||
| mimeType: "image/png", | ||
| name: "observable-logo-wide.png", | ||
| path: "./_file/observable-logo-wide.png" | ||
| path: "./observable-logo-wide.png" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -160,7 +160,7 @@ describe("file attachments", () => { | |
| /> | ||
| `; | ||
| const expected = html` | ||
| <img srcset="./_file/small.jpg 480w, https://upload.wikimedia.org/900px-American_Shorthair.jpg 900w" sizes="(max-width: 600px) 480px, 900px" src="https://upload.wikimedia.org/900px-American_Shorthair.jpg" alt="Cat image for testing"> | ||
| <img srcset="./small.jpg 480w, https://upload.wikimedia.org/900px-American_Shorthair.jpg 900w" sizes="(max-width: 600px) 480px, 900px" src="https://upload.wikimedia.org/900px-American_Shorthair.jpg" alt="Cat image for testing"> | ||
| `; | ||
| const context = mockContext(); | ||
| const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
|
@@ -170,7 +170,7 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "image/jpeg", | ||
| name: "small.jpg", | ||
| path: "./_file/small.jpg" | ||
| path: "./small.jpg" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
@@ -184,7 +184,7 @@ describe("file attachments", () => { | |
|
|
||
| const expected = html`<video width="320" height="240" controls> | ||
| <source src="https://www.youtube.com/watch?v=SsFyayu5csc" type="video/youtube"> | ||
| <source src="./_file/observable.mov" type="video/mov"> | ||
| <source src="./observable.mov" type="video/mov"> | ||
| Your browser doesn't support HTML video. | ||
| </video>`; | ||
|
|
||
|
|
@@ -196,7 +196,7 @@ describe("file attachments", () => { | |
| { | ||
| mimeType: "video/quicktime", | ||
| name: "observable.mov", | ||
| path: "./_file/observable.mov" | ||
| path: "./observable.mov" | ||
| } | ||
| ]); | ||
| }); | ||
|
|
||
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.
Should we error if the file already exists? (Which shouldn’t have been possible before, but should now be possible if you have e.g. an
index.htmland anindex.md.)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.
We should not error, but we must definitely skip the file in that case.
Here are examples (admittedly fringe) where a file points to a generated page:
javascript.md:
<a href=javascript.html download>download this page</a>or
<a href=javascript download>download this page</a>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.
now skipping both of these