Let's say I have a bunch of .cook files in a recipes folder. I'd like to render these as HTML with a layout, but also serve these raw .cook files in the built site.
It's the same scenario as wanting to keep the source .md files in a blog and serve along side built .html files, or keep raw .json files and serve as a JSON API.
I have a hard time finding my way around the docs to find an elegant solution for this.
What I landed on now:
// _config.ts
import { copy, expandGlob } from 'std/fs/mod.ts';
const SRC = 'src';
const DEST = 'build';
const site = lume({
src: SRC,
dest: DEST,
});
site
.data('layout', 'layouts/reci.njk', '/recipes')
// Makes src/recipes/*.cook → build/recipes/*/index.html
.loadPages(['.cook'], async (path) => {
const text = await Deno.readTextFile(path);
return parseToRecipe(text); // irrelevant
})
// Makes src/recipes/*.cook → build/recipes/*.cook
.addEventListener('afterBuild', async () => {
// Fiddly, since we don't want to overwrite the existing build/recipes directory from above
for await (const entry of expandGlob(`./src/recipes/*.cook`)) {
await copy(entry.path, `./${DEST}/recipes/${entry.name}`);
}
})
I've tried various combinations of:
Site.copy(): this would overwrite the built build/recipes dir.
Note: you can't use the same extension to generate pages and assets, so a way to have support for both is adding a sub-extension (like .page) for pages
Is my solution above the best one so far?
How often does it reproduce? Is there a required condition?
Version
2.1.3
Platform
macOS
What steps will reproduce the bug?
Let's say I have a bunch of
.cook
files in arecipes
folder. I'd like to render these as HTML with a layout, but also serve these raw.cook
files in the built site.It's the same scenario as wanting to keep the source
.md
files in a blog and serve along side built.html
files, or keep raw.json
files and serve as a JSON API.I have a hard time finding my way around the docs to find an elegant solution for this.
What I landed on now:
I've tried various combinations of:
Site.copy()
: this would overwrite the builtbuild/recipes
dir.Site.loadAssets()
.Site.loadData()
.I've read https://lume.land/docs/core/loaders top to bottom. The key paragraph for my issue is:
Is my solution above the best one so far?
How often does it reproduce? Is there a required condition?
No response
What is the expected behavior?
No response
What do you see instead?
-
Additional information
Related as input to: