Skip to content

Commit

Permalink
fix(ssg): 🐛 test and template fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Jan 14, 2024
1 parent ae6f635 commit aa3b754
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 81 deletions.
2 changes: 1 addition & 1 deletion content/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ image_width: "1200" ## The image width of the site.
image: "https://kura.pro/kaishi/images/banners/banner-kaishi.webp" ## The main image of the site in SVG format.
keywords: "kaishi starter templates, shokunin static site generator, static site generator, starter templates, bootstrap, bootstrap css, bootstrap javascript, content security policy, open graph meta tags, responsive navigation bar, schema.org meta tags" ## The keywords of the site. (max 160 characters)
language: "en-GB" ## The language of the site. (default: en-GB)
layout: "post" ## The layout of the site.
layout: "feature" ## The layout of the site.
locale: "en_GB" ## The locale of the site.
logo_alt: "Logo of Kaishi, a starter template for static sites" ## The logo alt of the site.
logo_height: "33" ## The logo height of the site.
Expand Down
8 changes: 4 additions & 4 deletions src/modules/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::utilities::directory::{
/// let html = generate_html(content, title, description, None);
/// let html_str = html.unwrap_or_else(|e| panic!("Error: {:?}", e));
///
/// assert_eq!(html_str, "<h1 id=\"h1-my\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" class=\"my\">My Page</h1><p>This is a test page</p><h2 id=\"h2-hello\" tabindex=\"0\" itemprop=\"name\" class=\"hello\">Hello, world!</h2>\n<p>This is a test.</p>\n");
/// assert_eq!(html_str, "<h1 id=\"h1-my\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"my\">My Page</h1><p>This is a test page</p><h2 id=\"h2-hello\" tabindex=\"0\" itemprop=\"name\" class=\"hello\">Hello, world!</h2>\n<p>This is a test.</p>\n");
///
/// ```
//
Expand Down Expand Up @@ -126,7 +126,7 @@ fn generate_header(title: &str, id_regex: &Regex) -> String {
if title.is_empty() {
return String::new();
}
let header_str = format!("<h1 id=\"\" tabindex=\"0\" itemprop=\"headline\">{}</h1>", title);
let header_str = format!("<h1 id=\"\">{}</h1>", title);
format_header_with_id_class(&header_str, id_regex)
}

Expand Down Expand Up @@ -287,7 +287,7 @@ pub fn post_process_html(html: &str, class_regex: &Regex, img_regex: &Regex) ->
let alt_substr = if alt_value.len() > max_alt_length {
&alt_value[..max_alt_length]
} else {
&alt_value
alt_value
};
let title_regex = regex::Regex::new(r#"title="([^"]*)""#).unwrap();
new_img_tag = title_regex.replace(&new_img_tag, format!(r#"title="{}{}""#, title_prefix, alt_substr)).to_string();
Expand All @@ -297,7 +297,7 @@ pub fn post_process_html(html: &str, class_regex: &Regex, img_regex: &Regex) ->
let alt_substr = if alt_value.len() > max_alt_length {
&alt_value[..max_alt_length]
} else {
&alt_value
alt_value
};
new_img_tag.push_str(&format!(" title=\"{}{}\"", title_prefix, alt_substr));
}
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub fn format_header_with_id_class(
"itemprop=\"name\""
}
));

// print!("header_type={:?}", header_type);
id_attribute_added = true;
}
Expand Down
2 changes: 1 addition & 1 deletion template/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
>
<!-- # Start Responsive navbar -->
<nav
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
id="mainNav"
itemscope
itemtype="http://schema.org/SiteNavigationElement"
Expand Down
24 changes: 12 additions & 12 deletions template/feature.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
>
<!-- # Start Responsive navbar -->
<nav
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
id="mainNav"
itemscope
itemtype="http://schema.org/SiteNavigationElement"
Expand Down Expand Up @@ -127,7 +127,7 @@
<!-- # End Responsive navbar -->

<!-- Header-->
<header class="w-100 py-5 position-relative">
<header class="w-100 position-relative">
<img
alt="{{banner_alt}}"
aria-hidden="false"
Expand All @@ -141,24 +141,24 @@
title="{{banner_alt}}"
width="{{banner_width}}"
/>
<div class="text-center text-white center mx-auto rounded rounded-3 p-5"
<div class="text-center text-theme center mx-auto"
style="
background-color: rgba(0,0,0, 0.618);
width: 61vw;
height: auto;
background: rgba(0,0,0,.618);
width: 100vw;
height: 100vh;
z-index: 1;">
<p class="display-2">{{name}}</p>
<p class="lead fs-3">{{subtitle}}</p>

