Download the PHP package johannschopplich/kirby-algolia-docsearch without Composer
On this page you can find all versions of the php package johannschopplich/kirby-algolia-docsearch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download johannschopplich/kirby-algolia-docsearch
More information about johannschopplich/kirby-algolia-docsearch
Files in johannschopplich/kirby-algolia-docsearch
Package kirby-algolia-docsearch
Short Description Algolia DocSearch plugin for Kirby CMS
License MIT
Homepage https://github.com/johannschopplich/kirby-algolia-docsearch#readme
Informations about the package kirby-algolia-docsearch
Kirby Algolia DocSearch
Quickest way to integrate a search bar in your Kirby project. Index your content with a Kirby CLI command or Panel button push it to Algolia. The Algolia's DocSearch JavaScript library will display a search button and result modal for you.
You can use the Algolia free plan, since the plugin itself indexes and parses the site. The Algolia crawler (a paid feature) is not needed. Leaving you with the option to stick with the free tier. πΈ
βBut DocSearch is for documentations! My Kirby project is not a documentation!β you might add.
Well, we co-opt the DocSearch library for our own purposes. π The library can be used anywhere, if the data model matches the requirements. Which it does. π
Key Features
- π«‘ No Algolia configuration required, just an account
- π Multi-language support
- π Kirby CLI command support
- π§ Janitor support
Preview
Requirements
- Kirby 3.9+
Kirby is not free software. However, you can try Kirby and the Starterkit on your local machine or on a test server as long as you need to make sure it is the right tool for your next project. β¦ and when youβre convinced, buy your license.
Installation
Composer
Download
Download and copy this repository to /site/plugins/kirby-algolia-docsearch
.
Setup
Algolia Account
If you do not yet have an Algolia account, you can create one.
DocSearch Library
The DocSearch library to display the search input field and result modal is not included in this package. Follow the instructions on the Algolia DocSearch installation website to add it to your project.
π tl;dr Installation
1. Import the required JS and CSS files in your project. Either by using a CDN or by installing the library via NPM. Or: 2. Create a [container](https://docsearch.algolia.com/docs/api#container) for your DocSearch component to go in. 3. Initialize the DocSearch library with your Algolia credentials.Usage
Configuration
Callback for Content
Instead of extracting content by an HTML tag name, you can define a closure which returns the content of a page:
In multi-language projects, you can also pass the language code to the closure and return the content for the given language:
Defining callbacks for each template is also possible:
Indexing the Site
Kirby CLI
Run the algolia-docsearch:index
command to index your content.
Panel Button
Given you have Janitor plugin installed, you can add a button to the Panel to index your content.
Page Hooks
This plugin registers page hooks to index a given page on changed slug, title, content or status. These hooks are not triggered by default, but have to be enabled in the plugin options.
With hooks enabled, you can index the whole page once and the plugin will keep the index up to date.
Multilang Projects
If languages are enabled in your Kirby project, the plugin will create an Algolia index for each language. The index name will be the value of the index
option appended by the language code, e.g. example-de
.
Cookbook
Index Blocks from text
Field
If you only want to index the main content of your pages, e.g. in a blocks field, you can define a closure for the content
option which returns the text content of a page.
DocSearch Initialization in Multilang Projects
For multilanguage projects you have to pass the translation's index name to the DocSearch library. You can extract the lang
attribute from the html
tag and append it to the index name.
Styling the Search Modal
The DocSearch library provides a customization API to style the search modal. You can add the following CSS to your project to style the search modal.
In practice, it's easiest to overwrite some CSS Custom Properties. You may take a look at how I styled the component.
Special Thanks
- Wolf-Dieter Grabner for sponsoring the initial version of this package. π
- Lukas Bestle and Nico Hoffmann for their Algolia integration.
License
Johann Schopplich