Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Windows support #26

Merged
merged 2 commits into from Dec 24, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 13 additions & 15 deletions src/commands/build.rs
Expand Up @@ -112,7 +112,7 @@ pub(crate) async fn process_file(
.await?
}
(fpm::File::Static(main_sa), fpm::File::Static(_)) => {
process_static(main_sa, config.root.as_str()).await?
process_static(main_sa, &config.root).await?
}
(fpm::File::Markdown(main_sa), fpm::File::Markdown(_)) => {
process_markdown(main_sa, config).await?
Expand All @@ -131,7 +131,7 @@ pub(crate) async fn process_file(
}
match main {
fpm::File::Ftd(doc) => process_ftd(config, doc, None, message, translated_data).await?,
fpm::File::Static(sa) => process_static(sa, config.root.as_str()).await?,
fpm::File::Static(sa) => process_static(sa, &config.root).await?,
fpm::File::Markdown(doc) => process_markdown(doc, config).await?,
}
println!("Processed {}", main.get_id());
Expand All @@ -155,21 +155,19 @@ async fn process_ftd(
message: Option<&str>,
translated_data: fpm::TranslationData,
) -> fpm::Result<()> {
let base_path = config.root.as_str();
if !main.id.eq("index.ftd") {
std::fs::create_dir_all(format!(
"{}/.build/{}",
base_path,
main.id.replace(".ftd", "")
))?;
std::fs::create_dir_all(config.root.join(".build").join(main.id.replace(".ftd", "")))?;
}
let file_rel_path = if main.id.eq("index.ftd") {
"index.html".to_string()
} else {
main.id.replace(".ftd", "/index.html")
main.id.replace(
".ftd",
format!("{}index.html", std::path::MAIN_SEPARATOR).as_str(),
)
};

let new_file_path = format!("{}/.build/{}", base_path, file_rel_path.as_str());
let new_file_path = config.root.join(".build").join(file_rel_path);

match (fallback, message) {
(Some(fallback), Some(message)) => {
Expand Down Expand Up @@ -441,13 +439,13 @@ async fn process_ftd(
}
}

async fn process_static(sa: &fpm::Static, base_path: &str) -> fpm::Result<()> {
if let Some((dir, _)) = sa.id.rsplit_once("/") {
std::fs::create_dir_all(format!("{}/.build/{}", base_path, dir))?;
async fn process_static(sa: &fpm::Static, base_path: &camino::Utf8Path) -> fpm::Result<()> {
if let Some((dir, _)) = sa.id.rsplit_once(std::path::MAIN_SEPARATOR) {
std::fs::create_dir_all(base_path.join(".build").join(dir))?;
}
std::fs::copy(
format!("{}/{}", sa.base_path, sa.id),
format!("{}/.build/{}", base_path, sa.id),
sa.base_path.join(sa.id.as_str()),
base_path.join(".build").join(sa.id.as_str()),
)?;
Ok(())
}
16 changes: 11 additions & 5 deletions src/document.rs
Expand Up @@ -40,7 +40,7 @@ pub struct Document {
#[derive(Debug, Clone)]
pub struct Static {
pub id: String,
pub base_path: String,
pub base_path: camino::Utf8PathBuf,
}

pub(crate) async fn get_documents(config: &fpm::Config) -> fpm::Result<Vec<fpm::File>> {
Expand Down Expand Up @@ -104,7 +104,7 @@ pub(crate) async fn get_file(
let id = match std::fs::canonicalize(doc_path)?
.to_str()
.unwrap()
.rsplit_once(format!("{}/", base_path).as_str())
.rsplit_once(format!("{}{}", base_path, std::path::MAIN_SEPARATOR).as_str())
{
Some((_, id)) => id.to_string(),
None => {
Expand All @@ -122,8 +122,14 @@ pub(crate) async fn get_file(
}),
Some((doc_name, "md")) => File::Markdown(Document {
id: if doc_name == "README"
&& !(std::path::Path::new("./index.ftd").exists()
|| std::path::Path::new("./index.md").exists())
&& !(std::path::Path::new(
format!(".{}index.ftd", std::path::MAIN_SEPARATOR).as_str(),
)
.exists()
|| std::path::Path::new(
format!(".{}index.md", std::path::MAIN_SEPARATOR).as_str(),
)
.exists())
{
"index.md".to_string()
} else {
Expand All @@ -134,7 +140,7 @@ pub(crate) async fn get_file(
}),
_ => File::Static(Static {
id: id.to_string(),
base_path: base_path.to_string(),
base_path: base_path.to_path_buf(),
}),
})
}