From e96ca4a72c965b106cf2247ca019c25fca465318 Mon Sep 17 00:00:00 2001 From: LebCit Date: Mon, 25 Dec 2023 09:30:26 +0200 Subject: [PATCH] Move themes static files to respective directories --- functions/search-default.js | 2 +- static/scripts/clean-blog-scripts.js | 47 ---------------- .../themes/clean-blog/clean-blog-scripts.js | 53 +++++++++++++++++++ .../{ => themes/default}/default-scripts.js | 2 +- .../clean-blog}/clean-blog-styles.css | 0 .../default}/default-pagination.css | 0 .../default}/default-single-post-preview.css | 4 +- .../default}/default-styles.min.css | 0 views/posts/templates.md | 2 +- views/posts/the-pagination-component.md | 2 +- .../themes/clean-blog/components/footer.html | 2 +- views/themes/clean-blog/components/head.html | 2 +- views/themes/default/components/footer.html | 2 +- views/themes/default/components/head.html | 2 +- .../themes/default/components/pagination.html | 2 +- views/themes/default/layouts/index.html | 2 +- 16 files changed, 65 insertions(+), 59 deletions(-) delete mode 100644 static/scripts/clean-blog-scripts.js create mode 100644 static/scripts/themes/clean-blog/clean-blog-scripts.js rename static/scripts/{ => themes/default}/default-scripts.js (97%) rename static/styles/{ => themes/clean-blog}/clean-blog-styles.css (100%) rename static/styles/{ => themes/default}/default-pagination.css (100%) rename static/styles/{ => themes/default}/default-single-post-preview.css (96%) rename static/styles/{ => themes/default}/default-styles.min.css (100%) diff --git a/functions/search-default.js b/functions/search-default.js index dcacb75..6b904bd 100644 --- a/functions/search-default.js +++ b/functions/search-default.js @@ -43,7 +43,7 @@ fetch("/static/scripts/posts.json") // Insert the default-single-post-preview.css at the end of the head tag document.head.insertAdjacentHTML( "beforeend", - '' + '' ) // Define an empty string that will hold the search result(s) diff --git a/static/scripts/clean-blog-scripts.js b/static/scripts/clean-blog-scripts.js deleted file mode 100644 index f5ad645..0000000 --- a/static/scripts/clean-blog-scripts.js +++ /dev/null @@ -1,47 +0,0 @@ -window.addEventListener("DOMContentLoaded", () => { - let scrollPos = 0 - const mainNav = document.getElementById("mainNav") - const headerHeight = mainNav.clientHeight - window.addEventListener("scroll", function () { - const currentTop = document.body.getBoundingClientRect().top * -1 - if (currentTop < scrollPos) { - // Scrolling Up - if (currentTop > 0 && mainNav.classList.contains("is-fixed")) { - mainNav.classList.add("is-visible") - } else { - mainNav.classList.remove("is-visible", "is-fixed") - } - } else { - // Scrolling Down - mainNav.classList.remove(["is-visible"]) - if (currentTop > headerHeight && !mainNav.classList.contains("is-fixed")) { - mainNav.classList.add("is-fixed") - } - } - scrollPos = currentTop - }) -}) - -// RESPONSIVE IMAGES IN PAGES AND POSTS -const main = document.getElementById("main") -const images = main.querySelectorAll("img") -images.forEach((image) => { - image.classList.add("img-fluid") -}) - -// Detect external links -const isExternalLink = (url) => { - const tmp = document.createElement("a") - tmp.href = url - return tmp.host !== window.location.host -} -// Select all links -const allLinks = document.querySelectorAll("a") -// Add attributes and icon to each external link -allLinks.forEach((link) => { - if (isExternalLink(link)) { - link.setAttribute("target", "_blank") - link.setAttribute("rel", "external noopener noreferrer") - link.insertAdjacentHTML("beforeend", ` `) - } -}) diff --git a/static/scripts/themes/clean-blog/clean-blog-scripts.js b/static/scripts/themes/clean-blog/clean-blog-scripts.js new file mode 100644 index 0000000..c7ac143 --- /dev/null +++ b/static/scripts/themes/clean-blog/clean-blog-scripts.js @@ -0,0 +1,53 @@ +window.addEventListener("DOMContentLoaded", () => { + let scrollPos = 0 + const mainNav = document.getElementById("mainNav") + const headerHeight = mainNav.clientHeight + window.addEventListener("scroll", function () { + const currentTop = document.body.getBoundingClientRect().top * -1 + if (currentTop < scrollPos) { + // Scrolling Up + if (currentTop > 0 && mainNav.classList.contains("is-fixed")) { + mainNav.classList.add("is-visible") + } else { + mainNav.classList.remove("is-visible", "is-fixed") + } + } else { + // Scrolling Down + mainNav.classList.remove(["is-visible"]) + if (currentTop > headerHeight && !mainNav.classList.contains("is-fixed")) { + mainNav.classList.add("is-fixed") + } + } + scrollPos = currentTop + }) + + // RESPONSIVE IMAGES IN PAGES AND POSTS + const main = document.getElementById("main") + // Ensure that a page or a post is displayed + if (main) { + const images = main.querySelectorAll("img") + images.forEach((image) => { + image.classList.add("img-fluid") + }) + } + + // Detect external links + const isExternalLink = (url) => { + const tmp = document.createElement("a") + tmp.href = url + return tmp.host !== window.location.host + } + // Select all links + const allLinks = document.querySelectorAll("a") + // Add attributes and icon to each external link + allLinks.forEach((link) => { + if (isExternalLink(link)) { + link.setAttribute("target", "_blank") + link.setAttribute("rel", "external noopener noreferrer") + link.insertAdjacentHTML( + "beforeend", + ` ` + ) + } + }) +}) diff --git a/static/scripts/default-scripts.js b/static/scripts/themes/default/default-scripts.js similarity index 97% rename from static/scripts/default-scripts.js rename to static/scripts/themes/default/default-scripts.js index 858985b..ff28045 100644 --- a/static/scripts/default-scripts.js +++ b/static/scripts/themes/default/default-scripts.js @@ -1,4 +1,4 @@ -import { isExternalLink } from "./is-external-link.js" +import { isExternalLink } from "../../is-external-link.js" // Utility function to ensure that the trailing slash is not considered when highlighting the menu item function removeTrailingSlash(str) { diff --git a/static/styles/clean-blog-styles.css b/static/styles/themes/clean-blog/clean-blog-styles.css similarity index 100% rename from static/styles/clean-blog-styles.css rename to static/styles/themes/clean-blog/clean-blog-styles.css diff --git a/static/styles/default-pagination.css b/static/styles/themes/default/default-pagination.css similarity index 100% rename from static/styles/default-pagination.css rename to static/styles/themes/default/default-pagination.css diff --git a/static/styles/default-single-post-preview.css b/static/styles/themes/default/default-single-post-preview.css similarity index 96% rename from static/styles/default-single-post-preview.css rename to static/styles/themes/default/default-single-post-preview.css index a90c9c0..7aad4c0 100644 --- a/static/styles/default-single-post-preview.css +++ b/static/styles/themes/default/default-single-post-preview.css @@ -74,7 +74,7 @@ } .blog-card .details .date:before { content: ""; - background: url("../icons/date-post-details.svg"); + background: url("../../../icons/date-post-details.svg"); position: absolute; width: 16px; height: 16px; @@ -84,7 +84,7 @@ } .blog-card .details .tags ul:before { content: ""; - background: url("../icons/tag-post-details.svg"); + background: url("../../../icons/tag-post-details.svg"); position: absolute; width: 16px; height: 16px; diff --git a/static/styles/default-styles.min.css b/static/styles/themes/default/default-styles.min.css similarity index 100% rename from static/styles/default-styles.min.css rename to static/styles/themes/default/default-styles.min.css diff --git a/views/posts/templates.md b/views/posts/templates.md index c4c4a76..c5b21a7 100644 --- a/views/posts/templates.md +++ b/views/posts/templates.md @@ -49,7 +49,7 @@ Now paste the following block of code: - +
diff --git a/views/posts/the-pagination-component.md b/views/posts/the-pagination-component.md index cf36cb0..55469c2 100644 --- a/views/posts/the-pagination-component.md +++ b/views/posts/the-pagination-component.md @@ -31,7 +31,7 @@ The `paginated` condition is a passed data object to display or not the paginati At the top of the `pagination.html` file, you can find a link to the stylesheet related to this component. ```xml - + ``` Those styles will only be available when the pagination component is displayed. This is very useful to avoid loading unnecessary styles in the app. diff --git a/views/themes/clean-blog/components/footer.html b/views/themes/clean-blog/components/footer.html index 1af89aa..ab3319a 100644 --- a/views/themes/clean-blog/components/footer.html +++ b/views/themes/clean-blog/components/footer.html @@ -37,7 +37,7 @@ <%/* Bootstrap core JS */%> <%/* Core theme JS */%> - + <% if (it.build) { %> <% } %> <%/* diff --git a/views/themes/clean-blog/components/head.html b/views/themes/clean-blog/components/head.html index 11ff83c..4f9538a 100644 --- a/views/themes/clean-blog/components/head.html +++ b/views/themes/clean-blog/components/head.html @@ -19,7 +19,7 @@ type="text/css" /> <%/* Core theme CSS (includes Bootstrap) */%> - + <% if (it.mdRoute) { %> <% } %> diff --git a/views/themes/default/components/footer.html b/views/themes/default/components/footer.html index 132fcfe..8aa2790 100644 --- a/views/themes/default/components/footer.html +++ b/views/themes/default/components/footer.html @@ -19,4 +19,4 @@ <% } %> - + diff --git a/views/themes/default/components/head.html b/views/themes/default/components/head.html index 0a6759f..a9dc24b 100644 --- a/views/themes/default/components/head.html +++ b/views/themes/default/components/head.html @@ -11,7 +11,7 @@ <% /* Stylesheets*/ %> - + <% if (it.mdRoute) { %> <% } %> diff --git a/views/themes/default/components/pagination.html b/views/themes/default/components/pagination.html index af3558e..3eb53b5 100644 --- a/views/themes/default/components/pagination.html +++ b/views/themes/default/components/pagination.html @@ -1,4 +1,4 @@ - + <%/* */%> <% if (it.firstPage && it.lastPage > 0) { %> diff --git a/views/themes/default/layouts/index.html b/views/themes/default/layouts/index.html index 79d1fa9..0d4a8c1 100644 --- a/views/themes/default/layouts/index.html +++ b/views/themes/default/layouts/index.html @@ -1,4 +1,4 @@ - + <% it.posts.forEach((post, index) => { %> <%/*