Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLING-12052: add Pagefind for site search #133

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .sling-module.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"branches": {
"master": {
"nodeLabel": "git-websites",
"additionalMavenParams": "-Ppublish-site -Dmsg=\"Automatic website deployment from $BUILD_URL\""
"additionalMavenParams": "-Ppagefind,publish-site -Dmsg=\"Automatic website deployment from $BUILD_URL\""
}
},
"jdks": [
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Clone this repository, run the below Maven command, open <http://localhost:8820/

This allows you to experiment with your changes before eventually publishing them.

To also activate the site search feature, use

mvn clean package -Ppagefind,run-site

## How to publish the website

The publishing process consists out of 2 steps:
Expand Down Expand Up @@ -76,6 +80,11 @@ Highlighting can be disabled by specifying an unknown language in the `<pre>` bl
This will not be highlighted.
</pre>

## Site search

The site search is based on [Pagefind](https://pagefind.app/), which is also used by the ASF
[community](https://community.apache.org/) and [www](https://www.apache.org/) websites. Searching the source code for "pagefind" shows how the integration works.

## Other Apache projects using JBake
It's sometimes useful to ~~steal ideas~~ get inspiration from other projects using similar tools, for now we know of:

Expand Down
46 changes: 45 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<repos.list.fullpath>${downloads.dir}/github-repositories.xml</repos.list.fullpath>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Must match the JBake output folder -->
<pagefind.site.folder>${project.build.directory}/${project.artifactId}-${project.version}</pagefind.site.folder>

<!-- pagefind needs to run after compile and before package... -->
<pagefind.maven.phase>test</pagefind.maven.phase>
</properties>

<build>
Expand Down Expand Up @@ -210,6 +216,44 @@
</plugins>
</build>
</profile>
<profile>
<id>pagefind</id>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.14.0</version>
<configuration>
<npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
<installDirectory>${project.build.directory}</installDirectory>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
<executions>
<execution>
<id>Install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>${pagefind.maven.phase}</phase>
<configuration>
<nodeVersion>v20.7.0</nodeVersion>
</configuration>
</execution>
<execution>
<id>Build pagefind index</id>
<goals>
<goal>npx</goal>
</goals>
<phase>${pagefind.maven.phase}</phase>
<configuration>
<arguments>pagefind --site ${pagefind.site.folder}</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
17 changes: 14 additions & 3 deletions src/main/jbake/assets/res/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a:hover {


.sidemenu {
border-top: 10px solid #f9bb00;
border-top: var(--page-border-top-height,10px) solid #f9bb00;
}

.sidemenu ul,.sidemenu p {
Expand All @@ -47,7 +47,7 @@ a:hover {
}

.main {
border-top: 10px solid #cde0ea;
border-top: var(--page-border-top-height,10px) solid #cde0ea;
max-width: 1000px;
}

Expand Down Expand Up @@ -150,4 +150,15 @@ ul.repolist {
color: #060;
margin: 0;
padding: 0;
}
}

#searchbox {
width: 100%;
--pagefind-ui-border: #cde0ea;
--pagefind-ui-border-width: 1px;
--pagefind-ui-border-radius: 1px;
}

:root {
--page-border-top-height: 5px;
}
10 changes: 10 additions & 0 deletions src/main/jbake/templates/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ head {
</script>
<!-- End Matomo Code -->
'''

yieldUnescaped "<link href='/pagefind/pagefind-ui.css' rel='stylesheet'>"
yieldUnescaped "<script src='/pagefind/pagefind-ui.js' type='text/javascript'></script>"
yieldUnescaped '''
<script>
window.addEventListener('DOMContentLoaded', (event) => {
new PagefindUI({ element: "#searchbox" });
});
</script>
'''
}
5 changes: 4 additions & 1 deletion src/main/jbake/templates/layout/main.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ html(lang:'en'){
div(class:"level is-marginless") {
include template: 'logos.tpl'
}
section(class:"searchbox level is-marginless") {
div(id:"searchbox") {}
}
div(class:"columns is-gapless") {
div(class:"column is-narrow sidemenu") {
include template: 'menu.tpl'
Expand All @@ -21,7 +24,7 @@ html(lang:'en'){

if( content ) {
if(content.title) {
h1(class:"title") {
h1(class:"title","data-pagefind-body":true) {
Copy link
Member

@kwin kwin Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this restrict indexing to this title only per page(https://pagefind.app/docs/indexing/#limiting-what-sections-of-a-page-are-indexed)/. What about increasing the ranking with data-pagefind-weight="10" (or "9") for this particular h1 and still index the rest of the body?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this restrict indexing to this title only per page...

The docs that you point to say "Multiple data-pagefind-body elements may exist on a page, and their content will be combined" - but this didn't work, it looks like pagefind does not index what it finds to be a title, due to it being the first H1 on the page. I have removed this attribute now.

yield "${ content.title }"
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/jbake/templates/page.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ layout 'layout/main.tpl', true,
include template : 'toc-brick.tpl'
},
bodyContents: contents {
div(class:"row"){
div(class:"row","data-pagefind-body":true){
div(){
section(){
yieldUnescaped U.processBody(content, config)
Expand Down