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:56 UTC
(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.
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>