Giter Club home page Giter Club logo

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 thom4parisot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hexo-algolia's Issues

Can't upload indexes. Too many requests error.

I have setup hexo algolia according to the docs. But when I ran $ hexo algolia, I couldn't upload the indexes to algolia. It said "Too many requests". I have been searching for days but I didn't find similar cases. Hope someone can help.

Here is the terminal output:

INFO  [hexo-algolia] Testing HEXO_ALGOLIA_INDEXING_KEY permissions.
INFO  Start processing
INFO  [hexo-algolia] 91 records to index (post, page).
INFO  [hexo-algolia] Indexing chunk 1 of 2 (50 records)
INFO  [hexo-algolia] Indexing chunk 2 of 2 (41 records)
ERROR [hexo-algolia] Too many requests
INFO  [hexo-algolia] Indexing done.

Clarify what --flush does

Taken from #35, what can be done to reassure about the destructive action --flush?

The outcome is likely to affect the README and the CLI help/commands.

Run hexo algolia error, how to solve?

NerodeMBP:Blog-hexo nero$ hexo algolia
(node:2795) [DEP0061] DeprecationWarning: fs.SyncWriteStream is deprecated.
INFO  [Algolia] Testing HEXO_ALGOLIA_INDEXING_KEY permissions.
INFO  Start processing
INFO  [Algolia] Identified 25 posts to index.
INFO  [Algolia] Start indexing...
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error
    at success (/Users/nero/Blog-hexo/node_modules/algoliasearch/src/AlgoliaSearchCore.js:351:32)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

TypeError: data.tags.map is not a function

The related hexo-next issue is here.

$ hexo algolia
INFO  [Algolia] Testing HEXO_ALGOLIA_INDEXING_KEY permissions.
INFO  Start processing
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: data.tags.map is not a function
    at F:\MyBlog\Hexo\node_modules\hexo-algolia\lib\command.js:113:39
    at Array.map (<anonymous>)
    at F:\MyBlog\Hexo\node_modules\hexo-algolia\lib\command.js:99:37
    at <anonymous>

Is this the Algolia's problem? It seems confused. Need to delete the the section of https://github.com/oncletom/hexo-algolia/blob/b04716a7ba70940094049a6816c767543404a424/lib/command.js#L112-L116

I always have 0 articles to index

It takes my blog ~4sec to load its files w/ [email protected]

I tried clearing out the ./public folder but it seems the indexing happens before the load ever happened:

image

It seems the rendering happens after generateAfter has been emitted:

image

Corp Theme

Hi,
Trying to add hexo-algolia to https://github.com/ptsteadman/hexo-theme-corporate-example and when I run hexo algolia I get following error

  C:\Nodejs\hexo-theme-corporate-example>hexo algolia
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: Cannot read property 'fields' of undefined
    at Hexo.algolia (C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo-algoliasearch\lib\algolia.js:16:39)
    at Hexo.tryCatcher (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.ret (eval at <anonymous> (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
    at C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo\lib\hexo\index.js:192:9
    at Promise._execute (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\debuggability.js:300:9)
    at Promise._resolveFromExecutor (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\promise.js:481:18)
    at new Promise (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\promise.js:77:14)
    at Hexo.call (C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo\lib\hexo\index.js:188:10)
    at C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\hexo-cli\lib\hexo.js:63:17
    at tryCatcher (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:504:31)
    at Promise._settlePromise (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:561:18)
    at Promise._settlePromise0 (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:606:10)
    at Promise._settlePromises (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:685:18)
    at Async._drainQueue (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:138:16)
    at Async._drainQueues (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:148:10)
    at Immediate.Async.drainQueues (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:570:20)
    at tryOnImmediate (timers.js:550:5)
    at processImmediate [as _immediateCallback] (timers.js:529:5)
FATAL Cannot read property 'fields' of undefined
TypeError: Cannot read property 'fields' of undefined
    at Hexo.algolia (C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo-algoliasearch\lib\algolia.js:16:39)
    at Hexo.tryCatcher (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\util.js:16:23)
    at Hexo.ret (eval at <anonymous> (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promisify.js:184:12), <anonymous>:13:39)
    at C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo\lib\hexo\index.js:192:9
    at Promise._execute (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\debuggability.js:300:9)
    at Promise._resolveFromExecutor (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\promise.js:481:18)
    at new Promise (C:\Nodejs\hexo-theme-corporate-example\node_modules\bluebird\js\release\promise.js:77:14)
    at Hexo.call (C:\Nodejs\hexo-theme-corporate-example\node_modules\hexo\lib\hexo\index.js:188:10)
    at C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\hexo-cli\lib\hexo.js:63:17
    at tryCatcher (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:504:31)
    at Promise._settlePromise (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:561:18)
    at Promise._settlePromise0 (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:606:10)
    at Promise._settlePromises (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\promise.js:685:18)
    at Async._drainQueue (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:138:16)
    at Async._drainQueues (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:148:10)
    at Immediate.Async.drainQueues (C:\Users\john\AppData\Roaming\npm\node_modules\hexo\node_modules\bluebird\js\release\async.js:17:14)
    at runCallback (timers.js:570:20)
    at tryOnImmediate (timers.js:550:5)
    at processImmediate [as _immediateCallback] (timers.js:529:5)

README.md typos

image

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

This is applicationId, not applicationID. ๐ŸŒš

Add `--update-settings` flag

This option would help automate:

  • the definition of searchable attributes
  • the highlighting pattern
  • the facetted terms
  • eventually the attributes to snippet (like content)

It has to be done once, on demand rather than for each content indexing.

Add `--incremental`

By doing the following:

  • gather the latest post.date and post.updated Algolia dates
  • find posts which post.date and post.updated
  • eventually find post ids which are not in Algolia index

Setup index command

hexo algolia setup-index
  1. Warn if settings are already available, prompt to overwrite โ€” bypass if --force flag is passed
  2. Performs an update otherwise

TypeError: client.getApiKey is not a function

When Im trying to run ./node_modules/.bin/hexo algolia I'm getting error TypeError: client.getApiKey is not a function.

I've already exported HEXO_ALGOLIA_INDEXING_KEY and triple checked all my configuration.
Is this a bug or Im just doing something wrong?

If You need full stack dump to check it just let me know ๐Ÿ˜„

Add custom properties to INDEXED_PROPERTIES

Enhancement. The ability to add custom properties to the index.

algolia:
  applicationID: 'ID'
  apiKey: 'Key'
  indexName: 'index'
  properties:
    - featured_image
    - something_else

Not indexing contents in the newest version?

I was using hexo-algolia 0.1.1 and updated it to 1.2.3 just now.

I found that the new data uploaded to Algolia now do not include the posts' contents but only titles and excerpts. However, most of my website's posts do not have excerpts.

Is there any way to work this out? By the way, it would be really great if I can choose what to index.

Thanks!

Question about Plugin state

Hello @borisschapira ๐Ÿ˜ƒ

The subtitle of your repo is An incomplete attempt to plug Algolia in Hexo
What is missing it prior the 0.2.0, or is ths till missing basic features?

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.