-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bruno rocha
committed
Oct 19, 2024
1 parent
2153a7d
commit ac0ee87
Showing
3 changed files
with
71 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
// Copy or create robots.txt | ||
const ROBOTS_SRC: &str = "robots.txt"; | ||
const DEFAULT_ROBOTS: &str = "User-agent: * | ||
Disallow: /private | ||
Allow: /public"; | ||
|
||
pub fn handle_robots(content_dir: &Path, output_path: &Path) { | ||
let robots_src = content_dir.join(ROBOTS_SRC); | ||
let robots_dst = output_path.join(ROBOTS_SRC); | ||
|
||
match robots_src.exists() { | ||
true => { | ||
if let Err(e) = fs::copy(&robots_src, &robots_dst) { | ||
eprintln!("Failed to copy robots.txt: {}", e); | ||
} else { | ||
println!("Copied robots.txt to output folder"); | ||
} | ||
} | ||
false => { | ||
if let Err(e) = fs::write(&robots_dst, DEFAULT_ROBOTS) { | ||
eprintln!("Failed to create default robots.txt: {}", e); | ||
} else { | ||
println!("Generated default robots.txt in output folder"); | ||
} | ||
} | ||
} | ||
} | ||
use log::{error, info}; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
// Copy or create robots.txt | ||
const ROBOTS_SRC: &str = "robots.txt"; | ||
const DEFAULT_ROBOTS: &str = "User-agent: * | ||
Disallow: /private | ||
Allow: /public"; | ||
|
||
pub fn handle_robots(content_dir: &Path, output_path: &Path) { | ||
let robots_src = content_dir.join(ROBOTS_SRC); | ||
let robots_dst = output_path.join(ROBOTS_SRC); | ||
|
||
match robots_src.exists() { | ||
true => { | ||
if let Err(e) = fs::copy(&robots_src, &robots_dst) { | ||
error!("Failed to copy robots.txt: {}", e); | ||
} else { | ||
info!("Copied robots.txt to output folder"); | ||
} | ||
} | ||
false => { | ||
if let Err(e) = fs::write(&robots_dst, DEFAULT_ROBOTS) { | ||
error!("Failed to create default robots.txt: {}", e); | ||
} else { | ||
info!("Generated default robots.txt in output folder"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters