update
This commit is contained in:
@@ -328,7 +328,7 @@ async fn serve_file(path: &str) -> Result<(&'static str, Vec<u8>, &'static str)>
|
||||
// Remove query parameters from path
|
||||
let clean_path = path.split('?').next().unwrap_or(path);
|
||||
|
||||
let file_path = if clean_path == "/" {
|
||||
let mut file_path = if clean_path == "/" {
|
||||
PathBuf::from("public/index.html")
|
||||
} else {
|
||||
PathBuf::from("public").join(clean_path.trim_start_matches('/'))
|
||||
@@ -337,9 +337,42 @@ async fn serve_file(path: &str) -> Result<(&'static str, Vec<u8>, &'static str)>
|
||||
println!("Serving file: {}", file_path.display());
|
||||
|
||||
// Check if file exists and get metadata
|
||||
let metadata = tokio::fs::metadata(&file_path).await?;
|
||||
if !metadata.is_file() {
|
||||
return Err(anyhow::anyhow!("Not a file: {}", file_path.display()));
|
||||
let metadata = tokio::fs::metadata(&file_path).await;
|
||||
|
||||
match metadata {
|
||||
Ok(meta) if meta.is_file() => {
|
||||
// File exists, proceed normally
|
||||
}
|
||||
Ok(meta) if meta.is_dir() => {
|
||||
// Directory exists, try to serve index.html
|
||||
file_path = file_path.join("index.html");
|
||||
println!("Directory found, trying index.html: {}", file_path.display());
|
||||
let index_metadata = tokio::fs::metadata(&file_path).await?;
|
||||
if !index_metadata.is_file() {
|
||||
return Err(anyhow::anyhow!("No index.html in directory: {}", file_path.display()));
|
||||
}
|
||||
}
|
||||
Ok(_) => {
|
||||
return Err(anyhow::anyhow!("Not a file: {}", file_path.display()));
|
||||
}
|
||||
Err(e) => {
|
||||
// Try adding index.html to the original path
|
||||
let index_path = PathBuf::from("public")
|
||||
.join(clean_path.trim_start_matches('/'))
|
||||
.join("index.html");
|
||||
|
||||
println!("File not found, trying index.html: {}", index_path.display());
|
||||
let index_metadata = tokio::fs::metadata(&index_path).await;
|
||||
if let Ok(meta) = index_metadata {
|
||||
if meta.is_file() {
|
||||
file_path = index_path;
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("Original error: {}", e));
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("File not found: {}", file_path.display()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (content_type, cache_control) = match file_path.extension().and_then(|ext| ext.to_str()) {
|
||||
|
@@ -86,6 +86,9 @@ impl Generator {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate PDS page
|
||||
self.generate_pds_page().await?;
|
||||
|
||||
println!("{} {} posts", "Generated".cyan(), posts.len());
|
||||
|
||||
Ok(())
|
||||
@@ -491,6 +494,30 @@ impl Generator {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn generate_pds_page(&self) -> Result<()> {
|
||||
let public_dir = self.base_path.join("public");
|
||||
let pds_dir = public_dir.join("pds");
|
||||
fs::create_dir_all(&pds_dir)?;
|
||||
|
||||
// Generate PDS page using the pds.html template
|
||||
let config_with_timestamp = self.create_config_with_timestamp()?;
|
||||
let mut context = tera::Context::new();
|
||||
context.insert("config", &config_with_timestamp);
|
||||
context.insert("site", &self.config.site);
|
||||
context.insert("page", &serde_json::json!({
|
||||
"title": "AT URI Browser",
|
||||
"description": "AT Protocol レコードをブラウズし、分散SNSのコンテンツを探索できます"
|
||||
}));
|
||||
|
||||
let rendered_content = self.template_engine.render("pds.html", &context)?;
|
||||
let output_path = pds_dir.join("index.html");
|
||||
fs::write(output_path, rendered_content)?;
|
||||
|
||||
println!("{} PDS page", "Generated".cyan());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn extract_plain_text(&self, html_content: &str) -> String {
|
||||
// Remove HTML tags and extract plain text
|
||||
let mut text = String::new();
|
||||
@@ -536,6 +563,7 @@ pub struct Post {
|
||||
pub extra: Option<serde_json::Value>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct Translation {
|
||||
pub lang: String,
|
||||
|
Reference in New Issue
Block a user