Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: how to support both rendering .html from a file and also copying the raw file #592

Closed
johanbrook opened this issue Apr 3, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@johanbrook
Copy link

Version

2.1.3

Platform

macOS

What steps will reproduce the bug?

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.
  • Site.loadAssets().
  • Site.loadData().

I've read https://lume.land/docs/core/loaders top to bottom. The key paragraph for my issue is:

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?

No response

What is the expected behavior?

No response

What do you see instead?

Additional information

Related as input to:

@johanbrook johanbrook added the bug Something isn't working label Apr 3, 2024
@johanbrook
Copy link
Author

Sorry, saw there are Discussions here too (#593).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant