0.1.0 ā€¢ Published 2 years ago

hexo-meilisearch v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

hexo-meilisearch Build Status

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:

  1. a new command, hexo meilisearch, to index the content of your website
  2. a theme helper to include Meilisearch search client
  3. 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.

šŸ“œ Browse the CHANGELOG to learn what has changed between versions. ā¬¢ Compatible with node>=16.0.0.

hexo theme

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
hostYour Meilisearch Search Url
searchKeyA Search-Only Key
indexNameThe 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

npm.io

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.

Please read Meilisearch Security guide thoroughly if you need some more informations about this.

License

MIT

0.1.0

2 years ago

0.0.1

2 years ago