mirror of
https://github.com/zyllian/webdog.git
synced 2025-05-10 02:26:42 -07: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.
|
/// Data for extras.
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct ExtraData {
|
pub struct ExtraData {
|
||||||
/// The name of the extra to run.
|
/// The name of the extra to run.
|
||||||
pub name: String,
|
pub name: String,
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl SiteConfig {
|
||||||
pub struct TemplateMetadata {}
|
pub struct TemplateMetadata {}
|
||||||
|
|
||||||
/// Struct for the front matter in pages.
|
/// Struct for the front matter in pages.
|
||||||
#[derive(Debug, Default, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct PageMetadata {
|
pub struct PageMetadata {
|
||||||
/// The page's title.
|
/// The page's title.
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -7,7 +7,7 @@ use url::Url;
|
||||||
use webdog::{
|
use webdog::{
|
||||||
frontmatter::FrontMatter,
|
frontmatter::FrontMatter,
|
||||||
resource::{ResourceBuilderConfig, ResourceMetadata},
|
resource::{ResourceBuilderConfig, ResourceMetadata},
|
||||||
Site, SiteConfig,
|
PageMetadata, Site, SiteConfig,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The default project to use when creating a new one, embedded into the binary.
|
/// The default project to use when creating a new one, embedded into the binary.
|
||||||
|
@ -58,6 +58,11 @@ enum Commands {
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
command: ResourceCommands,
|
command: ResourceCommands,
|
||||||
},
|
},
|
||||||
|
/// For dealing with standard site pages.
|
||||||
|
Page {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
command: PageCommands,
|
||||||
|
},
|
||||||
/// Creates a new resource of the given type.
|
/// Creates a new resource of the given type.
|
||||||
New {
|
New {
|
||||||
/// The type of resource to create.
|
/// 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<()> {
|
fn main() -> eyre::Result<()> {
|
||||||
#[cfg(feature = "color-eyre")]
|
#[cfg(feature = "color-eyre")]
|
||||||
color_eyre::install()?;
|
color_eyre::install()?;
|
||||||
|
@ -218,6 +237,36 @@ fn main() -> eyre::Result<()> {
|
||||||
Ok(())
|
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 {
|
Commands::New {
|
||||||
resource_type,
|
resource_type,
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl<'r> ResourceTemplateData<'r> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// struct for adding custom meta content embeds
|
/// struct for adding custom meta content embeds
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct EmbedMetadata {
|
pub struct EmbedMetadata {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue