Add forced full-site rendering
This commit is contained in:
@@ -29,13 +29,70 @@ pub fn write_generated_file(
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &str,
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
write_generated_file_with_mode(
|
||||
conn,
|
||||
output_dir,
|
||||
project_id,
|
||||
relative_path,
|
||||
content,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn write_generated_file_verified(
|
||||
conn: &Connection,
|
||||
output_dir: &Path,
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &str,
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
write_generated_file_with_mode(
|
||||
conn,
|
||||
output_dir,
|
||||
project_id,
|
||||
relative_path,
|
||||
content,
|
||||
false,
|
||||
true,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn write_generated_file_forced(
|
||||
conn: &Connection,
|
||||
output_dir: &Path,
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &str,
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
write_generated_file_with_mode(
|
||||
conn,
|
||||
output_dir,
|
||||
project_id,
|
||||
relative_path,
|
||||
content,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
}
|
||||
|
||||
fn write_generated_file_with_mode(
|
||||
conn: &Connection,
|
||||
output_dir: &Path,
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &str,
|
||||
force: bool,
|
||||
verify_output: bool,
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let hash = content_hash(content.as_bytes());
|
||||
let target_path = output_dir.join(relative_path);
|
||||
if let Ok(existing) = qhash::get_generated_file_hash(conn, project_id, relative_path)
|
||||
if !force
|
||||
&& let Ok(existing) = qhash::get_generated_file_hash(conn, project_id, relative_path)
|
||||
&& existing.content_hash == hash
|
||||
&& target_path.exists()
|
||||
&& file_hash(&target_path)? == hash
|
||||
&& (!verify_output || file_hash(&target_path)? == hash)
|
||||
{
|
||||
return Ok(GeneratedWriteOutcome::SkippedUnchanged);
|
||||
}
|
||||
@@ -64,13 +121,34 @@ pub fn write_generated_bytes(
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &[u8],
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
write_generated_bytes_with_force(conn, output_dir, project_id, relative_path, content, false)
|
||||
}
|
||||
|
||||
pub fn write_generated_bytes_forced(
|
||||
conn: &Connection,
|
||||
output_dir: &Path,
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &[u8],
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
write_generated_bytes_with_force(conn, output_dir, project_id, relative_path, content, true)
|
||||
}
|
||||
|
||||
fn write_generated_bytes_with_force(
|
||||
conn: &Connection,
|
||||
output_dir: &Path,
|
||||
project_id: &str,
|
||||
relative_path: &str,
|
||||
content: &[u8],
|
||||
force: bool,
|
||||
) -> Result<GeneratedWriteOutcome, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let hash = content_hash(content);
|
||||
let target_path = output_dir.join(relative_path);
|
||||
if let Ok(existing) = qhash::get_generated_file_hash(conn, project_id, relative_path)
|
||||
if !force
|
||||
&& let Ok(existing) = qhash::get_generated_file_hash(conn, project_id, relative_path)
|
||||
&& existing.content_hash == hash
|
||||
&& target_path.exists()
|
||||
&& file_hash(&target_path)? == hash
|
||||
{
|
||||
return Ok(GeneratedWriteOutcome::SkippedUnchanged);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ mod template_lookup;
|
||||
|
||||
pub use generation::{
|
||||
CalendarArchiveData, GeneratedWriteOutcome, build_calendar_json, build_core_generation_paths,
|
||||
write_generated_bytes, write_generated_file,
|
||||
write_generated_bytes, write_generated_bytes_forced, write_generated_file,
|
||||
write_generated_file_forced, write_generated_file_verified,
|
||||
};
|
||||
pub use markdown::render_markdown_to_html;
|
||||
pub use page_renderer::{RenderError, render_liquid_template};
|
||||
|
||||
Reference in New Issue
Block a user