diff --git a/htmlua-parser/src/config.rs b/htmlua-parser/src/config.rs
index ffe1320..de734ed 100644
--- a/htmlua-parser/src/config.rs
+++ b/htmlua-parser/src/config.rs
@@ -95,5 +95,6 @@ impl Config {
Ok(())
}
+ #[must_use]
pub fn config_file_path() -> PathBuf { Self::get_config_path() }
}
diff --git a/htmlua-parser/src/helpers.rs b/htmlua-parser/src/helpers.rs
index 3db0443..2992f70 100644
--- a/htmlua-parser/src/helpers.rs
+++ b/htmlua-parser/src/helpers.rs
@@ -6,7 +6,7 @@ use std::{
use anyhow::Result;
use kuchikiki::NodeRef;
-use markup5ever::{ns, LocalName, Namespace, namespace_url, QualName};
+use markup5ever::{LocalName, QualName, namespace_url, ns};
use tendril::TendrilSink;
diff --git a/htmlua-parser/src/render.rs b/htmlua-parser/src/render.rs
index e141020..6a70315 100644
--- a/htmlua-parser/src/render.rs
+++ b/htmlua-parser/src/render.rs
@@ -8,7 +8,7 @@ use std::{
use anyhow::{Result, anyhow};
use kuchikiki::{NodeRef, traits::TendrilSink};
use markup5ever::{LocalName, Namespace, QualName};
-use mlua::{Lua, Table};
+use mlua::Lua;
use pulldown_cmark::{Options, Parser, html};
use syntect::{
easy::HighlightLines,
@@ -215,7 +215,7 @@ pub fn generate_footnotes(document: NodeRef) -> Result {
#[cfg(test)]
mod tests {
use httptest::{Expectation, ServerPool, matchers::*, responders::*};
- use markup5ever::{ns, namespace_url};
+ use markup5ever::{namespace_url, ns};
use super::*;
@@ -417,7 +417,14 @@ mod tests {
let ctx_name = QualName::new(None, ns!(html), LocalName::from("div"));
let document = kuchikiki::parse_fragment(ctx_name, Vec::new()).one(page);
let d = expand_template(document, &p, None).unwrap();
- let text = d.select_first("head").unwrap().as_node().select_first("title").unwrap().as_node().text_contents();
+ let text = d
+ .select_first("head")
+ .unwrap()
+ .as_node()
+ .select_first("title")
+ .unwrap()
+ .as_node()
+ .text_contents();
assert_eq!(text, "title_test");
let text = d.select_first("#tb").unwrap().as_node().text_contents();
assert_eq!(text, "body_el");
diff --git a/htmlua-parser/src/serve.rs b/htmlua-parser/src/serve.rs
index 715bfcc..375e885 100644
--- a/htmlua-parser/src/serve.rs
+++ b/htmlua-parser/src/serve.rs
@@ -1,6 +1,6 @@
use std::{path::Path, sync::OnceLock};
-use anyhow::Result;
+use anyhow::{Result, anyhow};
use crate::{
config::Config,
@@ -13,7 +13,7 @@ static CONFIG: OnceLock = OnceLock::new();
pub fn get_config() -> &'static Config {
CONFIG.get_or_init(|| {
Config::load().unwrap_or_else(|e| {
- eprintln!("Warning: Failed to load config: {}", e);
+ eprintln!("Warning: Failed to load config: {e}");
eprintln!("Using default configuration");
Config::default()
})
@@ -24,8 +24,10 @@ pub fn serve_content(request_uri: &str) -> Result {
let config = get_config();
let safe_path = Path::new(request_uri).strip_prefix("/")?;
let page_path = config.paths.pages.join(safe_path);
- let doc = read_doc_from_file(page_path)?;
- let full_doc = expand_template(doc, &config.paths.components, None)?;
+ let doc = read_doc_from_file(page_path)?
+ .select_first("html")
+ .map_err(|()| anyhow!("failed to read doc"))?;
+ let full_doc = expand_template(doc.as_node().to_owned(), &config.paths.components, None)?;
let markdown_doc = process_markdown(full_doc)?;
let highlighted_doc = process_syntax_highlighting(markdown_doc)?;
let executed_doc = execute_lua(highlighted_doc)?;