Skip to content
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

resolve relative paths in sql front-matter table definitions #1797

Merged
merged 3 commits into from
Nov 6, 2024
Merged
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
5 changes: 3 additions & 2 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import type {LoaderResolver} from "./loader.js";
import type {MarkdownPage} from "./markdown.js";
import {extractNodeSpecifier, resolveNodeImport, resolveNodeImports} from "./node.js";
import {extractNpmSpecifier, populateNpmCache, resolveNpmImport, resolveNpmImports} from "./npm.js";
import {isAssetPath, isPathImport, parseRelativeUrl, relativePath, resolveLocalPath, resolvePath} from "./path.js";
import {isAssetPath, isPathImport, parseRelativeUrl} from "./path.js";
import {relativePath, resolveLocalPath, resolvePath, resolveRelativePath} from "./path.js";

export interface Resolvers {
path: string;
Expand Down Expand Up @@ -133,7 +134,7 @@ export async function getResolvers(page: MarkdownPage, config: ResolversConfig):
for (const value of Object.values(page.data.sql)) {
const source = String(value);
if (isAssetPath(source)) {
files.add(source);
files.add(resolveRelativePath(path, source));
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/input/build/sql/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
sql:
table: /table.csv
---

```sql echo
FROM table
```
3 changes: 3 additions & 0 deletions test/input/build/sql/table.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a,b
1,2
3,4
3 changes: 3 additions & 0 deletions test/output/build/sql/_file/table.b9485148.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
a,b
1,2
3,4
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
53 changes: 53 additions & 0 deletions test/output/build/sql/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="generator" content="Observable Framework v1.0.0-test">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&amp;display=swap" crossorigin>
<link rel="preload" as="style" href="./_observablehq/theme-air,near-midnight.00000004.css">
<link rel="preload" as="style" href="./_observablehq/stdlib/inputs.00000006.css">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,200..900;1,8..60,200..900&amp;display=swap" crossorigin>
<link rel="stylesheet" type="text/css" href="./_observablehq/theme-air,near-midnight.00000004.css">
<link rel="stylesheet" type="text/css" href="./_observablehq/stdlib/inputs.00000006.css">
<link rel="modulepreload" href="./_observablehq/client.00000001.js">
<link rel="modulepreload" href="./_observablehq/runtime.00000002.js">
<link rel="modulepreload" href="./_observablehq/stdlib.00000003.js">
<link rel="modulepreload" href="./_observablehq/stdlib/duckdb.00000005.js">
<link rel="modulepreload" href="./_observablehq/stdlib/inputs.00000007.js">
<link rel="modulepreload" href="./_npm/@duckdb/[email protected]/cd372fb8.js">
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js">
<link rel="modulepreload" href="./_npm/[email protected]/cd372fb8.js">
<script type="module">

import {define} from "./_observablehq/client.00000001.js";
import {registerFile, FileAttachment} from "./_observablehq/stdlib.00000003.js";
import {registerTable} from "./_observablehq/stdlib/duckdb.00000005.js";

registerFile("./table.csv", {"name":"./table.csv","mimeType":"text/csv","path":"./_file/table.b9485148.csv","lastModified":/* ts */1706742000000,"size":12});
registerTable("table", FileAttachment("./table.csv"));

define({id: "6894b77a", inputs: ["display","Inputs","sql"], body: async (display,Inputs,sql) => {
display(Inputs.table(await sql`FROM table`, {select: false}));
}});

</script>
</head>
<body>
<div id="observablehq-center">
<aside id="observablehq-toc" data-selector="h1:not(:first-of-type)[id], h2:first-child[id], :not(h1) + h2[id]">
<nav>
</nav>
</aside>
<main id="observablehq-main" class="observablehq">
<div class="observablehq observablehq--block"><!--:6894b77a:--></div>
<pre data-language="sql"><code class="language-sql"><span class="hljs-keyword">FROM</span> <span class="hljs-keyword">table</span>
</code></pre>
</main>
<footer id="observablehq-footer">
<div>Built with <a href="https://observablehq.com/" target="_blank" rel="noopener noreferrer">Observable</a> on <a title="2024-01-10T16:00:00">Jan 10, 2024</a>.</div>
</footer>
</div>
</body>
</html>