Icarus User Guide - Search Plugin
This article covers search plugin configurations supported by Icarus.
Visitors open the search box by clicking the search button on the navigation bar. Except for Baidu Search, the search box can also be opened with the keyboard and closed with Esc. See Keyboard Shortcuts for details.
Algolia
Install the hexo-algolia plugin under the root directory of your Hexo site.
Register and log into Algolia. Click the “Create Index” button on the dashboard when you log in for the first time. Then, enter the name of the index and click the “Create” button to complete index creation.
Next, click “API Keys” on the left navigation bar, copy “Application ID” and “Search-Only API Key” on the page. Open site configuration file
_config.ymlunder the root directory of your Hexo site and fill in the above information to the hexo-algolia plugin configurations.
For example, the following Algolia index information:
Algolia Index Information 1
2
3Algolia Index Name: My-Hexo-Site
Application ID: ABCDEFGHIJKL
Search-Only API Key: 7b08fca7d42412cee901a25643124221maps to the following plugin configuration:
_config.yml 1
2
3
4algolia:
applicationID: ABCDEFGHIJKL
indexName: My-Hexo-Site
apiKey: 7b08fca7d42412cee901a25643124221Go back to the “API Keys” page from the Algolia dashboard and switch to the “All API Keys” tab. Click the “New API Key” button. On the popup “Create API Key” dialog, select the index you created in step 2 in the “Indices” select box. Then, add
addObject,deleteObject,listIndexes,deleteIndexto the “ACL” field. Click the “Create” button to finish key creation. Copy the API key you just created, e.g.,727fbd8c998fe419318fa350db6793ca.
Open a Windows Command Prompt (CMD) or Linux/macOS terminal and change the working directory to the root directory of your Hexo site. Set the
HEXO_ALGOLIA_INDEXING_KEYenvironment variable to the API key you created in the last step. This variable is used by hexo-algolia when uploading indices to Algolia.On Windows:
Windows Command Prompt (CMD) 1
2C:\Users\you> cd path/to/your/hexo/site
C:\Users\you> set HEXO_ALGOLIA_INDEXING_KEY=727fbd8c998fe419318fa350db6793caOn Linux/macOS:
Linux/macOS Terminal 1
2cd path/to/your/hexo/site
export HEXO_ALGOLIA_INDEXING_KEY="727fbd8c998fe419318fa350db6793ca"Then, run the following commands to clean up your site and upload indices to Algolia:
Windows Command Prompt or Linux/macOS Terminal 1
2hexo clean
hexo algoliaFinally, set the search engine to Algolia in your theme configurations:
_config.icarus.yml 1
2
3search:
type: algolia
excerpt: excerpt # Optional. Defaults to `excerpt`excerptis the name of the attribute of your Algolia records that is shown as the preview text of each search result. Set it if your records keep the text of the posts in another attribute. The search results show the title and the preview text as plain text with the matched words highlighted: since hexo-component-inferno 4.2.0, HTML tags in the preview text are removed, and other HTML in the records is escaped instead of being rendered.
Baidu Search
Installation Guide
Open theme configuration file and set search engine to Baidu:
_config.icarus.yml 1
2search:
type: baiduBaidu Search sends visitors to the Baidu website to search your site, which is limited to the domain in the
urlsetting of your site configuration file_config.yml. Make sureurlis the address of your site. The search box of Baidu Search has no keyboard shortcuts.
Google Custom Search Engine (CSE)
Log into your Google account and visit Google CSE to create a CSE. Type in the URL of your site (without
http://orhttps://) in the “Sites to Search” field. Select the correct language from the “Language” select box. Then, fill in the “Name of the search engine”. Click the “Create” button to finish engine creation.
Then, click the “Get code” button on the right side of “Add it to your site”. Copy the value of
cxto the search settings in your theme’s configurations.
For example, the following HTML code:
Google CSE HTML code 1
2<script async src="https://cse.google.com/cse.js?cx=012345601234560123456:abcdefghijklmn"></script>
<div class="gcse-search"></div>maps to the following theme configuration:
_config.icarus.yml 1
2
3search:
type: google_cse
cx: 012345601234560123456:abcdefghijklmn
Insight
Installation Guide
Insight is the default search engine of this site. You can enable it using the following theme configuration:
_config.icarus.yml 1
2
3search:
type: insight
index_pages: true # Optional. Defaults to `true`. Set to `false` to exclude pages from search results.Insight does not need any external service. When you generate your site, it saves the text of your posts, pages, categories, and tags to a
content.jsonfile, which the search box downloads and searches in the browser. Since hexo-component-inferno 4.2.0, the keywords are matched as plain text instead of regular expressions, and the search results are escaped and shown as plain text. You can also use ↑ and ↓ to select a search result and Enter to open it.
Keyboard Shortcuts
Except for Baidu Search, all search plugins above support the following keyboard shortcuts:
- / opens the search box, unless you are typing in an input field, a text area, or other editable content.
- Ctrl + K (⌘ Command + K on macOS) opens the search box, even when you are typing.
- Esc closes the search box, and the focus returns to where it was before the search box opened.
Focusing the search button on the navigation bar, for example with Tab, does not open the search box. Press Enter or Space on it, or click it, instead. Moving the focus out of the open search box, for example with Tab, closes it.
Icarus User Guide - Search Plugin
https://ppoffice.github.io/hexo-theme-icarus/Plugins/Search/icarus-user-guide-search-plugin/