Skip to content

Commit

Permalink
fix: no longer strips extensions in static directory
Browse files Browse the repository at this point in the history
  • Loading branch information
w-henderson committed Nov 27, 2022
1 parent 6265884 commit 5726114
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion stuart-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stuart_core"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT"
homepage = "https://github.com/w-henderson/Stuart"
Expand Down
15 changes: 12 additions & 3 deletions stuart-core/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl Node {
None => ParsedContents::None,
}
} else {
ParsedContents::None
ParsedContents::Ignored
};

Ok(Node::File {
Expand Down Expand Up @@ -333,12 +333,21 @@ impl Node {
child.save_recur(&dir, config)?;
}
}
Self::File { name, contents, .. } => {
Self::File {
name,
contents,
parsed_contents,
..
} => {
if name != "root.html"
&& name != "md.html"
&& (config.save_data_files || !name.ends_with(".json"))
{
if config.strip_extensions && name.ends_with(".html") && name != "index.html" {
if config.strip_extensions
&& name.ends_with(".html")
&& name != "index.html"
&& !parsed_contents.is_ignored()
{
let directory_name = name.strip_suffix(".html").unwrap().to_string();
let dir = path.join(directory_name);

Expand Down
11 changes: 10 additions & 1 deletion stuart-core/src/parse/contents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ pub enum ParsedContents {
Json(Value),
/// A file that was parsed by a plugin.
Custom(Rc<Box<dyn NodeProcessor>>),
/// The file was not parsed.
/// The file was not parsed because no parser was available.
None,
/// The file was not parsed because it was ignored.
Ignored,
}

impl ParsedContents {
Expand All @@ -41,11 +43,17 @@ impl ParsedContents {
}
}

/// Returns `true` if the contents were ignored.
pub fn is_ignored(&self) -> bool {
matches!(self, Self::Ignored)
}

/// Converts the parsed contents to a JSON value, if applicable.
pub fn to_json(&self) -> Option<Value> {
match self {
ParsedContents::Html(_) => None,
ParsedContents::None => None,
ParsedContents::Ignored => None,

ParsedContents::Markdown(md) => Some(json!({
"type": "markdown",
Expand All @@ -70,6 +78,7 @@ impl Debug for ParsedContents {
Self::Json(arg0) => f.debug_tuple("Json").field(arg0).finish(),
Self::Custom(_) => f.debug_tuple("Custom").finish(),
Self::None => write!(f, "None"),
Self::Ignored => write!(f, "Ignored"),
}
}
}
4 changes: 2 additions & 2 deletions stuart/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stuart"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
license = "MIT"
homepage = "https://github.com/w-henderson/Stuart"
Expand All @@ -15,7 +15,7 @@ name = "stuart"
path = "src/main.rs"

[dependencies]
stuart_core = { version = "^0.2.2", path = "../stuart-core" }
stuart_core = { version = "^0.2.3", path = "../stuart-core" }

clap = "^3.2"
toml = "^0.5"
Expand Down

0 comments on commit 5726114

Please sign in to comment.