feat: Create site module

This commit is contained in:
Nathan McCarty 2023-03-15 20:27:00 -04:00
parent 68ccc95345
commit d7c7cffa1b
No known key found for this signature in database
2 changed files with 55 additions and 1 deletions

View File

@ -1,12 +1,17 @@
//! Management of on-disk layout of the source of a site
use self::config::Config;
use std::{collections::HashSet, path::PathBuf};
use self::{config::Config, page::Page};
pub mod config;
pub mod page;
/// Representation of the on-disk structure of a site
#[derive(Debug)]
pub struct Site {
/// Top level configuration
pub config: Config,
/// Non-post static pages
pub pages: HashSet<PathBuf, Page>,
}

49
src/site/page.rs Normal file
View File

@ -0,0 +1,49 @@
//! Management of a page
use std::path::PathBuf;
use serde::{Deserialize, Serialize};
/// Representation of the configuration for a page
#[derive(Serialize, Deserialize, Debug)]
pub struct PageConfig {
/// Title of the page
title: String,
/// Style sheets to apply
stylesheets: Vec<String>,
}
impl Default for PageConfig {
fn default() -> Self {
Self {
title: "Index".to_string(),
stylesheets: ["default", "index"]
.into_iter()
.map(str::to_string)
.collect(),
}
}
}
/// Representation of a page
#[derive(Debug)]
pub struct Page {
/// Configuration for the page
pub config: PageConfig,
/// Path to the djot file for the page
///
/// This can be any file in the appropiate directory with a `md` or `djot` extension, however
/// there can only be one file within the directory
///
/// This path is relative to the directory of the page
pub file: PathBuf,
}
impl Default for Page {
fn default() -> Self {
Self {
config: PageConfig::default(),
file: "index.djot".into(),
}
}
}