We used this in our theme → http://delas.electronthemes-ghost.com/
In this theme for search result we only used ##title and ##excerpt variable.
You can use also these variables
Variable Name
Purpose
##title
Post title
##url
Post url
##primary_tag_name
Name of primary tag
##primary_tag_url
Url of primary tag
##primary_author_name
Name of primary author
##primary_author_url
Profile url of primary author
##primary_author_avater
Profile photo of primary author
##excerpt
show some words of the post content. Default words count is 15
##published_at
Post publication date. Format can be change by time_format option
Amazing stuff. Thank you!
The content API-key will be different for local dev instance and production, yes?
How do you approach this?
Run locally with the production API search, or replace it after deploy, or…
ghost-finder.js?v=bcdabca04f:23355 Uncaught TypeError: Cannot read property 'addEventListener' of null
at new GhostFinder (ghost-finder.js?v=bcdabca04f:23355)
Extract the files, and only take “ghost-finder.js” from the /dist folder.
It is recommended that you minify this file to improve page loading speeds.
Download your theme from the Ghost admin interface.
Place the minified file above into your theme’s /assets/js folder.
In your theme files, determine where you want to add the search bar. For this example, let’s say you want to add it under your home page, index.js.
Open up index.js in your themes folder (or whichever page) and scroll to the bottom where you will see {{#contentFor “scripts”}}
You will put the javascript files call here to load the Ghost finder search.
Paste the following code:
{{!-- Load ghost search script --}}
<script type=“text/javascript” src=“{{asset “js/ghost-finder.js”}}”>
<script>
new GhostFinder({
input: ‘.search-field’,
showResult: ‘.search-results’,
time_format: ‘DD MMM YYYY’,
singleResultTemplate: <a href="##url" class="search-result"> <img class="search-result-thumbnail" src="##feature_image" alt="##title"> <div class="search-result-title-container"><p class="search-result-title">##title</p></div> </a>,
contentApiKey: YOUR API KEY HERE FROM GHOST ADMIN INTERFACE
})
</script>
Note how we import the script first then call the new GhostFinder() instance.
singleResultTemplate is your html styling for a single search result in the list. Then, you can style the other parts yourself.
Insert the html:
<div class=“search-container”>
<input class=“search-field” type=“text” placeholder=“Search the site” autocomplete=“off”>
<div class=“search-results”>
</div>
Whereever you want your serach bar to be in the same index.js page.
Go wild with your CSS styling using <style></style> tags.