[−][src]Crate ko
ko
is a simple file processor. It's extremely simple, very fast, and super
cute, as well. It reads files from a directory, does stuff to them, and then
spits them out somewhere else. That's all it does. The "stuff" that's being
done to the files is called middleware. Middleware is just a function that
takes a struct representing a file and then does something to that file.
It doesn't even have to return it! That's how easy it is to use ko
. Can
you believe it?
ko requires Rust 2018 (Rust 1.31+).
In its simplest form, you'd use it somewhat like this:
use ko::create_middleware; fn main() { ko::run(vec![ create_middleware(|files| { let file = &mut files[0]; file.content = "test hello".to_string(); }) ], Some("fixtures/example"), Some("_site")).unwrap(); }
Don't worry, ko
also has support for passing around custom metadata per-file
via a HashMap<&str, String>
:
use ko::create_middleware; fn main() { ko::run(vec![ create_middleware(|files| { let file = &mut files[0]; file.metadata.insert("cool stuff", "test hello".to_string()); }) ], Some("fixtures/example"), Some("_site")).unwrap(); }
And then later on, you could extract it from the same file. Metadata is completely virtual, meaning it doesn't actually affect what's written to disk (unless you make something out of it!)
There's no global metadata support in ko
, because I believe that should be implemented
in your application layer, rather than relying on ko
. It'd also break the perfectly
simple library interface that we have going here.
How does ko
compare to other software?
At some distant point in time, I'd like for ko
to be used as a static site
generator. How would it compare to other existing static site generators, then?
Well, it's much simpler than Jekyll or Hugo, for example, and it's even
simpler than other JavaScript-based SSGs such as Metalsmith or Wintersmith.
Existing Rust SSGs have all more or less tried to replicate the full feature set
of Jekyll or comparable software, so I hope I'll be scratching an itch here.
ko
currently only depends on walkdir
and globset
, and I'd like to keep
dependencies as light as possible.
Structs
SimpleFile | A struct describing a simple file, with only a name, content, path (relative & absolute), and custom metadata. |
Functions
create_middleware | A convenience function that creates middleware. |
ignore | Included middleware that excludes files from processing based on glob patterns. |
run | Runs a middleware chain. |
Type Definitions
MiddlewareFunction | A type describing middleware functions. |