hexo-meilisearch
v0.1.0
Published
Index content of your hexo website in Meilisearch and add search within minutes.
Downloads
1
Readme
hexo-meilisearch
Index content of your hexo website in Meilisearch and add search within minutes. This package inspiring from hexo-algolia
hexo-meilisearch
is an hexo plugin provided by the community.
This is what you get when you install it:
- a new command,
hexo meilisearch
, to index the content of your website - a theme helper to include Meilisearch search client
- another theme helper to configure the Meilisearch search client
👌 The hexo meilisearch
command can be run manually on your computer
and on a continuous integration system like [Travis CI][-ci-node].
📜 Browse the CHANGELOG to learn what has changed between versions.
⬢ Compatible with node>=16.0.0
.
Install
$ npm install --save hexo-meilisearch
Public Facing Search Options
You can configure Meilisearch integration to your hexo website with the _config.yml
file:
meilisearch:
host: 'hostUrl'
searchKey: 'YourSearchKey'
indexName: '...'
| Config Key | |
|-------------|------------------------------------------|
| host
| Your Meilisearch Search Url |
| searchKey
| A Search-Only Key |
| indexName
| The name of the Meilisearch index to use |
These configuration values are accessible from your hexo theme, to be used with Algolia JavaScript client.
Hexo Theme Setup
Helpers are provided to make your life easier.
Include Algolia JavaScript Client
The meilisearch
theme helper adds the
Meilisearch client to your pages.
<%- meilisearch() %>
Renders as:
<script src="/assets/meilisearch/milisearch.umd.js" async></script>
Configure Meilisearch JavaScript Client
You can make your index configuration available to your page and client-side scripts by adding the meilisearch_config()
hexo helper in the <head>
of your
document.
<%- meilisearch_config() %>
Once done, you can retrieve Algolia configuration by querying the
data attribute
of the meilisearch
meta tag.
const meilisearchConfig = document.querySelector('meta[property="meilisearch"]').dataset;
const client = new MeiliSearch({
host : meilisearchConfig.host,
apiKey: meilisearchConfig.searchKey
});
const index = client.index(meilisearchConfig.indexName);
Display Search Results
It is now up to you to use the aforementioned example to trigger a search and display the results in your page.
If you need some help, have a look at the search client doc and the tutorials.
Indexing Content
Content is indexed with the help of the hexo meilisearch
command.
$ ./node_modules/.bin/hexo meilisearch
API Key
A separate API Key must be provided as an environment variable named HEXO_MEILISEARCH_API_KEY
. Create it with these limited write access
permissions: Add records
, Delete records
, List indices
, Delete index
.
$ export HEXO_MEILISEARCH_API_KEY=…
$ ./node_modules/.bin/hexo meilisearch
Usage
$ ./node_modules/.bin/hexo help meilisearch
Usage: ./node_modules/.bin/hexo meilisearch
Description:
Index your content in Meilisearch Search API
Options:
--dry-run Does not push content to Algolia (default: false).
--flush Resets the Algolia index before starting the indexation (default: false).
--api-key An meilisearch API key with add/delete records permissions.
It should be different than the search-only API key configured in _config.yml.
--layouts A comma-separated list of page layouts to index (default: "page").
Security Concerns
Never store your API Key as apiKey
in the _config.yml
file: it would give full control of your meilisearch index to others
and [you don't want to face the consequences][daily-mirror-bonanza].
Please read Meilisearch Security guide thoroughly if you need some more informations about this.