How to support both rendering a page from a file but also keeping the raw file #593
Unanswered
johanbrook
asked this question in
Q&A
Replies: 2 comments 2 replies
-
Update: alternate version for (re-)generating the raw source files: site
// Load .cook files
.loadPages(['.cook'], async (path) => {
const raw = await Deno.readTextFile(path);
const recipe = parseToRecipe(raw);
return {
...recipe,
raw, // squirrel away the raw text to generate as new .cook file below
};
})
// (Re-)generate raw .cook files
.preprocess(['.cook'], (filtered, all) => {
for (const page of filtered) {
const cookFile = Page.create({
basename: page.src.entry?.name,
url: page.src.path + page.src.ext,
content: page.data.raw,
});
// For linking to the .cook file from the resulting .html file
page.data.rawUrl = cookFile.data.url;
all.push(cookFile);
}
}); |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think it's better an approach like markdown files: They are loaded as text files and the template engine parses the content and generate the HTML code. In this way the file is loaded only once, and you can include a front matter in the .cook files to configure things like the layout, url, draft mode, etc. import textLoader from "lume/core/loaders/text.ts";
export default class CookEngine implements Lume.Engine {
render(content, data) {
return renderRecipe(content, data);
}
renderComponent() {}
addHelper() {}
deleteCache() {}
}
site.loadPages([".cook"], {
loader: textLoader,
engine: new CookEngine(),
}); To generate the extra import { Page } from "lume/core/file.ts";
site.process([".cook"], (cookPages, allPages) => {
for (const page of cookPages) {
const rawContent = page.data.content;
allPages.push(Page.create({
url: page.outputPath.replace("/index.html", ".cook"),
content: rawContent
});
}
}); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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 alongside 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?
Related as input to:
Beta Was this translation helpful? Give feedback.
All reactions