Improve config loading

main
trivernis 1 year ago
parent b7b262718d
commit 9613035188
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -7,6 +7,9 @@ use clap::{Parser, Subcommand};
pub struct Args {
#[command(subcommand)]
pub command: Command,
#[clap(default_value = ".")]
pub directory: PathBuf,
}
#[derive(Clone, Debug, Subcommand)]
@ -16,7 +19,4 @@ pub enum Command {
}
#[derive(Clone, Debug, Parser)]
pub struct BuildArgs {
#[clap(default_value = ".")]
pub directory: PathBuf,
}
pub struct BuildArgs {}

@ -2,17 +2,24 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum Page {
Data(PageMetadata),
Data(PageData),
Content(String),
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PageMetadata {
/// template used to render this page
pub template: Option<String>,
pub struct PageData {
/// Metadata for this page
#[serde(default)]
pub metadata: PageMetadata,
/// remaining data of this page
/// passed to the templates when rendering
#[serde(flatten)]
pub data: toml::Value,
}
#[derive(Default, Clone, Debug, Deserialize, Serialize)]
pub struct PageMetadata {
/// template used to render this page
pub template: Option<String>,
}

@ -19,17 +19,17 @@ async fn main() -> Result<()> {
let args: Args = Args::parse();
init_tracing();
match args.command {
match &args.command {
args::Command::Build(build_args) => {
let cfg = read_config(&build_args.directory).await?;
build(cfg, build_args).await
let cfg = read_config(&args.directory).await?;
build(&args, &build_args, cfg).await
}
}
}
async fn build(cfg: Config, args: BuildArgs) -> Result<()> {
async fn build(args: &Args, _build_args: &BuildArgs, cfg: Config) -> Result<()> {
let folders = cfg.folders;
let base_path = args.directory;
let base_path = &args.directory;
let content_dir = base_path.join(folders.content.unwrap_or("content".into()));
let template_dir = base_path.join(folders.templates.unwrap_or("templates".into()));
let out_dir = base_path.join(folders.output.unwrap_or("public".into()));

@ -45,7 +45,7 @@ impl ContentRenderer {
match page {
crate::data::Page::Data(data) => {
if let Some(tmpl) = data.template {
if let Some(tmpl) = data.metadata.template {
template_name = tmpl;
}
context.insert("data", &data.data);

Loading…
Cancel
Save