-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1816b80
commit d8ce45e
Showing
9 changed files
with
149 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,46 @@ | ||
const log = require('hexo-log')({ debug: false, silent: false }); | ||
const { magenta } = require('chalk'); | ||
const path = require('path'); | ||
const fs = require("hexo-fs"); | ||
const handlebars = require("handlebars"); | ||
|
||
const _rootDir = hexo.source_dir.replace("source", ""); | ||
|
||
hexo.extend.generator.register("dynamic-search", async function(locals) { | ||
log.info("Generating Dynamic Page " + magenta("SEARCH") + " ..."); | ||
|
||
const config = this.config; | ||
|
||
let result = []; | ||
|
||
// Page | ||
let page = locals.dynamic.search; | ||
page.urlparam = config.search.url_parameter; | ||
|
||
return { | ||
result.push({ | ||
data: page, | ||
path: path.join(page.name, "index.html"), | ||
layout: "search" | ||
}; | ||
}); | ||
|
||
// opensearch.xml | ||
const osTemplate = path.join(_rootDir, config.template_dir, config.search.opensearch_template); | ||
if (!fs.existsSync(osTemplate)) { throw "OpenSearch Template file not found"; } | ||
|
||
const osSource = fs.readFileSync(osTemplate).toString('utf8'); | ||
const os = handlebars.compile(osSource); | ||
const osResult = os({ | ||
shortname: config.title, | ||
faviconUrl: config.url + "/" + config.favicon, | ||
searchUrl: config.url + "/" + config.search.path, | ||
searchParameter: config.search.url_parameter | ||
}); | ||
|
||
result.push({ | ||
path: config.search.opensearch_path, | ||
data: osResult | ||
}); | ||
|
||
|
||
return result; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> | ||
<ShortName>{{shortname}}</ShortName> | ||
<Description>Search {{shortname}}</Description> | ||
<InputEncoding>UTF-8</InputEncoding> | ||
<Image width="16" height="16" type="image/x-icon">{{faviconUrl}}</Image> | ||
<Url type="text/html" method="get" template="{{searchUrl}}?{{searchParameter}}={searchTerms}&ref=opensearch"/> | ||
<moz:SearchForm>{{searchUrl}}</moz:SearchForm> | ||
</OpenSearchDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters