Replies: 1 comment
-
I totally agree registering additional modules by pipeline (and especially by pipeline index) isn't the best way. I've been trying to avoid this by adding "hooks" at various places where it would make sense to inject new modules. For example, in Statiq Web the modules related to rendering or processing different types of files (JSON, YAML, Razor, Markdown, etc.) are not based on an extensible templates concept that uses media types. Under the hood this is essentially just a big switch statement at the appropriate point in the pipeline that calls out the the template modules, but it short-circuits the pipeline and avoids the user having to inject the modules directly. I wonder if a similar injection point makes sense for things like this - something like Calculated MetadataThe other alternative that might be even more appropriate is not to base this on modules at all. Metadata in Statiq is way more powerful than in Wyam and can be a delegate or even compiled script. In this case, I could see doing something like: public static Bootstrapper AddReadingTimeMeta(this Bootstrapper bootstrapper) =>
bootstrapper.AddSetting("ReadingTime", Config.FromDocument(doc => CalculateReadingTime(doc)));
private static TimeSpan CalculateReadingTime(IDocument doc)
{
// ...
} That has the exact same effect of adding a "ReadingTime" metadata value to the document as the module approach would, but it has some advantages:
ShortcodesThere's also a whole other approach that could work too. If we consider the reading time as part of the page and not necessarily front matter, something like a shortcode could work. That would let you write something like |
Beta Was this translation helpful? Give feedback.
-
Hey,
I've just migrated my blog over from Wyam to Statiq which was a great experience. The usability and tooling is fantastic and have enjoyed using it.
One of the things I wrote for my blog in Wyam was the reading time plugin which you can find here.
I added a helper method for registering the reading time plugin into the Wyam blog recipe with a helper like this:
With Statiq there isn't an easy method of doing the same. The closest i've gotten is this:
This works when you have access to
Statiq.Core
but following the advice and trying to useStatiq.Common
you're unable to extend the Bootstrapper in this way since you can't accessModifyPipeline
or target modules likeExecuteIf
.Let me also say I'm not a fan of accessing the modules by index, a way of targeting the pipeline for blog posts by name like Wyam would be useful or even a recursive way of finding a module to insert after? Just wanted to start a dialog on if there's a nicer way of providing a standard registration knowing a common pipeline layout.
Beta Was this translation helpful? Give feedback.
All reactions