<section
class="position-absolute top-50 start-50 translate-middle w-75 p-5">
<h1 class="mb-3 fw-semibold text-white display-1 lh-1">{{name}}</h1>
<p class="fs-4">{{subtitle}}</p>
</section>
</div>
</header>
<!-- # End Header-->

<!-- Main content-->
<main id="main" class="bd-masthead fs-5 p-5" aria-label="main">
<div class="container text-start justify-content-between">
{{content}}
</div>
<div class="text-start justify-content-between">{{content}}</div>
</main>

<!-- Footer-->
Expand Down
2 changes: 1 addition & 1 deletion template/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
>
<!-- # Start Responsive navbar -->
<nav
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
id="mainNav"
itemscope
itemtype="http://schema.org/SiteNavigationElement"
Expand Down
118 changes: 72 additions & 46 deletions template/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,61 +54,87 @@
<!-- # End Styles -->
</head>

<body id="page-top" itemscope itemtype="http://schema.org/WebPage" class="text-center bg-black text-white text-start fs-6">
<body
id="page-top"
itemscope
itemtype="http://schema.org/WebPage"
class="text-center bg-black text-white text-start fs-6"
>
<!-- # Start Responsive navbar -->
<nav class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg" id="mainNav"
itemscope itemtype="http://schema.org/SiteNavigationElement">
<div class="container p-3">
<figure class="py-0 mb-0">
<a href="/" tabindex="0" class="navbar-brand">
<img alt="Logo of {{name}}" height="{{logo_height}}" id="{{name}}" src="{{logo}}"
width="{{logo_width}}" />
</a>
<figcaption class="visually-hidden">{{subtitle}}</figcaption>
</figure>
<button aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"
class="navbar-toggler" data-bs-target="#navbarSupportedContent" data-bs-toggle="collapse" type="button">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" role="navigation" id="navbarSupportedContent">
{{navigation}}
</div>
<nav
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
id="mainNav"
itemscope
itemtype="http://schema.org/SiteNavigationElement"
>
<div class="container-xxl p-3">
<a class="navbar-brand p-0 me-0 me-lg-2" href="/" aria-label="logo">
<img
class="d-inline-block align-top"
width="{{logo_width}}"
height="{{logo_height}}"
src="{{logo}}"
alt="{{logo_alt}}"
title="{{logo_alt}}"
loading="lazy"
/>
</a>
<span itemprop="name">{{name}}</span>
<button
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
class="navbar-toggler"
data-bs-target="#navbarSupportedContent"
data-bs-toggle="collapse"
type="button"
>
<span class="navbar-toggler-icon"></span>
</button>
<div
class="collapse navbar-collapse"
role="navigation"
id="navbarSupportedContent"
>
{{navigation}}
</div>
</div>
</nav>
<!-- # End Responsive navbar -->

<!-- Header-->
<header class="w-100 py-5 position-relative">
<img
alt="{{banner_alt}}"
aria-hidden="false"
class="fade-in position-absolute top-0 start-0 w-100 h-100"
data-has-animated="true"
data-show-type="fade-in"
height="{{banner_height}}"
loading="lazy"
src="{{banner}}"
style="object-fit: cover; z-index: -1;"
title="{{banner_alt}}"
width="{{banner_width}}"
/>
<div class="text-center text-white center mx-auto rounded rounded-3 p-5"
style="
background-color: rgba(0,0,0, 0.618);
width: 61vw;
height: auto;
z-index: 1;">
<p class="display-2">{{name}}</p>
<p class="lead fs-3">{{subtitle}}</p>
</div>
</header>
<!-- # End Header-->
<header class="w-100 position-relative">
<img
alt="{{banner_alt}}"
aria-hidden="false"
class="fade-in position-absolute top-0 start-0 w-100 h-100"
data-has-animated="true"
data-show-type="fade-in"
height="{{banner_height}}"
loading="lazy"
src="{{banner}}"
style="object-fit: cover; z-index: -1;"
title="{{banner_alt}}"
width="{{banner_width}}"
/>
<div class="text-center text-theme center mx-auto"
style="
background: rgba(0,0,0,.618);
width: 100vw;
height: 100vh;
z-index: 1;">
<section
class="position-absolute top-50 start-50 translate-middle w-75 p-5">
<h1 class="mb-3 fw-semibold text-white display-1 lh-1">{{name}}</h1>
<p class="fs-4">{{subtitle}}</p>
</section>
</div>
</header>
<!-- # End Header-->

