Create a project
The configuration module frugal.config.ts
Frugal tries to assume as little as possible about your project, so you have to configure it. First, let's write the minimal configuration needed :
import { Config } from "https://deno.land/x/frugal@0.9.5/mod.ts"
export default {
self: import.meta.url,
pages: []
} satisfies Config;
123456
The self
property should be the absolute path of the configuration module (obtained with import.meta.url
). The folder where the config module resides will be the root of your project (the dirname of self
). Frugal will resolve every path relative to this root.
Unless you know what you are doing, self
should always be import.meta.url
.
The pages
should list the paths of the page modules of your website.
It is empty for now, but not for long.
Your first page
Create a file pages/home.ts
with the following code :
export const route = '/'
export function render() {
return `<!DOCTYPE html>
<html>
<body>
<h1>My blog</h1>
</body>
</html>`
}
12345678910
You just wrote your first static page with Frugal!
For now, we will not use any UI framework, so we output basic HTML with template strings in the render
method. This method will be called at build time to generate the page's markup. The route
contains the URL pattern of the generated page. Here the generated page will live at the root of the website.
Add the relative path to the newly created page in the configuration module :
import { Config } from "https://deno.land/x/frugal@0.9.5/mod.ts"
export default {
self: import.meta.url,
pages: ['pages/home.ts']
} satisfies Config;
123456
Now we need a script to run Frugal.
The dev script
Create a file dev.ts
with the following code:
import { context } from "https://deno.land/x/frugal@0.9.5/mod.ts"
import config from "./frugal.config.ts"
await context(config).watch()
1234
Simply calling the watch
function on the context
will set up a watch process and a dev server with live-reload.
You can now run this script to get a dev server with live reload :
deno run -A dev.ts
Visiting http://0.0.0.0:3000/ should display your page.
The dev server has live-reload capacity. Changing the code of a page or any of its dependencies should trigger a page reload.
However, this is limited to staticaly analyzable imports (static imports or dynamic imports with paths known ahead of time). Any change in external data sources (database, API, filesystem ...) won't trigger a reload: you'll have to refresh the page manually
Now that we have a working project, we will start coding our blog in the next section.