I’m currently using the SimpleSearch plugin on my GRAV CMS website to search and display results. However, I’m encountering an issue where the search results include links to non-routable pages, specifically those located in folders with names prefixed by an underscore (e.g., _hidden/page.md).
I would like to find a solution to exclude these non-routable pages from the search results. Ideally, I would prefer to avoid having to add code to each individual non-routable page.
Not an answer to your question, but have you tried the TNT Search plugin?
I can’t remember the details of why, but I had lots of problems like yours when I tried making SimpleSearch work, and they mostly went away when I switched to TNT Search. Both are released by the Grav team. There’s also Algolia as a premium plugin but I haven’t tried it except as a user on the Grav docs and I’m not very impressed.
However, I’m encountering an issue where the search results include links to non-routable pages, specifically those located in folders with names prefixed by an underscore (e.g., _hidden/page.md ).
“Non-routable”
The purpose of using the underscore (_) as prefix in a foldername is, imho, not to mark it as non-routable, but to mark a page as a module. Modules will be treated differently by Grav. Although a module is non-routable, it will be treated differently form pages which are explicitly being marked as non-routable using routable: false in the header of the page.
SimpleSearch
I suspect when a module (underscore prefixed folder) contains the search keyword, the parent (the modular) will be returned and not the module itself.
If you have a different experience, please share the relevant folder tree and frontmatter.
I wasn’t aware of the TNT Search plugin, but I’ll definitely take a closer look at it. It sounds like it might resolve some of the issues I’m facing with SimpleSearch.
Thank you for the detailed explanation regarding “non-routable” pages and the use of the underscore prefix. Your clarification helps me understand how modules are treated differently in GRAV. I appreciate the insight and will consider it while working on my site.
Thanks again to both of you for your helpful suggestions and explanations!
On this page, I display several modules, including, for example, Hero.
Case 1.
01.start -> 01._hero -> section.md
section.md:
title: 'We invest in the environment together'
block: hero
layout: full-image
...
The search finds the phrase ‘We invest in the environment together’ and directs to the main page. Thanks to you, I understand the reasoning behind this behavior. However, in my case, it causes confusion.
Case 2.
title: 'We invest in the environment together'
simplesearch:
process: false
block: hero
layout: full-image
...
When entering the phrase: ‘We invest in the environment together’, the search finds nothing. That’s ok!
Case 3.
title: 'We invest in the environment together'
routable: false
block: hero
layout: full-image
...
Gives me exactly the same result as in Case 1. That is, the phrase is found, and the link from the search results directs to the main page.
By default, all pages are routable . This means that they can be reached by pointing your browser to the URL of the page.
However, you may need to create a page that is created to hold specific content, but it is meant to be called directly by a plugin, other content, or even a theme directly.
The module is directly called by the modular, hence it will be available according the definition shown above.