Closed Protonull closed 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.
@oscarotero What about markdown and nunjucks files, which become HTML? I found this property very useful.
@binyamin Pages have two properties:
page.src
: Info about the source file (page.src.ext
returns the extension, like .md
, .njk
, etc).page.outputPath
: The output path of the page. For example /about-me/index.html
(with prettyUrls enabled) or /about-me.html
with prettyUrls disabled.So, if you want to detect if a page will become to HTML, just do page.outputPath.endsWith(".html")
.
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 thePage.isHtml
by having its value set viaPage.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 withtext/
then you know that you can safely useDeno.writeTextFile()
instead of another method.