statiqdev / Statiq.Web

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

Is there a way to remove a pipeline? #962

Closed AnkurSheel closed 2 years ago

AnkurSheel commented 3 years ago

I am trying to replace the Content Pipeline with my own custom pipeline but I am not sure of the best way to do it.

I wonder if there should be a helper function to remove the Pipeline or to remove /recreate the modules for the different phases of the pipeline. The current helpers append a module so the only way seems to be to filter all the documents from the process phase.

.ModifyPipeline(nameof(Content),
                    pipeline =>
                    {
                        pipeline.WithProcessModules(new FilterDocuments(false));
                    })

Also, is this the best way to do this?

daveaglick commented 3 years ago

There's a couple things you can do here in Statiq Web...

The first thing to note is that I'm planning on pipeline replacement methods for the bootstrapper in the next release: https://github.com/statiqdev/Statiq.Framework/issues/198 - no idea how I missed this concept when designing that API, but it's definitely an oversight and removing/replacing pipelines should be easier.

That said, there's a few things you can do today too. Statiq Web has this concept of templates which are a way to "hook" into the various pipelines. Basically templates define a specific module (or set of modules if you wrap them in an outer module) that gets run for specific media types. I.e. if you wanted to add support for EJS and wrote a module that could render EJS files, you might do something like:

.AddTemplate(MediaTypes.Get(".ejs"), ContentType.Content, Phase.Process, new RenderEjs())

There are also .ModifyTemplate() and .RemoveTemplate() methods (along with a more powerful .ConfigureTemplates() method that gives direct access to the template collection). So if what you want to do is related to a single kind of file, those might be helpful.

If you want to totally replace a module, you can also do that today, it's just not exposed in a nice fluent way:

.ConfigureEngine(engine =>
{
    // Create my new pipeline
    IPipeline pipeline = new Pipeline();
    pipeline.ProcessModules.AddRange(
        new ModuleA(),
        new ModuleB());

    // Remove the old one and add the new one
    engine.Pipelines.Remove(nameof(Statiq.Web.Pipelines.Content));
    engine.Pipelines.Add(nameof(Statiq.Web.Pipelines.Content), pipeline);
})

Hopefully one of those approaches will help - happy to continue brainstorming if not.

AnkurSheel commented 3 years ago

Thanks for the speedy reply. The configureEngine option works perfectly for what I am trying to do. Apart from the weird transformation between the input -> output folders that I want, I also wanted to use strongly typed models with Razor instead of using the document object in the .cshtml. Happy to share the link to my repo if you are interested.

no idea how I missed this concept when designing that API, but it's definitely an oversight and removing/replacing pipelines should be easier.

No worries. It's an iterative process, isn't it :)

Statiq Web has this concept of templates

Yeah, I tried removing/updating templates but it didn't really fit into what I was trying to do.

I think might be worth introducing a concept of overriding the phases for a pipeline. The use case is that only the modules in 1 or more of the pipeline phases need to be replaced. Currently, it seems as if you use the configureEngine option to replace one of the pipelines, you will have to build all the phases again.

daveaglick commented 2 years ago

I think might be worth introducing a concept of overriding the phases for a pipeline. The use case is that only the modules in 1 or more of the pipeline phases need to be replaced. Currently, it seems as if you use the configureEngine option to replace one of the pipelines, you will have to build all the phases again.

Fantastic idea - I'll repurpose this issue into the tracker for that

daveaglick commented 2 years ago

Actually ended up creating a new issue over in Framework so I'll close this one out now in favor of that one.