Skip to content

Commit

Permalink
add ondemand
Browse files Browse the repository at this point in the history
  • Loading branch information
RickCogley committed Nov 16, 2024
1 parent f924ad5 commit 693d61f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import phosphor from "https://deno.land/x/[email protected]/phosphor.ts";
import picture from "lume/plugins/picture.ts";
import transformImages from "lume/plugins/transform_images.ts";
import brotli from "lume/plugins/brotli.ts";
import onDemand from "lume/plugins/on_demand.ts";

const site = lume(
{
Expand Down Expand Up @@ -60,6 +61,16 @@ site.use(transformImages({
matches: /\.(jpg|jpeg|png|webp)$/i, // This regex matches only image files
}));
site.use(brotli());
site.use(onDemand({
extraData(request: Request) {
const searchParams = new URL(request.url).searchParams;
const params = Object.fromEntries(searchParams.entries());

return {
params,
};
},
}));

site.copy("assets");
// site.copy("static/portfolio", "portfolio");
Expand Down
9 changes: 9 additions & 0 deletions _preload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Don't execute this function
* It's just statically analyzable so dynamic imports work on Deno Deploy
* @see https://deno.com/deploy/changelog#statically-analyzable-dynamic-imports
*/
export function toStaticallyAnalyzableDynamicImports() {
import("./src/archive/index.ts");
import("./src/_data.ts");
}
3 changes: 3 additions & 0 deletions _routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"/ondemand/": "/ondemand.vto"
}
2 changes: 2 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Server from "lume/core/server.ts";
import precompress from "lume/middlewares/precompress.ts";
import expires from "lume/middlewares/expires.ts";
import csp from "https://raw.githubusercontent.com/lumeland/experimental-plugins/main/csp/mod.ts";
import onDemand from "lume/middlewares/on_demand.ts";
import "./_preload.ts";

//import csp from "https://raw.githubusercontent.com/RickCogley/experimental-plugins/refs/heads/main/csp/mod.ts";

Expand Down Expand Up @@ -50,6 +52,8 @@ server.use(csp({
"X-Powered-By": "Lume and sweat, blood, and tears",
}));

server.use(onDemand({ site }));

server.start();

console.log("Listening on http://localhost:8000");
6 changes: 6 additions & 0 deletions src/ondemand.vto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
layout: layouts/base.vto
ondemand: true
---

Hello {{ params.name }}

1 comment on commit 693d61f

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on 693d61f Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

UNCAUGHT_EXCEPTION

ReferenceError: site is not defined
    at file:///src/serve.ts:55:23

Please sign in to comment.