From b598b7ad718774a5de2919462d45ab36d16d0690 Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Thu, 16 Mar 2023 14:47:52 -0400 Subject: [PATCH] feat: Default site value --- src/bin/cli/init.rs | 11 +++++++++-- src/site.rs | 15 +++++++++++++-- src/site/config.rs | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/bin/cli/init.rs b/src/bin/cli/init.rs index f5bbf7c..fb76625 100644 --- a/src/bin/cli/init.rs +++ b/src/bin/cli/init.rs @@ -1,6 +1,7 @@ use clap::Args; -use color_eyre::eyre::{bail, ensure, Context, Result}; -use tracing::instrument; +use color_eyre::eyre::{bail, Context, Result}; +use stranger_site_gen::site::Site; +use tracing::{debug, instrument}; use super::GlobalArgs; @@ -30,6 +31,12 @@ impl InitArgs { ); } println!("Initalizing new site in {}", site_dir.to_string_lossy()); + // Generate the default site, and change the domain if requested + let mut site = Site::default(); + if let Some(domain_name) = self.doman_name { + site.config.domain.domain_name = domain_name; + } + debug!(?site); todo!() } } diff --git a/src/site.rs b/src/site.rs index dbcbc5f..d8fab1d 100644 --- a/src/site.rs +++ b/src/site.rs @@ -1,6 +1,6 @@ //! Management of on-disk layout of the source of a site -use std::{collections::HashSet, path::PathBuf}; +use std::{collections::HashMap, path::PathBuf}; use self::{config::Config, page::Page}; @@ -13,5 +13,16 @@ pub struct Site { /// Top level configuration pub config: Config, /// Non-post static pages - pub pages: HashSet, + pub pages: HashMap, +} + +impl Default for Site { + fn default() -> Self { + let mut pages = HashMap::new(); + pages.insert("index".into(), Page::default()); + Self { + config: Config::default(), + pages, + } + } } diff --git a/src/site/config.rs b/src/site/config.rs index f037bbe..8e00ba7 100644 --- a/src/site/config.rs +++ b/src/site/config.rs @@ -23,7 +23,7 @@ impl Default for Domain { /// Top level configuration for a site /// /// Describes the file located at `site/config.dhall` -#[derive(Serialize, Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug, Default)] pub struct Config { /// Doman name settings pub domain: Domain,