commit - cf2f714a8988b299dff993cbee9ddbf86c8372d2
commit + 2e6b707359dc0f08cf7fcc054dedf926bafc168f
blob - /dev/null
blob + 879b53732d4c4885c1418820b484d8c1e3864f05 (mode 644)
--- /dev/null
+++ content/posts/primeiro-post.md
+---
+title: Primeiro Post
+date: 2026-04-03
+draft: false
+----
+
+# Meu primeiro post
+
+Conteúdo aqui.......
blob - baa7948ca14aef00755b9ee961de492c7fbcf862
blob + 2169a45cd1baf27dbb465447fbe6c5662a7a89e8
--- src/main.rs
+++ src/main.rs
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
-use std::{env, fs, collections::HashMap};
+use std::{env, fs, path::{Path, PathBuf}, collections::HashMap};
fn main() {
let args: Vec<String> = env::args().collect();
}
}
+//////////////////////////////////////////////////////////////////////////////
+// Filesystem
+//////////////////////////////////////////////////////////////////////////////
+fn walk(dir: &Path, files: &mut Vec<PathBuf>) {
+ let entries = match fs::read_dir(dir) {
+ Ok(e) => e,
+ Err(_) => return,
+ };
+
+ for entry in entries {
+ let path = match entry {
+ Ok(e) => e.path(),
+ Err(_) => continue,
+ };
+
+ if path.is_dir() {
+ walk(&path, files);
+ } else {
+ files.push(path);
+ }
+ }
+}
+
+fn copy_dir(src: &Path, dst: &Path) {
+ let mut files = Vec::new();
+ walk(src, &mut files);
+ for file in files {
+ let relative = file.strip_prefix(src).expect("strip prefix");
+ let target = dst.join(relative);
+ if let Some(parent) = target.parent() {
+ fs::create_dir_all(parent).expect("create dir");
+ }
+ fs::copy(file, &target).expect("copy file");
+ }
+}
+
+
//////////////////////////////////////////////////////////////////////////////
// Build
//////////////////////////////////////////////////////////////////////////////
fn build() {
- let md = fs::read_to_string("content/index.md")
- .expect("read content/index.md");
let template = fs::read_to_string("templates/base.html")
.expect("read templates/base.html");
- let meta = parse_frontmatter(&md);
+ let content_dir = Path::new("content");
+ let mut files = Vec::new();
+ walk(content_dir, &mut files);
- if meta.draft {
- return;
- }
+ for file in &files {
+ if file.extension().and_then(|e| e.to_str()) != Some("md") {
+ continue;
+ }
- let html_content = markdown::to_html_with_options(&md, &markdown::Options {
- parse: parse_options(),
- ..markdown::Options::default()
- }).expect("markdown to html");
+ let md = fs::read_to_string(file)
+ .expect("read content");
+ let meta = parse_frontmatter(&md);
- let output = template
- .replace("{{title}}", &meta.title)
- .replace("{{content}}", &html_content);
+ if meta.draft {
+ continue;
+ }
- fs::create_dir_all("public").expect("create public/");
- fs::write("public/index.html", output).expect("write public/index.html");
+ let html_content = markdown::to_html_with_options(&md, &markdown::Options {
+ parse: parse_options(),
+ ..markdown::Options::default()
+ }).expect("markdown to html");
- println!("build ok: public/index.html");
+ let relative = file.strip_prefix(content_dir).expect("strip prefix");
+ let out_path = Path::new("public").join(relative).with_extension("html");
+
+ if let Some(parent) = out_path.parent() {
+ fs::create_dir_all(parent).expect("create dir");
+ }
+
+ let output = template
+ .replace("{{title}}", &meta.title)
+ .replace("{{content}}", &html_content);
+
+ fs::write(&out_path, output).expect("write html");
+ println!("build ok: {}", out_path.display());
+ }
+
+ let static_dir = Path::new("static");
+ if static_dir.exists() {
+ copy_dir(static_dir, &Path::new("public/static"));
+ }
}
blob - /dev/null
blob + 18c51f5ba51cae75c667e89bf240331384f536df (mode 644)
--- /dev/null
+++ static/style.css
+body { max-width: 40em; margin: 0 auto; }