feat: reconstruct krile source

This commit is contained in:
liv 2023-03-19 17:20:25 +01:00
parent e91056fee5
commit 4fa8813869
7 changed files with 270 additions and 2 deletions

85
krile/CHANGELOG.md Normal file
View file

@ -0,0 +1,85 @@
# Changelog
## [0.5.6] - 2021-11-10
### Changed
- Upgraded shtola to `0.4.2`.
## [0.5.5] - 2021-11-10
### Changed
- Upgraded shtola to `0.4.1`.
## [0.5.4] - 2021-11-10
### Added
- Upgraded shtola to `0.4.0`.
- Added pretty links support.
## [0.5.3] - 2021-11-09
### Changed
- Upgraded shtola to `0.3.0`.
## [0.5.2] - 2021-11-09
### Changed
- The Markdown processing plugin now runs before the Layout processing
plugin. This is because rendering half-Markdown, half-HTML pages will
break something at some point, so it's best to render layouts when they're
entirely HTML.
## [0.5.1] - 2021-11-03
### Added
- Upgraded shtola to `0.3.0-alpha5`.
## [0.5.0] - 2021-09-21
### Changed
- The CLI interface now takes source and destination in the form of option
flags instead of positional arguments.
- Added a `--version` switch.
- Upgraded shtola to `0.3.0-alpha5`.
## [0.4.1] - 2021-07-23
### Added
- Upgraded shtola to `0.3.0-alpha4`.
## [0.4.0] - 2021-07-23
### Added
- Read other ignores from a `.krileignore` file.
## [0.3.1] - 2021-07-23
### Added
- Upgraded shtola to `0.3.0-alpha3`.
## [0.3.0] - 2021-07-23
### Added
- Upgraded shtola to `0.3.0-alpha2`.
- Krile now reads your `.gitignore` (at top level) and ignores all of the stuff in it.
## [0.2.0] - 2021-07-23
### Added
- Added a flag to toggle verbose log output.
## [0.1.0] - 2021-07-21
Initial release.

13
krile/Cargo.toml Normal file
View file

@ -0,0 +1,13 @@
[package]
name = "krile"
description = "A static site generator"
version = "0.5.6"
license = "AGPL-3.0-or-later"
edition = "2021"
repository = "https://codeberg.org/shadows_withal/shtola/src/branch/main/krile"
readme = "README.md"
[dependencies]
shtola = { version = "0.4.2", features = ["full"] }
argh = "~0.1"
minifemme = "~1.0"

27
krile/README.md Normal file
View file

@ -0,0 +1,27 @@
# krile
Krile is a reference implementation of a CLI frontend for [shtola](https://crates.io/crates/shtola).
It's pretty unstable, since it usually tracks prerelease versions of shtola, I mostly use it
for myself. You're welcome to use it as the basis for your own frontend though.
## Installation
```sh
cargo install krile
```
## Usage
```sh
# Minimal configuration
krile page-source/ # outputs to ./dest/
# Clean destination directory (my-dest/) before building
krile page-source/ my-dest/ -c
# Don't run the markdown plugin
krile page-source/ -i markdown
```
## License
AGPL 3.0.

87
krile/src/main.rs Normal file
View file

@ -0,0 +1,87 @@
use std::path::PathBuf;
use std::time::Instant;
use argh::FromArgs;
use shtola::log::*;
use shtola::plugins;
use shtola::Shtola;
const VERSION: &'static str = "0.5.6";
#[derive(FromArgs)]
/// A static site generator.
struct Args {
/// output the current version
#[argh(switch)]
version: bool,
/// the source directory
#[argh(option, short = 's', default = "PathBuf::from(\"./\")")]
source: PathBuf,
/// the destination directory
#[argh(option, short = 'd', default = "PathBuf::from(\"./dest\")")]
destination: PathBuf,
/// whether to wipe the destination directory before building
#[argh(switch, short = 'c')]
clean: bool,
/// what plugins to not run
#[argh(option, short = 'i')]
ignored_plugins: Vec<String>,
/// whether to skip parsing frontmatter (will probably break plugins)
#[argh(switch)]
no_frontmatter: bool,
/// whether to output debug stuff
#[argh(switch, short = 'v')]
verbose: bool,
}
fn main() {
let args: Args = argh::from_env();
if args.version {
println!("{}", VERSION);
std::process::exit(0);
}
if args.verbose {
minifemme::start(minifemme::LevelFilter::Trace, minifemme::LogMode::Pretty);
} else {
minifemme::start(minifemme::LevelFilter::Info, minifemme::LogMode::Pretty);
}
info!("Starting build");
let start = Instant::now();
let mut sh = Shtola::new();
sh.source(&args.source);
sh.destination(args.destination);
sh.clean(args.clean);
sh.frontmatter(!args.no_frontmatter);
let potential_gitignore = args.source.join(".gitignore");
if potential_gitignore.exists() {
sh.source_ignores(&potential_gitignore).unwrap();
}
let potential_krileignore = args.source.join(".krileignore");
if potential_krileignore.exists() {
sh.source_ignores(&potential_krileignore).unwrap();
}
if !args.ignored_plugins.contains(&"markdown".to_string()) {
sh.register(plugins::markdown::plugin());
}
if !args.ignored_plugins.contains(&"tera_layouts".to_string()) {
sh.register(plugins::tera_layouts::plugin());
}
if !args.ignored_plugins.contains(&"pretty_links".to_string()) {
sh.register(plugins::pretty_links::plugin());
}
sh.build().unwrap();
info!(
"Finished build in {:?}",
Instant::now().duration_since(start)
);
}