Questions on Page Loaders #1642
-
Love the new Page loaders feature! They made me wonder....
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
For your second question, the |
Beta Was this translation helpful? Give feedback.
-
For (1), we’d like to better understand this use case. Why would you want to remove the You can fully customize the appearance of the page by disabling Framework’s UI by setting the sidebar and toc to false, by specifying a custom (possibly null) header and footer, and by providing a custom stylesheet. See the Response iframe example. We’re also exploring an embedding API #1084 #1637 if you want to use Framework to create embeddable components rather than full-page apps. We previously explored making the page template a user-specifiable function in #253, but it wasn’t clear what it would be used for, so we opted for higher-level features such as a user-configurable header, footer, and styles. For (2), as @mythmon said, you can specify the dynamicPaths option as an async function. This is the example in the docs which uses SQL (wrapped in JavaScript): import postgres from "postgres";
const sql = postgres(); // Note: uses psql environment variables
export default {
async *dynamicPaths() {
for await (const {id} of sql`SELECT id FROM products`.cursor()) {
yield `/products/${id}`;
}
}
}; If you wanted to invoke an external script in another language to enumerate the dynamic paths, you could do that in the same way that Framework invokes data loaders using import {spawn} from "node:child_process";
import readline from "node:readline";
export default {
async *dynamicPaths() {
const script = spawn("python3", ["script.py"]);
yield* readline.createInterface({input: script.stdout});
const code = await new Promise((resolve) => script.on("close", resolve));
if (code !== 0) throw new Error(`script exited with code ${code}`);
}
}; Here import sys
def main():
data = ["/path1", "/path2", "/path3"]
for line in data:
print(line)
if __name__ == "__main__":
main() If there’s demand for this pattern, we could definitely extend the dynamicPaths option to allow invoking of a data loader. But in the meantime we recommend copying the above snippet. |
Beta Was this translation helpful? Give feedback.
For (1), we’d like to better understand this use case. Why would you want to remove the
modulepreload
hints? Why would you remove Framework’s scripts, which are essential for the code to run?You can fully customize the appearance of the page by disabling Framework’s UI by setting the sidebar and toc to false, by specifying a custom (possibly null) header and footer, and by providing a custom stylesheet. See the Response iframe example. We’re also exploring an embedding API #1084 #1637 if you want to use Framework to create embeddable components rather than full-page apps.
We previously explored making the page template a user-specifiable function in #253, but it wasn’t clear what it woul…