From ad5e758243d4d7f8b9047cc02c5ae6bf4df03f0b Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 01:52:24 +0200
Subject: [PATCH 03/14] Created a site-internal folder for items are not in a
collection, 404 page is moved into it, the folder is excluded from navgen
Signed-off-by: Hofi
---
_plugins/generate_tooltips.rb | 2 +-
_tools/navgen | 2 +-
doc/{ => site-internal}/404.md | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
rename doc/{ => site-internal}/404.md (92%)
diff --git a/_plugins/generate_tooltips.rb b/_plugins/generate_tooltips.rb
index 2a986bf0..431c7247 100644
--- a/_plugins/generate_tooltips.rb
+++ b/_plugins/generate_tooltips.rb
@@ -432,7 +432,7 @@ def JekyllTooltipGen_hack_description_out(page_has_subtitle, page_has_descriptio
if $JekyllTooltipGen_markdown_extensions == nil
$JekyllTooltipGen_markdown_extensions = site.config['markdown_ext'].split(',').map { |ext| ".#{ext.strip}" }
# Skip shorter than 3 letter long (e.g. Glossary header) anchor items (for testing: https://rubular.com/)
- $JekyllTooltipGen_page_links = Jekyll::TooltipGen.gen_page_link_data(JekyllTooltipGen_links_folder, /\/(adm|dev|doc)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/) # /\/(adm|dev|doc)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/ 'adm-temp-macro-ose#message.yml'
+ $JekyllTooltipGen_page_links = Jekyll::TooltipGen.gen_page_link_data(JekyllTooltipGen_links_folder, /\/(adm|dev|doc|site)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/) # /\/(adm|dev|doc)-(([^#]+)|(.*\#{1}.{3,}))\.yml\z/ 'adm-temp-macro-ose#message.yml'
# Sort the $JekyllTooltipGen_page_links dictionary keys based on the "title" values in reverse order case insensitive
$JekyllTooltipGen_page_links_ids_sorted_by_title = Jekyll::TooltipGen.page_links_ids_sorted_by_title($JekyllTooltipGen_page_links)
# Create $JekyllTooltipGen_nav_links dictionary using "url" as key and add nav_ndx to all items based on we can adjust navigation order (in page_pagination.html)
diff --git a/_tools/navgen b/_tools/navgen
index a47131a5..627ea1ea 100755
--- a/_tools/navgen
+++ b/_tools/navgen
@@ -186,7 +186,7 @@ gen_navigation()
> "${OUTPUT_FILE}"
add_warning_header "${OUTPUT_FILE}"
- for DOC_PROJECT_ITEM in $(find -L "${DOC_FOLDER}" -mindepth 1 -maxdepth 1 -type d | sort); do
+ for DOC_PROJECT_ITEM in $(find -L "${DOC_FOLDER}" -mindepth 1 -maxdepth 1 -type d -and -not -name "site-internal" | sort); do
START_DIR=$(trim_trailing_slashes "${DOC_PROJECT_ITEM}")
ROOT_DIR_NAME=$(basename "${START_DIR}")
[ "${REMOVE_UNDERLINE_FROM_DOC_DIR_NAMES}x" != "x" ] && ROOT_DIR_NAME=${ROOT_DIR_NAME#_}
diff --git a/doc/404.md b/doc/site-internal/404.md
similarity index 92%
rename from doc/404.md
rename to doc/site-internal/404.md
index f534554b..ed90bf67 100644
--- a/doc/404.md
+++ b/doc/site-internal/404.md
@@ -16,7 +16,7 @@ Fear not, intrepid traveler!\
Here are a few ways to escape this digital abyss:
> * Check the URL again. Typos happen to the best of us!
-> * Return to the {% include markdown_link id="doc-center" title="homepage" %} and regroup.
+> * Return to the [[homepage|doc-center]] and regroup.
> * Take a deep breath and count to ten. Maybe the page will magically appear.
> * Offer a sacrifice to the tech gods. A keyboard or mouse should do the trick.
> * Try shouting "syslog-ng" three times while doing a rain dance. Results may vary.
From 18f68c3cc5a05782c30e704df14bd2645320374e Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 01:54:29 +0200
Subject: [PATCH 04/14] Excluded none collection pages from lunr search
Signed-off-by: Hofi
---
_config.yml | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/_config.yml b/_config.yml
index 7e556d8e..05d7b86c 100644
--- a/_config.yml
+++ b/_config.yml
@@ -164,13 +164,14 @@ defaults:
# Search settings
search: true
+# Setting search_full_content to true could impact page load performance!
search_full_content: true
search_provider: lunr
lunr:
- search_within_pages: true
- # Setting search_full_content to true could impact page load performance!
- search_full_content: true
+ # No we have all the valuable content in collections
+ # Standalone pages like, sitemap.xml, 404, etc. should not be searched
+ search_within_pages: false
# search_provider: algolia
# algolia:
From 99f345e60efa5087d10fd3251c80b1e2e3f8c201 Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 01:53:45 +0200
Subject: [PATCH 05/14] Added the lunr search help internal page, external
links to the original lunr contents, and a link to the help page under the
search input field
Signed-off-by: Hofi
---
_data/external_links.yml | 10 +++
_includes/search/search_form.html | 1 +
doc/site-internal/lunr_search_help.md | 115 ++++++++++++++++++++++++++
3 files changed, 126 insertions(+)
create mode 100644 doc/site-internal/lunr_search_help.md
diff --git a/_data/external_links.yml b/_data/external_links.yml
index eff49026..3a4dc7b1 100644
--- a/_data/external_links.yml
+++ b/_data/external_links.yml
@@ -132,3 +132,13 @@ ietf-syslog-proto:
id: ietf-syslog-proto
url: https://tools.ietf.org/html/rfc5424
title: [ "new syslog (IETF-syslog) protocol" ]
+
+lunr-site:
+ id: lunr-site
+ url: https://lunrjs.com
+ title: [ "Lunar site" ]
+
+lunr-search-help:
+ id: lunr-search-help
+ url: https://lunrjs.com/guides/searching.html
+ title: [ "Lunar search help" ]
diff --git a/_includes/search/search_form.html b/_includes/search/search_form.html
index b9de365c..1ff1ac61 100644
--- a/_includes/search/search_form.html
+++ b/_includes/search/search_form.html
@@ -7,6 +7,7 @@
{{ site.data.ui-text[site.locale].search_label_text | default: 'Enter your search term...' }}
+ [ Hover or click for search help ]
{%- when "google" -%}
diff --git a/doc/site-internal/lunr_search_help.md b/doc/site-internal/lunr_search_help.md
new file mode 100644
index 00000000..865c5f30
--- /dev/null
+++ b/doc/site-internal/lunr_search_help.md
@@ -0,0 +1,115 @@
+---
+title: Documentation Search Help
+permalink: /lunr_search_help
+id: site-lunr-search-help
+search: false
+---
+
+We are using [[Lunr|lunr-site]] for searching, this is a slightly modified snippet of the original [[Lunr searching page|lunr-search-help]].
+Please visit the original Lunar site for more information.
+
+## Searching
+
+The simplest way to start is to pass the text on which you want to search into the search field:
+
+``` javascript
+'foo'
+```
+
+The above will return details of all documents that match the term “foo”. Although it looks like a string, the search method parses the string into a search query. This supports special syntax for defining more complex queries.
+
+Searches for multiple terms are also supported. If a document matches at least one of the search terms, it will show in the results. The search terms are combined with OR.
+
+``` javascript
+'foo bar'
+```
+
+The above example will match documents that contain either “foo” or “bar”. Documents that contain both will score more highly and will be returned first.
+
+## Scoring
+
+The score (also known as relevance) of a document is calculated by the BM25 algorithm, along with other factors such as boosts. You don’t need to worry too much about the details of how BM25 works; to summarize, the more a search term occurs in a single document, the more that term will increase that document’s score, but the more a search term occurs in the overall collection of documents, the less that term will increase a document’s score.
+
+For example, let’s say you’re indexing a collection of documents about JavaScript testing libraries. The terms “JavaScript”, “library”, and “test” may occur very frequently throughout the entire collection, so finding a document that mentions one of these terms isn’t very significant. However, if you’re searching for “integration test”, only three documents in the collection have the term “integration” in them, and one of them mentions “integration” many times, that will bring the score for that one document higher up.
+
+## Wildcards
+
+Lunr supports wildcards when performing searches. A wildcard is represented as an asterisk (*) and can appear anywhere in a search term. For example, the following will match all documents with words beginning with “foo”:
+
+``` javascript
+'foo*'
+```
+
+This will match all documents that end with ‘oo’:
+
+``` javascript
+'*oo'
+```
+
+Leading wildcards, as in the above example, should be used sparingly. They can have a negative impact on the performance of a search, especially in large indexes.
+
+Finally, a wildcard can be in the middle of a term. The following will match any documents that contain a term that begins with “f” and ends in “o”:
+
+``` javascript
+'f*o'
+```
+
+It is also worth noting that, when a search term contains a wildcard, no stemming is performed on the search term.
+
+## Term Presence
+
+By default, Lunr combines multiple terms together in a search with a logical OR. That is, a search for “foo bar” will match documents that contain “foo” or contain “bar” or contain both. This behaviour is controllable at the term level, i.e. the presence of each term in matching documents can be specified. By default each term is optional in a matching document, though a document must have at least one matching term. It is possible to specify that a term must be present in matching documents, or that it must be absent in matching documents.
+
+To indicate that a term must be present in matching documents the term should be prefixed with a plus (+) and to indicate that a term must be absent the term should be prefixed with a minus (-). Without either prefix the term’s presence in matching documents is optional.
+
+The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”:
+
+``` javascript
+'+foo bar -baz'
+```
+
+To simulate a logical AND search of “foo AND bar” mark both terms as required:
+
+``` javascript
+'+foo +bar'
+```
+
+## Fields
+
+By default, Lunr will search all fields in a document for the query term, and it is possible to restrict a term to a specific field. The following example searches for the term “foo” in the field title:
+
+``` javascript
+'title:foo'
+```
+
+The search term is prefixed with the name of the field, followed by a colon (:). The field must be one of the fields defined when building the index. Unrecognised fields will lead to an error.
+
+Field-based searches can be combined with all other term modifiers and wildcards, as well as other terms. For example, to search for words beginning with “foo” in the title or with “bar” in any field the following query can be used:
+
+``` javascript
+'title:foo* bar'
+```
+
+## Boosts
+
+In multi-term searches, a single term may be important than others. For these cases Lunr supports term level boosts. Any document that matches a boosted term will get a higher relevance score, and appear higher up in the results. A boost is applied by appending a caret (^) and then a positive integer to a term.
+
+``` javascript
+'foo^10 bar'
+```
+
+The above example weights the term “foo” 10 times higher than the term “bar”. The boost value can be any positive integer, and different terms can have different boosts:
+
+``` javascript
+'foo^10 bar^5 baz'
+```
+
+## Fuzzy Matches
+
+Lunr supports fuzzy matching search terms in documents, which can be helpful if the spelling of a term is unclear, or to increase the number of search results that are returned. The amount of fuzziness to allow when searching can also be controlled. Fuzziness is applied by appending a tilde (~) and then a positive integer to a term. The following search matches all documents that have a word within 1 edit distance of “foo”:
+
+``` javascript
+'foo~1'
+```
+
+An edit distance of 1 allows words to match if either adding, removing, changing or transposing a character in the word would lead to a match. For example “boo” requires a single edit (replacing “f” with “b”) and would match, but “boot” would not as it also requires an additional “t” at the end.
From 39c86c5b66f3b53570f79d5e5613059b9aa54687 Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 02:03:43 +0200
Subject: [PATCH 06/14] Fixed the handling of the changed doc root
Signed-off-by: Hofi
---
_js/custom/navigation.js | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/_js/custom/navigation.js b/_js/custom/navigation.js
index 699b0b98..3f7d6f9c 100644
--- a/_js/custom/navigation.js
+++ b/_js/custom/navigation.js
@@ -4,7 +4,7 @@
$(function () {
// FIXME: How to get the real base URL (without using Liquid and Front Matter) ?!?!
- const docRootName = 'doc';
+ const docRoot = '';
const notFoundPageName = '404.html';
const contentID = 'article';
@@ -158,7 +158,7 @@ $(function () {
error => {
if (error == "Error: 404") {
var baseURL = window.location.origin;
- var notFoundURL = baseURL + '/' + docRoot + '/' + notFoundPageName;
+ var notFoundURL = baseURL + '/' + (docRoot != '' ? docRoot + '/' : '') + notFoundPageName;
updateContentFromUrl(notFoundURL);
}
@@ -174,15 +174,20 @@ $(function () {
// Functions to handle link clicks
// -------------
function getCollectionFromDocPath(url) {
- var parts = url.href.split('/');
- var docIndex = parts.indexOf(docRootName);
+ var collection = '';
+ var parts = trimCharFromString(url.pathname, '/').split('/');
- // If 'doc' is not found or it's the last segment, return an empty string
- if (docIndex === -1 || docIndex === parts.length - 1) {
- return '';
+ if (docRoot == '') {
+ collection = parts[0];
}
+ else {
+ var docIndex = parts.indexOf(docRoot);
- return parts[docIndex + 1];
+ // If 'docRoot' is found or it is not the last segment, return the next part after it as the collection name
+ if (docIndex !== -1 && docIndex !== parts.length - 1)
+ collection = parts[docIndex + 1];
+ }
+ return collection;
}
function sameCollection(url1, url2) {
From 5193eab18f5ed5cfa9e04aefc06434092f07b27e Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 02:05:06 +0200
Subject: [PATCH 07/14] lunr-store.js readability correction
Signed-off-by: Hofi
---
_js/lunr/lunr-store.js | 71 +++++++++++++++++++++---------------------
1 file changed, 36 insertions(+), 35 deletions(-)
diff --git a/_js/lunr/lunr-store.js b/_js/lunr/lunr-store.js
index 565e3b3e..4b8b473d 100644
--- a/_js/lunr/lunr-store.js
+++ b/_js/lunr/lunr-store.js
@@ -46,39 +46,40 @@ var store = [
"teaser": {{ teaser | relative_url | jsonify }}
}{%- unless forloop.last and l -%},{%- endunless -%}
{%- endfor -%}
- {%- endfor -%}{%- if site.lunr.search_within_pages -%},
- {%- assign pages = site.pages | where_exp:'doc','doc.search != false' -%}
- {%- for doc in pages -%}
- {%- if forloop.last -%}
- {%- assign l = true -%}
- {%- endif -%}
- {
- "title": {{ doc.title | jsonify }},
- "excerpt":
- {%- if site.search_full_content == true -%}
- {{ doc.content | newline_to_br |
- replace:" ", " " |
- replace:"
", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " "|
- strip_html | strip_newlines | jsonify }},
- {%- else -%}
- {{ doc.content | newline_to_br |
- replace:" ", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " " |
- replace:"", " "|
- strip_html | strip_newlines | truncatewords: 50 | jsonify }},
- {%- endif -%}
- "url": {{ doc.url | absolute_url | jsonify }}
- }{%- unless forloop.last and l -%},{%- endunless -%}
{%- endfor -%}
-{%- endif -%}]
+ {%- if site.lunr.search_within_pages -%},
+ {%- assign pages = site.pages | where_exp:'doc','doc.search != false' -%}
+ {%- for doc in pages -%}
+ {%- if forloop.last -%}
+ {%- assign l = true -%}
+ {%- endif -%}
+ {
+ "title": {{ doc.title | jsonify }},
+ "excerpt":
+ {%- if site.search_full_content == true -%}
+ {{ doc.content | newline_to_br |
+ replace:" ", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " "|
+ strip_html | strip_newlines | jsonify }},
+ {%- else -%}
+ {{ doc.content | newline_to_br |
+ replace:" ", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " " |
+ replace:"", " "|
+ strip_html | strip_newlines | truncatewords: 50 | jsonify }},
+ {%- endif -%}
+ "url": {{ doc.url | absolute_url | jsonify }}
+ }{%- unless forloop.last and l -%},{%- endunless -%}
+ {%- endfor -%}
+ {%- endif -%}]
From 3004a9c5100386d8f60af174d1dd1acb48befd4b Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 02:07:27 +0200
Subject: [PATCH 08/14] TOC hiding moved to a separate, reusable function
Signed-off-by: Hofi
---
_js/custom/navigation.js | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/_js/custom/navigation.js b/_js/custom/navigation.js
index 3f7d6f9c..ce32d270 100644
--- a/_js/custom/navigation.js
+++ b/_js/custom/navigation.js
@@ -8,6 +8,23 @@ $(function () {
const notFoundPageName = '404.html';
const contentID = 'article';
+ function hideTocIfNotNeeded(docObject, forceHide) {
+ var shouldHide = forceHide;
+ var tocElement = docObject.querySelector('.toc');
+
+ if (tocElement) {
+ var tocMenuElement = tocElement.querySelector('.toc__menu');
+ if (null == tocMenuElement || false == tocMenuElement.hasChildNodes)
+ shouldHide = true;
+ }
+ if (shouldHide) {
+ // TOC is autogenerated via 'include toc.html' so its size is not known prior the call of toc.html
+ // Signal emptiness, css will hide if needed based on it and config settings
+ // NOTE: Not hiding directly here to behave the same way like the left sidebar does
+ tocElement.classList.add('empty');
+ }
+ }
+
function adjustSidebars() {
// Identify the URL of the loaded page
var loadedPageUrl = window.location.pathname;
@@ -56,15 +73,7 @@ $(function () {
matchingNavItem.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
- // TOC is autogenerated via 'include toc.html' so its size is not known prior the call of toc.html
- // Signal emptiness, css will hide if needed based on it and config settings
- // NOTE: Not hiding directly here to behave the same way like the left sidebar does
- var tocElement = document.querySelector('.toc');
- if (tocElement) {
- var tocMenuElement = tocElement.querySelector('.toc__menu');
- if (null == tocMenuElement || false == tocMenuElement.hasChildNodes)
- tocElement.classList.add('empty');
- }
+ hideTocIfNotNeeded(document, false);
}
}
From c60284663c073693473cdc9aaad2a006c43544ae Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 02:08:47 +0200
Subject: [PATCH 09/14] Hide tooltip on window focus lost as well
Signed-off-by: Hofi
---
_js/custom/navigation.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/_js/custom/navigation.js b/_js/custom/navigation.js
index ce32d270..dbfaebec 100644
--- a/_js/custom/navigation.js
+++ b/_js/custom/navigation.js
@@ -495,6 +495,11 @@ $(function () {
document.addEventListener("mouseover", function (event) {
elementUnderCursor = event.target;
});
+
+ window.addEventListener('blur', function () {
+ if (tooltipTarget)
+ hideTooltip(true);
+ });
}
// -------------
From d5b9bf02e2c0dffb813987b9da940c070fbcc13b Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 02:12:03 +0200
Subject: [PATCH 10/14] Added support of full age content in the tooltip, and
using it for showing the lunr search help if hovering the search input field
hint text
Signed-off-by: Hofi
---
_js/custom/navigation.js | 76 ++++++++++++------
_js/main.min.js | 79 +++++++++++++------
.../minimal-mistakes/_navigation.scss | 11 ++-
.../minimal-mistakes/_search.scss | 13 ++-
4 files changed, 129 insertions(+), 50 deletions(-)
diff --git a/_js/custom/navigation.js b/_js/custom/navigation.js
index dbfaebec..e0aef639 100644
--- a/_js/custom/navigation.js
+++ b/_js/custom/navigation.js
@@ -8,6 +8,14 @@ $(function () {
const notFoundPageName = '404.html';
const contentID = 'article';
+ function trimCharFromString(str, char) {
+ // Create a regular expression to match the given character at the beginning or end of the string
+ const regex = new RegExp(`^${char}|${char}$`, 'g');
+
+ // Use replace() to trim the character from the string
+ return str.replace(regex, '');
+ }
+
function hideTocIfNotNeeded(docObject, forceHide) {
var shouldHide = forceHide;
var tocElement = docObject.querySelector('.toc');
@@ -208,6 +216,9 @@ $(function () {
function handleNavLinkClick(event) {
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
+ if (tooltipTarget)
+ hideTooltip(true);
+
var updated = false;
// Get the relative URL value and update the browser URL
// Use originalTarget or explicitTarget to get the correct one even for clicks from the tooltips
@@ -219,7 +230,7 @@ $(function () {
// Try to load into the inner content frame only if the collection has not changed
// Otherwise let the original click flow take effect, as the nav bar must be reloaded too
// for a different collection
- if (url.origin == window.location.origin && sameCollection(url, window.location)) {
+ if (url.origin === window.location.origin && anchorElement.target !== '_blank' && sameCollection(url, window.location)) {
// Prevent default navigation behavior, we will use our content load method
event.preventDefault();
@@ -238,7 +249,7 @@ $(function () {
event.target.blur();
}
if (false == updated)
- console.debug("Different collection item requested, loading full page...")
+ console.debug("Different collection item or new tab/page requested, loading full page...")
}
}
@@ -301,10 +312,13 @@ $(function () {
});
}
- function alterPageTitle(content) {
+ function alterPageForTooltip(content, fullPageContent) {
let tempContainer = document.createElement('div');
tempContainer.innerHTML = content;
+ if (fullPageContent)
+ hideTocIfNotNeeded(tempContainer, true);
+
// Remove/Override some default title style formatting to look better in the tooltip
const pageTitle = tempContainer.querySelector('#page-title');
if (pageTitle)
@@ -314,7 +328,11 @@ $(function () {
if (pageSubtitle)
pageSubtitle.style.borderBottom = '0px';
- return tempContainer.innerHTML;
+ var newContent = tempContainer.innerHTML
+ // remove unnecessary, reqursive inner content tooltips
+ newContent = newContent.replace(/\bcontent-tooltip\b/g, '');
+
+ return newContent;
}
function loadContentPartFrom(url, onSuccess, onError) {
@@ -333,17 +351,14 @@ $(function () {
var startHeading = newContent.querySelector('#' + startHeadingId);
if (startHeading) {
var content = startHeading.outerHTML; // Include the starting element itself
-
var nextSibling = startHeading.nextElementSibling;
+
// Collect all siblings until the next heading or the end of the document
// FIXME: This magic 6 must be maintained together now with generate_links.rb (and other places ?!)
while (nextSibling && nextSibling.tagName !== 'H1' && nextSibling.tagName !== 'H2' && nextSibling.tagName !== 'H3' && nextSibling.tagName !== 'H4' && nextSibling.tagName !== 'H5' && nextSibling.tagName !== 'H6') {
content += nextSibling.outerHTML;
nextSibling = nextSibling.nextElementSibling;
}
- if (false == hasAnchor)
- content = alterPageTitle(content);
-
onSuccess(content);
}
else
@@ -387,9 +402,14 @@ $(function () {
tooltip.style.setProperty(posName, newPosition);
}
- function showTooltip(event, tooltipText) {
+ function showTooltip(event, tooltipText, fullPageContent) {
tooltip.innerHTML = tooltipText.innerHTML;
+ if (fullPageContent)
+ tooltip.classList.add("full-content-tooltip");
+ else
+ tooltip.classList.remove("full-content-tooltip");
+
var tooltipPos = getTooltipPos(event, tooltipTarget)
var tooltipArrowLeftShift = 2 * toolTipArrowSize;
@@ -450,27 +470,37 @@ $(function () {
element.appendChild(tooltipText);
element.addEventListener('mouseover', function (event) {
+ var fullPageContent = element.classList.contains('full-content-tooltip');
+
tooltipTarget = element;
// Load only once per page load
if (tooltipText.innerHTML === '') {
var url = element.href;
- loadContentPartFrom(
- url,
- newContent => {
- // remove unnecessary inner content tooltips
- newContent = newContent.replace(/\bcontent-tooltip\b/g, '');
- // cache for reuse
- tooltipText.innerHTML = newContent;
- showTooltip(event, tooltipText);
- },
- error => {
- console.error('Error loading the tooltip content!' + error);
- }
- );
+
+ function onSuccess(newContent) {
+ if (typeof (newContent) === 'object' && 'innerHTML' in newContent)
+ newContent = newContent.innerHTML;
+ newContent = alterPageForTooltip(newContent, fullPageContent);
+
+ // cache for reuse
+ tooltipText.innerHTML = newContent;
+ showTooltip(event, tooltipText, fullPageContent);
+ }
+
+ function onError(error) {
+ console.error('Error loading the tooltip content!' + error);
+ }
+
+ if (fullPageContent) {
+ loadContentFromUrl(url, newContent => onSuccess(newContent), error => onError(error));
+ }
+ else {
+ loadContentPartFrom(url, newContent => onSuccess(newContent), error => onError(error));
+ }
}
else
- showTooltip(event, tooltipText);
+ showTooltip(event, tooltipText, fullPageContent);
});
});
diff --git a/_js/main.min.js b/_js/main.min.js
index 35f381f5..de869a0e 100644
--- a/_js/main.min.js
+++ b/_js/main.min.js
@@ -8453,9 +8453,24 @@ $(function() {
});
$(function() {
- const docRootName = "doc";
+ const docRoot = "";
const notFoundPageName = "404.html";
const contentID = "article";
+ function trimCharFromString(str, char) {
+ const regex = new RegExp(`^${char}|${char}$`, "g");
+ return str.replace(regex, "");
+ }
+ function hideTocIfNotNeeded(docObject, forceHide) {
+ var shouldHide = forceHide;
+ var tocElement = docObject.querySelector(".toc");
+ if (tocElement) {
+ var tocMenuElement = tocElement.querySelector(".toc__menu");
+ if (null == tocMenuElement || false == tocMenuElement.hasChildNodes) shouldHide = true;
+ }
+ if (shouldHide) {
+ tocElement.classList.add("empty");
+ }
+ }
function adjustSidebars() {
var loadedPageUrl = window.location.pathname;
var sidebarElement = document.querySelector(".sidebar");
@@ -8482,11 +8497,7 @@ $(function() {
block: "nearest"
});
}
- var tocElement = document.querySelector(".toc");
- if (tocElement) {
- var tocMenuElement = tocElement.querySelector(".toc__menu");
- if (null == tocMenuElement || false == tocMenuElement.hasChildNodes) tocElement.classList.add("empty");
- }
+ hideTocIfNotNeeded(document, false);
}
}
function loadContentFromUrl(url, onSuccess, onError) {
@@ -8542,7 +8553,7 @@ $(function() {
}, error => {
if (error == "Error: 404") {
var baseURL = window.location.origin;
- var notFoundURL = baseURL + "/" + docRoot + "/" + notFoundPageName;
+ var notFoundURL = baseURL + "/" + (docRoot != "" ? docRoot + "/" : "") + notFoundPageName;
updateContentFromUrl(notFoundURL);
} else {
currContent.innerHTML = "
Sorry, there was a problem loading the content!
(" + error + ")";
@@ -8551,12 +8562,15 @@ $(function() {
});
}
function getCollectionFromDocPath(url) {
- var parts = url.href.split("/");
- var docIndex = parts.indexOf(docRootName);
- if (docIndex === -1 || docIndex === parts.length - 1) {
- return "";
+ var collection = "";
+ var parts = trimCharFromString(url.pathname, "/").split("/");
+ if (docRoot == "") {
+ collection = parts[0];
+ } else {
+ var docIndex = parts.indexOf(docRoot);
+ if (docIndex !== -1 && docIndex !== parts.length - 1) collection = parts[docIndex + 1];
}
- return parts[docIndex + 1];
+ return collection;
}
function sameCollection(url1, url2) {
var collection1 = getCollectionFromDocPath(url1);
@@ -8565,11 +8579,12 @@ $(function() {
}
function handleNavLinkClick(event) {
if (!event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey) {
+ if (tooltipTarget) hideTooltip(true);
var updated = false;
var anchorElement = event.originalTarget.closest("a");
if (anchorElement) {
var url = new URL(anchorElement.href);
- if (url.origin == window.location.origin && sameCollection(url, window.location)) {
+ if (url.origin === window.location.origin && anchorElement.target !== "_blank" && sameCollection(url, window.location)) {
event.preventDefault();
var urlStr = url.pathname + url.hash;
updated = urlStr != window.location.pathname + window.location.hash;
@@ -8578,7 +8593,7 @@ $(function() {
}
event.target.blur();
}
- if (false == updated) console.debug("Different collection item requested, loading full page...");
+ if (false == updated) console.debug("Different collection item or new tab/page requested, loading full page...");
}
}
function updateNavLinks(event) {
@@ -8620,14 +8635,17 @@ $(function() {
}
});
}
- function alterPageTitle(content) {
+ function alterPageForTooltip(content, fullPageContent) {
let tempContainer = document.createElement("div");
tempContainer.innerHTML = content;
+ if (fullPageContent) hideTocIfNotNeeded(tempContainer, true);
const pageTitle = tempContainer.querySelector("#page-title");
if (pageTitle) pageTitle.style.marginTop = "1em";
const pageSubtitle = tempContainer.querySelector("#page-subtitle");
if (pageSubtitle) pageSubtitle.style.borderBottom = "0px";
- return tempContainer.innerHTML;
+ var newContent = tempContainer.innerHTML;
+ newContent = newContent.replace(/\bcontent-tooltip\b/g, "");
+ return newContent;
}
function loadContentPartFrom(url, onSuccess, onError) {
var startHeadingId = "page-title";
@@ -8643,7 +8661,6 @@ $(function() {
content += nextSibling.outerHTML;
nextSibling = nextSibling.nextElementSibling;
}
- if (false == hasAnchor) content = alterPageTitle(content);
onSuccess(content);
} else console.error("Start heading not found by ID: " + startHeadingId);
}, error => {
@@ -8672,8 +8689,9 @@ $(function() {
var newPosition = position + "px";
tooltip.style.setProperty(posName, newPosition);
}
- function showTooltip(event, tooltipText) {
+ function showTooltip(event, tooltipText, fullPageContent) {
tooltip.innerHTML = tooltipText.innerHTML;
+ if (fullPageContent) tooltip.classList.add("full-content-tooltip"); else tooltip.classList.remove("full-content-tooltip");
var tooltipPos = getTooltipPos(event, tooltipTarget);
var tooltipArrowLeftShift = 2 * toolTipArrowSize;
setArrowPosition("--tooltip-arrow-top", -1 * toolTipArrowSize);
@@ -8715,17 +8733,25 @@ $(function() {
tooltipText.textContent = "";
element.appendChild(tooltipText);
element.addEventListener("mouseover", function(event) {
+ var fullPageContent = element.classList.contains("full-content-tooltip");
tooltipTarget = element;
if (tooltipText.innerHTML === "") {
var url = element.href;
- loadContentPartFrom(url, newContent => {
- newContent = newContent.replace(/\bcontent-tooltip\b/g, "");
+ function onSuccess(newContent) {
+ if (typeof newContent === "object" && "innerHTML" in newContent) newContent = newContent.innerHTML;
+ newContent = alterPageForTooltip(newContent, fullPageContent);
tooltipText.innerHTML = newContent;
- showTooltip(event, tooltipText);
- }, error => {
+ showTooltip(event, tooltipText, fullPageContent);
+ }
+ function onError(error) {
console.error("Error loading the tooltip content!" + error);
- });
- } else showTooltip(event, tooltipText);
+ }
+ if (fullPageContent) {
+ loadContentFromUrl(url, newContent => onSuccess(newContent), error => onError(error));
+ } else {
+ loadContentPartFrom(url, newContent => onSuccess(newContent), error => onError(error));
+ }
+ } else showTooltip(event, tooltipText, fullPageContent);
});
});
document.addEventListener("mousemove", event => {
@@ -8744,6 +8770,9 @@ $(function() {
document.addEventListener("mouseover", function(event) {
elementUnderCursor = event.target;
});
+ window.addEventListener("blur", function() {
+ if (tooltipTarget) hideTooltip(true);
+ });
}
var initiallySticky = $(".sidebar").hasClass("sticky");
var stickySideBar = function() {
@@ -8794,7 +8823,7 @@ $(function() {
});
$(function() {
- lunr.tokenizer.separator = /[\s\-_]+/;
+ lunr.tokenizer.separator = /[\s]+/;
});
$(function() {
diff --git a/_sass/minimal-mistakes/minimal-mistakes/_navigation.scss b/_sass/minimal-mistakes/minimal-mistakes/_navigation.scss
index 2d05614b..9db1b045 100644
--- a/_sass/minimal-mistakes/minimal-mistakes/_navigation.scss
+++ b/_sass/minimal-mistakes/minimal-mistakes/_navigation.scss
@@ -733,7 +733,7 @@
}
/*
- Tootltip content navigation
+ Tooltip content navigation
========================================================================== */
// @font-face {
@@ -768,6 +768,15 @@
@include breakpoint($x-large) {
max-width: $right-sidebar-width + 125px;
}
+ &.full-content-tooltip {
+ max-width: 400px;
+ @include breakpoint($large) {
+ max-width: 2 * $right-sidebar-width-narrow + 100px;
+ }
+ @include breakpoint($x-large) {
+ max-width: 2 * $right-sidebar-width + 125px;
+ }
+ }
height: auto;
padding-top: 0;
diff --git a/_sass/minimal-mistakes/minimal-mistakes/_search.scss b/_sass/minimal-mistakes/minimal-mistakes/_search.scss
index 863f6c43..9a38d0e4 100644
--- a/_sass/minimal-mistakes/minimal-mistakes/_search.scss
+++ b/_sass/minimal-mistakes/minimal-mistakes/_search.scss
@@ -81,12 +81,13 @@
display: block;
margin-bottom: 0;
padding: 0;
+ padding-bottom: 0.5em;
border: none;
outline: none;
box-shadow: none;
background-color: transparent;
font-size: $type-size-3;
-
+
@include breakpoint($large) {
font-size: $type-size-2;
}
@@ -96,6 +97,16 @@
}
}
+ a:not(.btn) {
+ &:hover {
+ text-decoration: underline;
+
+ img {
+ box-shadow: 0 0 10px rgba(#000, 0.25);
+ }
+ }
+ }
+
&.is--visible {
display: block;
visibility: visible;
From dfc3dbb7e49fe597a6db9a96c0c0173269eaf982 Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 12:30:50 +0200
Subject: [PATCH 11/14] Just some convention mismatch correction
Signed-off-by: Hofi
---
_js/custom/navigation.js | 4 ++--
_js/main.min.js | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/_js/custom/navigation.js b/_js/custom/navigation.js
index e0aef639..cbaba3af 100644
--- a/_js/custom/navigation.js
+++ b/_js/custom/navigation.js
@@ -504,7 +504,7 @@ $(function () {
});
});
- document.addEventListener('mousemove', (event) => {
+ document.addEventListener('mousemove', function (event) {
if (shouldHideTooltip(event.target)) {
if (tooltipTarget)
hideTooltip(true);
@@ -515,7 +515,7 @@ $(function () {
}
});
- document.addEventListener('scroll', (event) => {
+ document.addEventListener('scroll', function (event) {
if (elementUnderCursor == null || shouldHideTooltip(elementUnderCursor)) {
if (tooltipTarget)
hideTooltip(true);
diff --git a/_js/main.min.js b/_js/main.min.js
index de869a0e..f1efa7f5 100644
--- a/_js/main.min.js
+++ b/_js/main.min.js
@@ -8754,7 +8754,7 @@ $(function() {
} else showTooltip(event, tooltipText, fullPageContent);
});
});
- document.addEventListener("mousemove", event => {
+ document.addEventListener("mousemove", function(event) {
if (shouldHideTooltip(event.target)) {
if (tooltipTarget) hideTooltip(true);
} else {
@@ -8762,7 +8762,7 @@ $(function() {
shouldShowTooltip = true;
}
});
- document.addEventListener("scroll", event => {
+ document.addEventListener("scroll", function(event) {
if (elementUnderCursor == null || shouldHideTooltip(elementUnderCursor)) {
if (tooltipTarget) hideTooltip(true);
}
From 43efe1ab95858dc0794eb1144770ae0d5a87f851 Mon Sep 17 00:00:00 2001
From: Hofi
Date: Thu, 9 May 2024 12:31:36 +0200
Subject: [PATCH 12/14] Search string is now remebered between page reloads as
well
Signed-off-by: Hofi
---
_js/lunr/lunr-en.js | 106 ++++++++++++++++++++++++++++++++------------
1 file changed, 78 insertions(+), 28 deletions(-)
diff --git a/_js/lunr/lunr-en.js b/_js/lunr/lunr-en.js
index ab44341d..cafa9864 100644
--- a/_js/lunr/lunr-en.js
+++ b/_js/lunr/lunr-en.js
@@ -30,52 +30,102 @@ function removeExtension(url) {
return url; // If no extension found, return the original URL
}
+// Function to set a cookie
+function setCookie(name, value, days) {
+ var expires = "";
+ if (days) {
+ var date = new Date();
+ date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
+ expires = "; expires=" + date.toUTCString();
+ }
+ document.cookie = name + "=" + (value || "") + expires + "; path=/; SameSite=Strict";
+}
+
+// Function to get a cookie value
+function getCookie(name) {
+ var nameEQ = name + "=";
+ var ca = document.cookie.split(';');
+ for (var i = 0; i < ca.length; i++) {
+ var c = ca[i];
+ while (c.charAt(0) == ' ') {
+ c = c.substring(1, c.length);
+ }
+ if (c.indexOf(nameEQ) == 0) {
+ return c.substring(nameEQ.length, c.length);
+ }
+ }
+ return null;
+}
+
$(document).ready(function() {
- $('input#search').on('keyup', function () {
+
+ // Function to restore input field value from cookie
+ function restoreInputValue() {
+ var searchInput = document.getElementById('search');
+ var searchValue = getCookie('search');
+ if (searchValue) {
+ searchInput.value = searchValue;
+ onKeyUp();
+ }
+ }
+
+ // Function to save input field value to cookie
+ function saveInputValue() {
+ var searchInput = document.getElementById('search');
+ setCookie('search', searchInput.value, 365);
+ }
+
+ function onKeyUp() {
+ saveInputValue();
+
var resultdiv = $('#results');
- var query = $(this).val().toLowerCase();
+ var searchInput = document.getElementById('search');
+ var query = searchInput.value.toLowerCase();
var result =
idx.query(function (q) {
query.split(lunr.tokenizer.separator).forEach(function (term) {
q.term(term, { boost: 100 })
- if(query.lastIndexOf(" ") != query.length-1){
- q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
+ if (query.lastIndexOf(" ") != query.length - 1) {
+ q.term(term, { usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING, boost: 10 })
}
- if (term != ""){
- q.term(term, { usePipeline: false, editDistance: 1, boost: 1 })
+ if (term != "") {
+ q.term(term, { usePipeline: false, editDistance: 1, boost: 1 })
}
})
});
resultdiv.empty();
- resultdiv.prepend('