Clarify search form example

Addresses #6, which highlights some confusion about the example search form.
This updates it to use the `link` filter used in Pico templates to render URLs
appropriate for the value of the `rewrite_url` config variable.
This commit is contained in:
Pontus Horn
2019-06-14 23:08:36 +02:00
committed by GitHub
parent d456e95c96
commit 1adbcec56f

View File

@@ -61,11 +61,11 @@ in a sub-folder) and see the search results for "foobar" listed.
## The search form
How to design your search form is up to you, but here's a very rudimentary example which you can put either in a
template file or on a specific page.
How to design your search form is up to you, but here's a very rudimentary example which you can put in a
template file:
```html
<form id="search_form" action="/search">
<form id="search_form" action="{{ "search"|link }}">
<label for="search_input">Search the site:</label>
<input type="search" id="search_input" name="q" />
<input type="submit" value="Search" />
@@ -74,12 +74,14 @@ template file or on a specific page.
// Intercept form submit and go to the search results page directly, avoiding a redirect
document.getElementById('search_form').addEventListener('submit', function (e) {
var search_terms = document.getElementById('search_input').value;
location.href = '/search/' + encodeURIComponent(search_terms);
location.href = '{{ "search"|link }}/' + encodeURIComponent(search_terms);
e.preventDefault();
});
</script>
```
If you want to put it in a content file, you'll have to adjust the template variables accordingly, ie. instead of `{{ "search"|link }}` you'd use something like `%base_url%?search`.
## Configuration options
You can exclude certain pages from being included in the search results by using the configuration option `search_excludes`.