<!-- Main content-->
<main id="main" class="bd-masthead fs-5 p-5" aria-label="main">
<div class="container text-start justify-content-between">
{{content}}
</div>
<div class="text-start justify-content-between">{{content}}</div>
</main>

<!-- Footer-->
Expand Down
20 changes: 11 additions & 9 deletions template/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
>
<!-- # Start Responsive navbar -->
<nav
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
class="navbar navbar-expand-lg bd-navbar navbar-dark bg-black text-white sticky-top shadow-small border-bottom border-black blur-dark shadow-lg"
id="mainNav"
itemscope
itemtype="http://schema.org/SiteNavigationElement"
Expand Down Expand Up @@ -127,7 +127,7 @@
<!-- # End Responsive navbar -->

<!-- Header-->
<header class="w-100 py-5 position-relative">
<header class="w-100 position-relative">
<img
alt="{{banner_alt}}"
aria-hidden="false"
Expand All @@ -141,15 +141,17 @@
title="{{banner_alt}}"
width="{{banner_width}}"
/>
<div class="text-center text-white center mx-auto rounded rounded-3 p-5"
<div class="text-center text-theme center mx-auto"
style="
background-color: rgba(0,0,0, 0.618);
width: 61vw;
height: auto;
background: rgba(0,0,0,.618);
width: 100vw;
height: 100vh;
z-index: 1;">
<p class="display-2">{{name}}</p>
<p class="lead fs-3">{{subtitle}}</p>

<section
class="position-absolute top-50 start-50 translate-middle w-75 p-5">
<h1 class="mb-3 fw-semibold text-white display-1 lh-1">{{name}}</h1>
<p class="fs-4">{{subtitle}}</p>
</section>
</div>
</header>
<!-- # End Header-->
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ description: My Description
Ok(html) => {
assert_eq!(
html,
"<h1 id=\"h1-my\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"my\">My Page</h1><p>This is a test page</p><h2 id=\"h2-hello\" tabindex=\"0\" itemprop=\"name\" class=\"hello\">Hello, world!</h2>\n<p>This is a test.</p>\n"
"<h1 id=\"h1-my\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"my\">My Page</h1><p>This is a test page</p><h2 id=\"h2-hello\" tabindex=\"0\" itemprop=\"name\" class=\"hello\">Hello, world!</h2>\n<p>This is a test.</p>\n"
);
},
Err(err) => {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tests {
let title = "Welcome";
let description = "Say hi to the world!";
let result = generate_html(content, title, description, None);
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
match result {
Ok(res) => assert_eq!(res.trim(), expected),
Err(e) => panic!("Error: {:?}", e),
Expand All @@ -25,7 +25,7 @@ mod tests {
let title = "Welcome";
let description = "Say hi to the world!";
let result = generate_html(content, title, description, None);
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
match result {
Ok(res) => assert_eq!(res.trim(), expected),
Err(e) => panic!("Error: {:?}", e),
Expand All @@ -52,7 +52,7 @@ mod tests {
let title = "Welcome";
let description = "";
let result = generate_html(content, title, description, None);
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"welcome\">Welcome</h1><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
match result {
Ok(res) => assert_eq!(res.trim(), expected),
Err(e) => panic!("Error: {:?}", e),
Expand All @@ -65,7 +65,7 @@ mod tests {
let title = "Welcome";
let description = "Say hi to the world!";
let result = generate_html(content, title, description, None);
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p><h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1>";
match result {
Ok(res) => assert_eq!(res.trim(), expected),
Err(e) => panic!("Error: {:?}", e),
Expand All @@ -78,7 +78,7 @@ mod tests {
let title = "Welcome";
let description = "Say hi to the world!";
let result = generate_html(content, title, description, None);
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" tabindex=\"0\" itemprop=\"headline\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p>";
let expected = "<h1 id=\"h1-welcome\" tabindex=\"0\" itemprop=\"headline\" id=\"\" class=\"welcome\">Welcome</h1><p>Say hi to the world!</p>";
match result {
Ok(res) => assert_eq!(res.trim(), expected),
Err(e) => panic!("Error: {:?}", e),
Expand Down

0 comments on commit aa3b754

Please sign in to comment.