Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat:] Add Watch Feature to Monitor Input Folder for Changes #60

Merged
merged 11 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ keywords = ["web", "blog", "static", "site", "html"]
[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9"
hotwatch = "0.5"
tera = "1.20"
comrak = {version = "0.29.0", features = ["shortcodes"]}
walkdir = "2.5"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Arguments:

Options:
--serve Serve the site with a built-in HTTP server
--watch Watch for file changes and rebuild site
--bind <BIND> [default: localhost:8000]
--config <CONFIG> Path to custom configuration file (defaults to marmite.yaml) [default: marmite.yaml]
--debug Print debug messages
Expand Down
60 changes: 32 additions & 28 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
use clap::Parser;
use std::path::PathBuf;

/// Command Line Argument Parser for Marmite CLI
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Cli {
/// Input folder containing markdown files
pub input_folder: PathBuf,

/// Output folder to generate the site
pub output_folder: PathBuf,

/// Serve the site with a built-in HTTP server
#[arg(long)]
pub serve: bool,

#[arg(long, default_value = "localhost:8000")]
pub bind: String,

/// Path to custom configuration file (defaults to marmite.yaml)
#[arg(long, default_value = "marmite.yaml")]
pub config: String,

/// Print debug messages
#[arg(long)]
pub debug: bool,
}
use clap::Parser;
use std::path::PathBuf;

/// Command Line Argument Parser for Marmite CLI
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Cli {
/// Input folder containing markdown files
pub input_folder: PathBuf,

/// Output folder to generate the site
pub output_folder: PathBuf,

/// Serve the site with a built-in HTTP server
#[arg(long)]
pub serve: bool,

/// Detect changes and rebuild the site automatically
#[arg(long)]
pub watch: bool,

#[arg(long, default_value = "localhost:8000")]
pub bind: String,

/// Path to custom configuration file (defaults to marmite.yaml)
#[arg(long, default_value = "marmite.yaml")]
pub config: String,

/// Print debug messages
#[arg(long)]
pub debug: bool,
}
100 changes: 50 additions & 50 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,45 @@ use serde::{Deserialize, Serialize};
use serde_yaml::Value;
use std::collections::HashMap;

#[derive(Debug, Deserialize, Serialize)]
pub struct Marmite<'a> {
#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Marmite {
#[serde(default = "default_name")]
pub name: &'a str,
pub name: String,
#[serde(default = "default_tagline")]
pub tagline: &'a str,
pub tagline: String,
#[serde(default = "default_url")]
pub url: &'a str,
pub url: String,
#[serde(default = "default_footer")]
pub footer: &'a str,
pub footer: String,
#[serde(default = "default_pagination")]
pub pagination: u32,

#[serde(default = "default_list_title")]
pub list_title: &'a str,
pub list_title: String,
#[serde(default = "default_pages_title")]
pub pages_title: &'a str,
pub pages_title: String,
#[serde(default = "default_tags_title")]
pub tags_title: &'a str,
pub tags_title: String,
#[serde(default = "default_tags_content_title")]
pub tags_content_title: &'a str,
pub tags_content_title: String,
#[serde(default = "default_archives_title")]
pub archives_title: &'a str,
pub archives_title: String,

#[serde(default = "default_content_path")]
pub content_path: &'a str,
pub content_path: String,
#[serde(default = "default_site_path")]
pub site_path: &'a str,
pub site_path: String,
#[serde(default = "default_templates_path")]
pub templates_path: &'a str,
pub templates_path: String,
#[serde(default = "default_static_path")]
pub static_path: &'a str,
pub static_path: String,
#[serde(default = "default_media_path")]
pub media_path: &'a str,
pub media_path: String,

#[serde(default = "default_card_image")]
pub card_image: &'a str,
pub card_image: String,
#[serde(default = "default_logo_image")]
pub logo_image: &'a str,
pub logo_image: String,

#[serde(default = "default_menu")]
pub menu: Option<Vec<(String, String)>>,
Expand All @@ -49,72 +49,72 @@ pub struct Marmite<'a> {
pub data: Option<HashMap<String, Value>>,
}

fn default_name() -> &'static str {
"Home"
fn default_name() -> String {
"Home".to_string()
}

fn default_tagline() -> &'static str {
"Site generated from markdown content"
fn default_tagline() -> String {
"Site generated from markdown content".to_string()
}

fn default_url() -> &'static str {
""
fn default_url() -> String {
String::new()
}

fn default_footer() -> &'static str {
r#"<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC-BY_NC-SA</a> | Site generated with <a href="https://github.com/rochacbruno/marmite">Marmite</a>"#
fn default_footer() -> String {
r#"<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC-BY_NC-SA</a> | Site generated with <a href="https://github.com/rochacbruno/marmite">Marmite</a>"#.to_string()
}

fn default_pagination() -> u32 {
10
}

fn default_list_title() -> &'static str {
"Posts"
fn default_list_title() -> String {
"Posts".to_string()
}

fn default_tags_title() -> &'static str {
"Tags"
fn default_tags_title() -> String {
"Tags".to_string()
}

fn default_tags_content_title() -> &'static str {
"Posts tagged with '$tag'"
fn default_tags_content_title() -> String {
"Posts tagged with '$tag'".to_string()
}

fn default_pages_title() -> &'static str {
"Pages"
fn default_pages_title() -> String {
"Pages".to_string()
}

fn default_archives_title() -> &'static str {
"Archive"
fn default_archives_title() -> String {
"Archive".to_string()
}

fn default_site_path() -> &'static str {
""
fn default_site_path() -> String {
String::new()
}

fn default_content_path() -> &'static str {
"content"
fn default_content_path() -> String {
"content".to_string()
}

fn default_templates_path() -> &'static str {
"templates"
fn default_templates_path() -> String {
"templates".to_string()
}

fn default_static_path() -> &'static str {
"static"
fn default_static_path() -> String {
"static".to_string()
}

fn default_media_path() -> &'static str {
"media"
fn default_media_path() -> String {
"media".to_string()
}

fn default_card_image() -> &'static str {
""
fn default_card_image() -> String {
String::new()
}

fn default_logo_image() -> &'static str {
""
fn default_logo_image() -> String {
String::new()
}

fn default_menu() -> Option<Vec<(String, String)>> {
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fn main() {
let output_folder = Arc::new(args.output_folder);
let serve = args.serve;

let watch = args.watch;
let config_path = if args.config.starts_with('.') || args.config.starts_with('/') {
PathBuf::new().join(args.config)
} else {
Expand All @@ -32,7 +33,7 @@ fn main() {
error!("Logger already initialized: {}", e);
}

site::generate(&config_path, &input_folder, &output_folder);
site::generate(&config_path, &input_folder, &output_folder, watch);

// Serve the site if the flag was provided
if serve {
Expand Down
Loading