Fractal as static site generator and/or plugin?
See original GitHub issueForgive me if this way off-base, but re: modularity discussed in #197, you might consider either supporting plugins for a popular static site generator (via a common API) or essentially turning Fractal into a static site generator plugin that can be run in isolation. That way, Fractal could leverage an ecosystem of plugins that already exist (e.g. for compiling Sass or rendering Markdown) rather than needing to build and support its own.
For instance, Metalsmith does one thing well that (to my eye, at least) appears to map directly to at least one part of Fractal: it walks a directory and creates an in-memory “file system” object with both site- and file-specific metadata, then provides a plugin API for modifying any/all of them. In practice, this would mean replacing fs.js/ffs with Metalsmith and rewriting the core to work with a its file system object and data objects. Fractal’s “core” Metalsmith plugin could then either just build the component data structure, or load the theme specified in the options and tell it to render:
// options here can come either directly from the JS API or
// from the dependent module's package.json
modul.exports = function plugin(options) {
return function fractalize(files, metalsmith, done) {
const metadata = metalsmith.metadata();
const opts = Object.assign({}, metadata.fractal, options);
const fractal = metadata.fractal = new Fractal(opts);
return async.eachSeries(
Object.keys(files),
// this is a fictional API, but something like this would need to exist
(path, next) => fractal.addFile(path, files[path], next),
// finally, reconcile all the files into their respective components
error => error ? done(error) : fractal.build(done)
);
};
};
The Fractal CLI could then use other plugins to do the watching, serving w/live reloading, etc.
Metalsmith is just an example—there are a number of similar frameworks, each with their own ecosystems. There’s obviously a good deal of risk involved in hitching Fractal to the success of another framework, but I think it might be worth it if you can leverage the tools and talents of an existing community.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top GitHub Comments
@micahgodbolt Btw, metalsmith-in-place v2 was just released, which is in my opinion better suited for templating than layouts in most use-cases. It uses jstransformers and can easily be extended with a custom rendering engine if needed. Might be useful.
I’m giving this a try in that I’m creating a new site that uses fractal templates to drive metalsmith’s layout files. Basically setting partials directory as fractal/components and using {{> component/component }} to pull templates in.
I did run into one issue with metalsmith-layouts where non template files in the component folder were causing problems.
Here’s the current proposed fix for that.
https://github.com/superwolff/metalsmith-layouts/pull/116
I"ll be sure to keep everyone updated on my progress of combining the two.