Make use of HasShortcode to automtically include js files when neded.

This commit is contained in:
Fredrik Jonsson 2020-09-24 11:30:17 +02:00
commit 6b58f9f39d
2 changed files with 4 additions and 4 deletions

View file

@ -314,7 +314,7 @@ Here is the three steps needed to create a search page.
outputs:
home: ["HTML", "SearchIndex", "[other formats you need]"]
```
3. Add the shortcode `{{< search >}}` to a page. Also set `searchform: true` in the front matter for that page so the search and flexsearch js files gets loaded.
3. Add the shortcode `{{< search >}}` to a page. The search and flexsearch js files gets loaded automatically on pages that use the shortcode.
Your search page will now have a search field where all the posts of the site can be searched.
@ -327,7 +327,7 @@ If your server support php with the mail() command (very common) you can use the
1. Copy the file `themes/zen/php/contact.php.example` to `static/php/contact.php`.
2. Edit the contact.php file so it has your own e-mail address. You may also change the mail subject prefix.
3. Add the shortcode `{{< contact >}}` to a page. Also set `contactform: true` in the front matter for that page so the contact.js file gets loaded.
3. Add the shortcode `{{< contact >}}` to a page. The contact.js file gets loaded automatically on pages that use the shortcode.
If you have a SPF record for your domain, make sure the web server is listed or other mail server may mark the mail as spam.

View file

@ -10,11 +10,11 @@
{{ $mobilemenu := resources.Get "js/mobile.js" | minify | fingerprint -}}
<script defer src="{{ $mobilemenu.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "contactform" -}}
{{ if .HasShortcode "contact" -}}
{{ $contact := resources.Get "js/contact.js" | minify | fingerprint -}}
<script defer src="{{ $contact.RelPermalink }}"></script>
{{ end -}}
{{ if $.Param "searchform" -}}
{{ if .HasShortcode "search" -}}
{{ $flexsearch := resources.Get "js/lib/flexsearch.min.js" | fingerprint -}}
<script defer src="{{ $flexsearch.RelPermalink }}"></script>
{{ $search := resources.Get "js/search.js" | resources.ExecuteAsTemplate "js/search.js" . | minify | fingerprint -}}