summaryrefslogtreecommitdiff
path: root/src/generate_html.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/generate_html.rs')
-rw-r--r--src/generate_html.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/generate_html.rs b/src/generate_html.rs
index 33158a5..306892b 100644
--- a/src/generate_html.rs
+++ b/src/generate_html.rs
@@ -28,12 +28,10 @@ pub fn generate_html(page: &Page, website: &Website) -> String {
None => String::new(),
};
let toc = get_table_of_contents(page);
- let toc_main = if page.headings.len() > 3 {
+ let toc_main = if page.headings.len() >= 3 {
format!("<details><summary></summary>\n{toc}</details>\n")
} else { String::new() };
- let toc_side = if page.headings.len() > 3 {
- format!("<div>{toc}</div>\n")
- } else { String::new() };
+ let toc_side = format!("<div>{toc}</div>\n");
let main = document_to_html(page, website); let main = main.trim();
format!("\
@@ -45,7 +43,8 @@ pub fn generate_html(page: &Page, website: &Website) -> String {
{head}
</head>
<body>
-<nav id='toc-side'>
+<nav id='outline' class='hidden'>
+<h1></h1>
{toc_side}
</nav>
<div id='page'>
@@ -107,9 +106,6 @@ pub fn get_html_head(page: &Page, website: &Website) -> String {
pub fn get_table_of_contents(page: &Page) -> String {
- if page.headings.len() < 3 {
- return String::new();
- }
let mut toc = String::from("<ul>\n");
let site_name = sanitize_text(&page.name, true);
toc.push_str(&format!("<li class='l1'><a href='#title'>{site_name}</a></li>\n"));
@@ -146,21 +142,27 @@ pub fn document_to_html(page: &Page, website: &Website) -> String {
($t:expr,$f:expr) => {{ html!("<{}>", $t); $f; html!("</{}>", $t); }}; }
wrap!("article",
- for block in &page.document.blocks {
+ for (i, block) in page.document.blocks.iter().enumerate() {
match block {
Block::Heading { level, line } => {
if let Level::Heading1 = level {
html!("</article>");
html!("<article>");
+ // html!("<nav class='return'><a href='#'></a></nav>");
+ };
+ // Find namespaced heading ID from headings list.
+ let url = match page.headings.iter().find(|h| h.block_id == i) {
+ Some(heading) => heading.url.clone(),
+ None => unreachable!("Couldn't find heading in headings list"),
};
- let id = make_url_safe(strip_appendix(&line.to_string()));
+ // let url = make_url_safe(strip_appendix(&line.to_string()));
let heading_tag = match level {
Level::Heading1 => "h1",
Level::Heading2 => "h2",
Level::Heading3 => "h3",
};
- wrap!(heading_tag, format!("id='{id}'"), {
- tag!("a", line, format!("href='#{id}'"));
+ wrap!(heading_tag, format!("id='{url}'"), {
+ tag!("a", line, format!("href='#{url}'"));
});
}
Block::Paragraph(line) => tag!("p", line),