You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2025/06/22 14:06:54 UTC
(freemarker-docgen) branch master updated (cf09fc5 -> 4fb4b0a)
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-docgen.git
from cf09fc5 Pagefind: Updated README
new cf5adb0 Pagefind: Less confusing UI logic for hiding the search
new 4fb4b0a Pagefind: Added data-pagefind-weight attributes to demote index pages, and the to a lesser extent the changelogs. Un-hided H1, as despite it's repetitive next to the tile, the title is not indexed.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../freemarker/docgen/core/statics/js/pagefind.js | 29 +++++++++++
.../org/freemarker/docgen/core/templates/page.ftlh | 60 ++++++++++++++++------
2 files changed, 73 insertions(+), 16 deletions(-)
(freemarker-docgen) 01/02: Pagefind: Less confusing UI logic for hiding the search
Posted by dd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-docgen.git
commit cf5adb080d474f0f6d11670786eebf42ff631382
Author: ddekany <dd...@apache.org>
AuthorDate: Sun Jun 22 14:01:20 2025 +0200
Pagefind: Less confusing UI logic for hiding the search
---
.../freemarker/docgen/core/statics/js/pagefind.js | 29 ++++++++++++++++++++++
.../org/freemarker/docgen/core/templates/page.ftlh | 6 ++---
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/statics/js/pagefind.js b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/statics/js/pagefind.js
index 2ba281b..56c7d90 100644
--- a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/statics/js/pagefind.js
+++ b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/statics/js/pagefind.js
@@ -65,14 +65,38 @@ function getPagefindPanelToggleButton() {
return memoizedPagefindPanelToggleButton;
}
+var memoizedPagefindCloseButton = null;
+function getPagefindCloseButton() {
+ if (memoizedPagefindCloseButton == null) {
+ const button = getPagefindPanel().querySelector('button.pagefind-ui__search-clear');
+ if (!button) {
+ window.alert('Pagefind close button not found!');
+ throw new Error('Pagefind close button not found!');
+ }
+ memoizedPagefindCloseButton = button;
+ }
+ return memoizedPagefindCloseButton;
+}
+
function hidePagefindPanel() {
getPagefindPanel().style.display = 'none';
+ getPagefindPanelToggleButton().style.visibility = 'visible';
getPagefindInput().blur();
}
function showPagefindPanel() {
+ if (location.protocol === 'file:') {
+ window.alert('PLEASE NOTE: ' +
+ 'Due to the security restrictions of browsers (same origin policy), search is only expected to work ' +
+ 'if you visit via HTTP(S), and not via a "file:" URL. For local testing, use something like ' +
+ '"npx http-server"!');
+ }
+
getPagefindPanel().style.display = 'block';
+ getPagefindPanelToggleButton().style.visibility = 'hidden';
getPagefindInput().focus();
+
+ getPagefindCloseButton().style.visibility = 'visible';
}
function togglePagefindPanel() {
@@ -99,6 +123,11 @@ function addDocgenPagefindCustomizations() {
}
});
+ const closeButton = getPagefindCloseButton();
+ closeButton.addEventListener('click', (event) => {
+ hidePagefindPanel();
+ });
+
hidePagefindPanel();
}
diff --git a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
index 2500ab3..66751ec 100644
--- a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
+++ b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
@@ -82,9 +82,9 @@
</#if>
<#if hasSearch && pagefindBasedSearch>
- <link href="pagefind/pagefind-ui.css" rel="stylesheet">
- <script src="pagefind/pagefind-ui.js"></script>
- <script src="docgen-resources/js/pagefind.js"></script>
+ <link href="pagefind/pagefind-ui.css?${transformStartTime?long?c}" rel="stylesheet">
+ <script src="pagefind/pagefind-ui.js?${transformStartTime?long?c}"></script>
+ <script src="docgen-resources/js/pagefind.js?${transformStartTime?long?c}"></script>
</#if>
</head>
</#compress>
(freemarker-docgen) 02/02: Pagefind: Added data-pagefind-weight attributes to demote index pages, and the to a lesser extent the changelogs. Un-hided H1, as despite it's repetitive next to the tile, the title is not indexed.
Posted by dd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-docgen.git
commit 4fb4b0af91dfcd6ac96a621946d6446b77bea02b
Author: ddekany <dd...@apache.org>
AuthorDate: Sun Jun 22 15:12:28 2025 +0200
Pagefind: Added data-pagefind-weight attributes to demote index pages, and the to a lesser extent the changelogs. Un-hided H1, as despite it's repetitive next to the tile, the title is not indexed.
---
.../org/freemarker/docgen/core/templates/page.ftlh | 54 ++++++++++++++++------
1 file changed, 41 insertions(+), 13 deletions(-)
diff --git a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
index 66751ec..33ae41f 100644
--- a/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
+++ b/freemarker-docgen-core/src/main/resources/org/freemarker/docgen/core/templates/page.ftlh
@@ -57,6 +57,17 @@
<meta charset="utf-8">
<title>${fullTitle}</title>
+ <#if hasSearch && pagefindBasedSearch>
+ <template data-pagefind-meta="title"><#t>
+ <#local pagefindPageTitlePath = nav.breadCrumbPathToNode(.node)>
+ <#-- Skip the book title in Pagefind search hits, except if that's all we have: -->
+ <#if pagefindPageTitlePath?size gt 1>
+ <#local pagefindPageTitlePath = pagefindPageTitlePath[1..]>
+ </#if>
+ <#list pagefindPageTitlePath as step>${u.getRequiredTitleAsString(step)}<#sep> / </#list><#t>
+ </template>
+ </#if>
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="format-detection" content="telephone=no">
@@ -161,23 +172,14 @@
<#macro pageContent>
<#local pageType = getPageType()>
<div class="col-right"><#t>
- <div class="page-content" data-pagefind-body><#t>
+ <#local pageFindWeight = tryGetPagePagefindWeight()>
+ <div class="page-content" data-pagefind-body<#if pageFindWeight != -1> data-pagefind-weight="${pageFindWeight?c}"</#if>><#t>
<#compress>
<div class="page-title"><#t>
<#if !simpleNavigationMode>
<@nav.pagers class="top" /><#t>
</#if>
- <#if hasSearch && pagefindBasedSearch>
- <div style="display: none" data-pagefind-meta="title"><#t>
- <#local pagefindPageTitlePath = nav.breadCrumbPathToNode(.node)>
- <#-- Skip the book title in Pagefind search hits, except if that's all we have: -->
- <#if pagefindPageTitlePath?size gt 1>
- <#local pagefindPageTitlePath = pagefindPageTitlePath[1..]>
- </#if>
- <#list pagefindPageTitlePath as step>${u.getRequiredTitleAsString(step)}<#sep> / </#list><#t>
- </div><#t>
- </#if>
- <div class="title-wrapper" data-pagefind-ignore="all"><#t>
+ <div class="title-wrapper"><#t>
<#visit titleElement using nodeHandlers><#t>
</div><#t>
</div><#t>
@@ -233,7 +235,7 @@
<#compress>
<#local tocElems = .node["*[@${att}]"]>
<#if (tocElems?size >= minLength)>
- <div class="page-menu">
+ <div class="page-menu" data-pagefind-ignore="all">
<#if title != ''>
<div class="page-menu-title">${title}</div>
</#if>
@@ -267,3 +269,29 @@
<#function getPageType>
<#return pageType!.node?nodeName>
</#function>
+
+<#-- Return -1 if there's no override, otherwise return the pagefind weight. -->
+<#function tryGetPagePagefindWeight(node = .node)>
+ <#list 1..999 as _>
+ <#local result = tryGetPagePagefindWeightDirect(node)!-1>
+ <#if result != -1>
+ <#return result>
+ </#if>
+
+ <#if node?parent??>
+ <#local node = node?parent>
+ <#else>
+ <#return -1>
+ </#if>
+ </#list>
+</#function>
+
+<#function tryGetPagePagefindWeightDirect node>
+ <#if node?nodeName == "index" || node.@role[0]! == 'index'>
+ <#return 0.25>
+ </#if>
+ <#if node.@role[0]! == "changelog">
+ <#return 0.67>
+ </#if>
+ <#-- Return with no result -->
+</#function>