lumeland / lume

🔥 Static site generator for Deno 🦕
https://lume.land
MIT License
1.86k stars 85 forks source link

Replace Page.isHtml with Page.contentType #317

Closed Protonull closed 1 year ago

Protonull commented 1 year ago

Enter your suggestions in details:

Just saw the changelog which included the addition of Page.isHtml, which is great, but I wonder if a broader is-function might be more useful. Lume's docs mention the possibility of dynamically generated assets here, and those assets could be blobs like PDFs of other files, or text files, indeed like the example'd Javascript-map file. But what if it's an XML file like an RSS feed? Would that appear to Lume as a HTML file? Would that therefore impact how that file is rendered? I'm not sure tbh, but I do think either way there's enough of a reason to allow for more exhaustive check. You could even keep the Page.isHtml by having its value set via Page.isHtml = Page.contentType === "text/html"; You could check the prefix of the content-type to know how to save the file: if the type is prefixed with text/ then you know that you can safely use Deno.writeTextFile() instead of another method.

oscarotero commented 1 year ago

You can get the content type of the pages by the url. For example:

if (page.data.url.endsWith(".css")) {
    // it's a CSS file
}

The isHtml property is used internally because HTML pages are the only format that doesn't require to have the .html extension in the url. For example /about-me/. It's used internally by some plugins like search that only returns html pages.

Thinking more about this, probably it could use the outputPath property to get the .html extension (page.outputPath.endsWith(".html")).

Here's the code: https://github.com/lumeland/lume/blob/master/core/filesystem.ts#L121-L136

Maybe i will change it in the next version.

binyamin commented 1 year ago

@oscarotero What about markdown and nunjucks files, which become HTML? I found this property very useful.

oscarotero commented 1 year ago

@binyamin Pages have two properties:

So, if you want to detect if a page will become to HTML, just do page.outputPath.endsWith(".html").