Giter Site home page Giter Site logo

soxft / hexo-algolia Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thom4parisot/hexo-algolia

0.0 0.0 0.0 168 KB

Index your hexo website content to Algolia Search.

Home Page: https://npmjs.com/hexo-algolia

License: MIT License

JavaScript 100.00%

hexo-algolia's Introduction

hexo-algolia Build Status

Index content of your hexo website in Algolia and add search within minutes.

hexo-algolia is an hexo plugin provided by the community. This is what you get when you install it:

  1. a new command, hexo algolia, to index the content of your website
  2. a theme helper to include Algolia search client
  3. another theme helper to configure the Algolia search client

๐Ÿ‘Œ The hexo algolia 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>=4.0.0.

hexo theme

Install

$ npm install --save hexo-algolia

Public Facing Search Options

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

algolia:
  applicationID: 'applicationID'
  apiKey: 'apiKey'
  indexName: '...'
Config Key
applicationIDย  Your Algolia Application ID
apiKey A Search-Only API key
indexName The name of the Algolia 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 algolia_search theme helper adds the Algolia search client to your pages.

<%- algolia_search() %>

Renders as:

<script src="/assets/algolia/algoliasearchLite.min.js" async></script>

Configure Algolia JavaScript Client

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() %>

Once done, you can retrieve Algolia 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);

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 algolia command.

$ ./node_modules/.bin/hexo algolia

API Key

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.

$ export HEXO_ALGOLIA_INDEXING_KEY=โ€ฆ
$ ./node_modules/.bin/hexo algolia

Usage

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

Description:
Index your content in Algolia Search API

Options:
  --dry-run       Does not push content to Algolia (default: false).
  --flush         Resets the Algolia index before starting the indexation (default: false).
  --indexing-key  An algolia 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 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.

License

MIT

hexo-algolia's People

Contributors

alexjoverm avatar borisschapira avatar dependabot[bot] avatar emohamed avatar soxft avatar thom4parisot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.