You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
/* globals hexo:false, console:false*/ |
|
'use strict'; |
|
|
|
var fs = require('fs'); |
|
var path = require('path'); |
|
var command = require('./lib/command'); |
|
var searchTagHelper = require('./lib/helpers/search_tag.js'); |
|
var searchConfigHelper = require('./lib/helpers/search_config.js'); |
|
|
|
var KNOWN_ASSETS = [ |
|
'algoliasearchLite.min.js', |
|
'algoliasearchLite.js', |
|
'algoliasearch.min.js', |
|
'algoliasearch.js' |
|
]; |
|
|
|
hexo.extend.console.register( |
|
'algolia', |
|
'Index your content in Algolia Search API', |
|
{ |
|
options: [ |
|
{ |
|
name: '--dry-run', |
|
desc: 'Does not push content to Algolia (default: false).' |
|
}, |
|
{ |
|
name: '--flush', |
|
desc: 'Resets the Algolia index before starting the indexation (default: false).' |
|
}, |
|
{ |
|
name: '--layouts', |
|
desc: 'A comma-separated list of page layouts to index (default: "page").', |
|
}, |
|
{ |
|
name: '--indexing-key', |
|
desc: 'An algolia API key with add/delete records permissions.\n\t\t It should be different than the search-only API key configured in _config.yml.', |
|
} |
|
] |
|
}, |
|
command |
|
); |
|
|
|
hexo.extend.helper.register( |
|
'algolia_search_cdn', |
|
searchTagHelper.fromCDN.bind(null, hexo) |
|
); |
|
hexo.extend.helper.register( |
|
'algolia_search', |
|
searchTagHelper.fromNpmPackage.bind(null, hexo) |
|
); |
|
hexo.extend.helper.register( |
|
'algolia_search_config', |
|
searchConfigHelper(hexo.config) |
|
); |
|
|
|
hexo.extend.generator.register('algolia', function() { |
|
return KNOWN_ASSETS.map(function(assetFile) { |
|
var sourceFile = require.resolve('algoliasearch/dist/' + assetFile); |
|
|
|
return { |
|
path: path.join('assets', 'algolia', assetFile), |
|
data: function() { |
|
return fs.createReadStream(sourceFile); |
|
} |
|
}; |
|
}); |
|
});
|
|
|