minor refactors here and there
This commit is contained in:
parent
77b5d8f510
commit
7bbc6b8d5d
|
@ -0,0 +1 @@
|
||||||
|
/target
|
|
@ -5,6 +5,9 @@ edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
toml = "0.5"
|
toml = "0.5"
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -1,10 +1,10 @@
|
||||||
use chrono::{DateTime, NaiveDateTime};
|
use chrono::NaiveDateTime;
|
||||||
use html5ever::tendril::SliceExt;
|
use html5ever::tendril::SliceExt;
|
||||||
use nipper::{Document, Node, Selection};
|
use nipper::{Document, Selection};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::borrow::{Borrow, Cow};
|
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::{read_to_string, File};
|
use std::fs::{read_to_string, File};
|
||||||
|
@ -68,8 +68,8 @@ fn main() -> Result<(), Error> {
|
||||||
let index = Document::from(read_to_string(index_file)?.as_str());
|
let index = Document::from(read_to_string(index_file)?.as_str());
|
||||||
for post in &posts {
|
for post in &posts {
|
||||||
let template_html = Document::from(template.as_str());
|
let template_html = Document::from(template.as_str());
|
||||||
let mut output_html = template_html;
|
let output_html = template_html;
|
||||||
let mut typeset_elements = output_html.select("meta[typeset]");
|
let typeset_elements = output_html.select("meta[typeset]");
|
||||||
for mut element in typeset_elements.iter() {
|
for mut element in typeset_elements.iter() {
|
||||||
match element.attr("typeset").unwrap().to_string().as_str() {
|
match element.attr("typeset").unwrap().to_string().as_str() {
|
||||||
"page-title" => {
|
"page-title" => {
|
||||||
|
@ -78,7 +78,7 @@ fn main() -> Result<(), Error> {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace("$", post.title.as_str());
|
.replace("$", post.title.as_str());
|
||||||
|
|
||||||
element.replace_with_html(format!(r#"<title>{}</title>"#, title));
|
element.replace_with_html(format!(r#"<title>{title}</title>"#));
|
||||||
}
|
}
|
||||||
"title" => {
|
"title" => {
|
||||||
element.replace_with_html(post.title.to_string());
|
element.replace_with_html(post.title.to_string());
|
||||||
|
@ -94,7 +94,7 @@ fn main() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let output = output_html.html().to_string();
|
let output = output_html.html().to_string();
|
||||||
let path = out_path.join(PathBuf::from(format!("{}{}", &post.id, ".html")));
|
let path = out_path.join(PathBuf::from(format!("{}.html", &post.id)));
|
||||||
let mut file = File::create(path)?;
|
let mut file = File::create(path)?;
|
||||||
file.write_all(output.as_bytes())?;
|
file.write_all(output.as_bytes())?;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ fn main() -> Result<(), Error> {
|
||||||
"Found {} post lists",
|
"Found {} post lists",
|
||||||
index.select(r#"meta[typeset="index-entry""#).length()
|
index.select(r#"meta[typeset="index-entry""#).length()
|
||||||
);
|
);
|
||||||
for mut index_ref in index.select(r#"meta[typeset="index-entry""#).iter() {
|
for index_ref in index.select(r#"meta[typeset="index-entry""#).iter() {
|
||||||
let n = index_ref
|
let n = index_ref
|
||||||
.attr("content")
|
.attr("content")
|
||||||
.unwrap_or("".to_tendril())
|
.unwrap_or("".to_tendril())
|
||||||
|
@ -119,11 +119,7 @@ fn main() -> Result<(), Error> {
|
||||||
nth_children(parent.parent(), n)
|
nth_children(parent.parent(), n)
|
||||||
.select(r#"meta[typeset="index-entry""#)
|
.select(r#"meta[typeset="index-entry""#)
|
||||||
.replace_with_html(
|
.replace_with_html(
|
||||||
format!(
|
format!("<a href=\"./{}.html\">{}</a>\n", post.id, post.title).as_str(),
|
||||||
"<a href=\"./{}.html\">{}</a>\n",
|
|
||||||
post.id, post.title
|
|
||||||
)
|
|
||||||
.as_str(),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
parent.parent().children().iter().nth(0).unwrap().remove();
|
parent.parent().children().iter().nth(0).unwrap().remove();
|
||||||
|
|
Loading…
Reference in New Issue