mirror of
https://github.com/zyllian/webdog.git
synced 2025-01-17 19:22:21 -08:00
add command for creating a new page
This commit is contained in:
parent
0d9c48db40
commit
b1a6e052e1
4 changed files with 53 additions and 4 deletions
|
@ -39,7 +39,7 @@ impl Extra {
|
|||
}
|
||||
|
||||
/// Data for extras.
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ExtraData {
|
||||
/// The name of the extra to run.
|
||||
pub name: String,
|
||||
|
|
|
@ -107,7 +107,7 @@ impl SiteConfig {
|
|||
pub struct TemplateMetadata {}
|
||||
|
||||
/// Struct for the front matter in pages.
|
||||
#[derive(Debug, Default, Deserialize)]
|
||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||
pub struct PageMetadata {
|
||||
/// The page's title.
|
||||
pub title: Option<String>,
|
||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -7,7 +7,7 @@ use url::Url;
|
|||
use webdog::{
|
||||
frontmatter::FrontMatter,
|
||||
resource::{ResourceBuilderConfig, ResourceMetadata},
|
||||
Site, SiteConfig,
|
||||
PageMetadata, Site, SiteConfig,
|
||||
};
|
||||
|
||||
/// The default project to use when creating a new one, embedded into the binary.
|
||||
|
@ -58,6 +58,11 @@ enum Commands {
|
|||
#[clap(subcommand)]
|
||||
command: ResourceCommands,
|
||||
},
|
||||
/// For dealing with standard site pages.
|
||||
Page {
|
||||
#[clap(subcommand)]
|
||||
command: PageCommands,
|
||||
},
|
||||
/// Creates a new resource of the given type.
|
||||
New {
|
||||
/// The type of resource to create.
|
||||
|
@ -91,6 +96,20 @@ enum ResourceCommands {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
enum PageCommands {
|
||||
/// Creates a new standard page.
|
||||
New {
|
||||
/// The page's ID.
|
||||
id: String,
|
||||
/// The page's title.
|
||||
title: Option<String>,
|
||||
/// The page's base template if using one other than the default.
|
||||
#[arg(long)]
|
||||
template: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
#[cfg(feature = "color-eyre")]
|
||||
color_eyre::install()?;
|
||||
|
@ -218,6 +237,36 @@ fn main() -> eyre::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
},
|
||||
Commands::Page { command } => match command {
|
||||
PageCommands::New {
|
||||
id,
|
||||
title,
|
||||
template,
|
||||
} => {
|
||||
let page_path = cli
|
||||
.site_path
|
||||
.join(webdog::PAGES_PATH)
|
||||
.join(&id)
|
||||
.with_extension("md");
|
||||
if page_path.exists() {
|
||||
eprintln!("page already exists!");
|
||||
return Ok(());
|
||||
}
|
||||
let fm = FrontMatter {
|
||||
content: "new page :)".to_string(),
|
||||
data: Some(PageMetadata {
|
||||
title,
|
||||
template,
|
||||
..Default::default()
|
||||
}),
|
||||
};
|
||||
std::fs::write(&page_path, fm.format()?)?;
|
||||
|
||||
println!("Page created! Edit at {:?}.", page_path);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
Commands::New {
|
||||
resource_type,
|
||||
id,
|
||||
|
|
|
@ -64,7 +64,7 @@ impl<'r> ResourceTemplateData<'r> {
|
|||
}
|
||||
|
||||
/// struct for adding custom meta content embeds
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct EmbedMetadata {
|
||||
pub title: String,
|
||||
#[serde(default)]
|
||||
|
|
Loading…
Add table
Reference in a new issue