statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.64k stars 235 forks source link

Layout file not being used in beta 16 #934

Closed JamesThorpe closed 3 years ago

JamesThorpe commented 3 years ago

I've been building a very simple site, along the lines of:

/input/index.md
/input/styles/site.less
/theme/input/_layout.cshtml
/theme/settings.yml

With the settings.yml containing a single setting, Layout: /_layout.cshtml.

Up until today the theme/layout was working properly, but beta 16 seems to ignore it entirely. Beta 15 is fine still. The debug output for beta 15 shows:

[DBUG] [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler] Compilation of the generated code for the Razor file at '_layout.cshtml' started. [DBUG] [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.RuntimeViewCompiler] Compilation of the generated code for the Razor file at '_layout.cshtml' completed in 266.7794ms.

But no mention of that file at all in the beta 16 output. The main program is still very basic:

    public class Program
    {
        public static async Task<int> Main(string[] args) => 
            await Bootstrapper.Factory.CreateWeb(args).RunAsync();
    }

The .md files are transformed into .html files still, but based purely on the content of the markdown, but none of the layout.

daveaglick commented 3 years ago

Ah, damn. I know exactly why that is. It's an unintended consequence of #933. The problem is that if you have a plain old .html file in your input folder, there's an expectation that'll get copied over as-is. I.e., if my foo.html file has all the trappings of an HTML file like <html>...</html> etc. I'm not expecting it to apply any additional layout around that (a different user hit this and was very confused why his <html>...</html> was being wrapped with a layout file).

On the other hand, once Markdown renders, it's converted to an HTML file (in-memory, but still). That's a "partial" HTML file though so it should get all the layout stuff. The change I made to copy HTML files directly without applying layout seems to have stopped applying to all HTML files, including Markdown output.

A better fix for the actual use case is probably to look for <html in the document content. If found, treat it as a complete HTML file and don't apply layouts. If not found, treat it as a fragment and apply layouts. That should work for the .html file on disk, and will be even smarter than just relying on file name. It'll also work for Markdown and other preprocessors since those generate fragments by default.

This will be an easy fix (I hope), should have a patch release out tonight.

JamesThorpe commented 3 years ago

Ah, well actually I didn't tell the whole story in my ticket - one of the input files is a (partial) html file (h1, divs ps and a script tag), with the expectation that it'll get embedded in the layout. Unsure if that changes things or not?

JamesThorpe commented 3 years ago

Have read through that ticket - I've updated back to 16, and renamed the .html to .fhtml, and that one is now embedded in the layout, but the .md files aren't.

daveaglick commented 3 years ago

Yeah, the Markdown files aren't going to work in 16 at all now 😬, so that makes me highly motivated to get a fix out!

Actually think I've already got the code done, so just need to do a little testing and then I'll publish.

daveaglick commented 3 years ago

I'll probably delist that version from NuGet in the meantime

daveaglick commented 3 years ago

The fix is rolling out now as 1.0.0-beta.17. Also added some unit tests to cover this situation so the same thing won't regress again the next time I feel like playing with the layout templates.