Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including hexo-algolia with all npm packages installed. Try it out:

var hexoAlgolia = require("hexo-algolia")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

hexo-algolia v1.2.5

Index your content in Algolia Search API

hexo-algolia Build Status

Index content of an hexo website in Algolia and provide JavaScript helpers to add search in your hexo theme.

Browse the CHANGELOG to learn what has changed between versions.


Compatible with node>=4.0.0.

$ npm install --save hexo-algolia

Public Facing Search Options

You can configure Algolia integration to your hexo website with the _config.yml file:

  applicationID: 'applicationID'
  apiKey: 'apiKey'
  indexName: '...'
Config Key
applicationIDYour Algolia Application ID
apiKeyA Search-Only API key
indexNameThe name of the Algolia index to use

These configuration values are accessible from your hexo theme, to be used with Algolia JavaScript client.

Hexo Helpers

Helpers are provided to make your life easier.

Algolia JavaScript Client Tags

The plugin provides an easy way to add Algolia JavaScript API Client either locally (served by hexo) or remotely (via Algolia CDN).

<%- algolia_search() %>

Renders as:

<script src="/assets/algolia/algoliasearchLite.min.js" async></script>
<%- algolia_search_cdn() %>

Renders as:

<script src="" async></script>

Configuration <meta> Tag

You can make your index configuration available to your page and client-side scripts by adding the algolia_config() hexo helper in the <head> of your document.

<%- algolia_search_config() %>

Renders as:

<meta property="algolia:search" data-application-id="..." data-api-key="..." data-index-name="...">

You can access the exposed configuration by querying the data attribute of the algolia:search meta tag:

const algoliaConfig = document.querySelector('meta[property="algolia:search"]').dataset;

const client = algoliasearch(algoliaConfig.applicationID, algoliaConfig.apiKey);
const index = client.initIndex(algoliaConfig.indexName);

Indexing Content

Content can be indexed from the command line with the help of the hexo algolia command.

$ ./node_modules/.bin/hexo algolia


A separate API Key must be provided as an environment variable named HEXO_ALGOLIA_INDEXING_KEY. Create it with these limited write access permissions: Add records, Delete records, List indices, Delete index.

$ ./node_modules/.bin/hexo algolia


$ ./node_modules/.bin/hexo help algolia
Usage: ./node_modules/.bin/hexo algolia

Index your content in Algolia Search API

  --dry-run          Does not push content to Algolia
  --flush            Resets the Algolia index before starting the indexation

Security Concerns

Never store your Admin API Key as apiKey in the _config.yml file: it would give full control of your Algolia index to others and you don't want to face the consequences.

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



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free