Skip to content

Commit

Permalink
Create directories for manually set paths
Browse files Browse the repository at this point in the history
  • Loading branch information
grego committed Oct 11, 2022
1 parent 82cda13 commit 837107d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 127 deletions.
154 changes: 31 additions & 123 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 Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blades"
version = "0.4.0"
version = "0.4.1"
authors = ["Maroš Grego <[email protected]>"]
edition = "2021"
description = "Blazing fast dead simple static site generator"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ const fn default_assets() -> Cow<'static, str> {
}

#[inline]
const fn default_true() -> bool {
pub(crate) const fn default_true() -> bool {
true
}
14 changes: 12 additions & 2 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// You should have received a copy of the GNU General Public License
// along with Blades. If not, see <http://www.gnu.org/licenses/>
use crate::config::Site;
use crate::config::{default_true, Site};
use crate::sources::{Parser, Source, Sources};
use crate::tasks::render;
use crate::taxonomies::{Classification, Taxonomies};
Expand Down Expand Up @@ -106,6 +106,9 @@ pub struct Page<'p> {
#[serde(skip)]
#[ramhorns(skip)]
next: usize,
#[serde(skip, default = "default_true")]
#[ramhorns(skip)]
nonstandard_path: bool,
/// Priority of this page in the sitemap
#[serde(skip, default = "default_priority")]
pub priority: f32,
Expand Down Expand Up @@ -142,7 +145,7 @@ pub struct Pages<'p>(Box<[Page<'p>]>);
/// A single picture on a page.
#[derive(Clone, Content, Deserialize, Serialize)]
pub struct Picture<'p> {
/// An alternative text displayed when the image can't be loaded of for accessibility.
/// An alternative text displayed when the image can't be loaded or for accessibility.
#[serde(borrow, default)]
pub alt: Cow<'p, str>,
/// An associated caption of the picture.
Expand Down Expand Up @@ -322,6 +325,7 @@ impl<'p> Page<'p> {
if is_section || page_path.is_empty() || Path::new(page_path).is_absolute() {
let path = &path[0..path.rfind(is_separator).unwrap_or_default()];
page.path = Cow::const_str(path).into();
page.nonstandard_path = false;
} else if page_path == "." {
page.path = Cow::const_str("").into();
}
Expand Down Expand Up @@ -385,6 +389,9 @@ impl<'p> Page<'p> {
let mut path = output_dir.join(self.path.as_ref());
path.push(self.slug.as_ref());
create_dir_all(path)
} else if self.nonstandard_path {
let path = output_dir.join(self.path.as_ref());
create_dir_all(path)
} else {
Ok(())
}
Expand Down Expand Up @@ -588,6 +595,9 @@ impl<'p> Pages<'p> {
pages[j].next = j + 1;
}
}

// Assign a unique identifier
pages[i].id = i;
}
Pages(pages.into())
}
Expand Down

0 comments on commit 837107d

Please sign in to comment.