Members
(inner, constant) default404 :String
Hikaru's default 404 page content for server.
Type:
- String
(inner, constant) hikaruDir
Hikaru's package dir.
(inner, constant) isBinaryFileSync
You should use isBinaryPath(p)
mostly. This is only for
compatibility because isbinaryfile
dependency is dropped.
(inner, constant) resolveHeaderIDs
Use resolveHeadingIDs(node)
instead.
Methods
(inner) checkType(var, name, …types)
Check whether a variable is one of give types.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
var |
* | ||
name |
String | Variable name. |
|
types |
String |
<repeatable> |
(inner) delSite(site, key, file)
Delete file from an array in site which have the same source.
Parameters:
Name | Type | Description |
---|---|---|
site |
Site | |
key |
String | |
file |
File |
(inner) escapeHTML(str) → {String}
Escape HTML chars.
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Returns:
Escaped HTML string.
- Type
- String
(inner) fallbackSort(arr, …fns)
Sort an array with a fallback list, call comparing function from first to last until there is a difference.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
arr |
Array | ||
fns |
compareCallback |
<repeatable> |
(inner) formatDateTimeFn(locales) → {formatDateTime}
Get a function to format date and time, with locale support if
Intl
is available.
Parameters:
Name | Type | Description |
---|---|---|
locales |
String |
- Source:
- See:
Returns:
- Type
- formatDateTime
(inner) formatDateTimeSimple(dtopt) → {String}
Format date and time to YYYY-MM-DD HH:mm:ss
.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dt |
* |
<optional> |
new Date() |
Returns:
- Type
- String
(inner) genCategories(posts) → {CategoriesData}
Generate categories from posts.
Parameters:
Name | Type | Description |
---|---|---|
posts |
Array.<File> |
Returns:
- Type
- CategoriesData
(inner) genTOC(node, optsopt)
Generate TOC from HTML headings.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
Object | parse5 Node. |
|
opts |
Object |
<optional> |
(inner) genTags(posts) → {TagsData}
Generate tags from posts.
Parameters:
Name | Type | Description |
---|---|---|
posts |
Array.<File> |
Returns:
- Type
- TagsData
(inner) getContentType(docPath) → {String}
Detect Content-Type via filename.
Parameters:
Name | Type | Description |
---|---|---|
docPath |
String |
Returns:
Content-Type value.
- Type
- String
(inner) getFrontMatter(str) → {FrontMatter}
Get front-matter from string, front-matter here should be at the
beginning of string (so UTF-8 BOM is not supported), and should begin with
---
in the first line, and should have valid YAML in lines after that, and
should end with ---
in the next line.
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Returns:
- Type
- FrontMatter
(inner) getFullDocPath(file) → {String}
Get File's full document path.
Parameters:
Name | Type | Description |
---|---|---|
file |
File |
Returns:
- Type
- String
(inner) getFullSrcPath(file) → {String}
Get File's full src path.
Parameters:
Name | Type | Description |
---|---|---|
file |
File |
Returns:
- Type
- String
(inner) getNodeAttr(node, attrName) → {String}
Get an attribute value from parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |
attrName |
String |
- Source:
- See:
Returns:
Value of the attribute, null
if not available.
- Type
- String
(inner) getNodeText(node) → {String}
Get text content of a parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |
- Source:
- See:
Returns:
- Type
- String
(inner) getPathFn(rootDiropt) → {getPath}
Get a function to handle full website path.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rootDir |
String |
<optional> |
Site rootDir. |
Returns:
- Type
- getPath
(inner) getURLFn(baseURLopt, rootDiropt) → {getURL}
Get a function to handle full website URL.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
baseURL |
String |
<optional> |
Site baseURL. |
rootDir |
String |
<optional> |
Site rootDir. |
Returns:
- Type
- getURL
(inner) getURLProtocol(url) → {String}
Get protocol of a URL.
Parameters:
Name | Type | Description |
---|---|---|
url |
String |
Returns:
If no protocol return null
.
- Type
- String
(inner) getVersion() → {String}
Get Hikaru version.
Returns:
- Type
- String
(inner) isArray(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
- Type
- Boolean
(inner) isBinary(b) → {Boolean}
Check whether a buffer is a binary. You should use
isBinaryPath(p)
because this is costly and mostly a false positive is
harmless so we don't need an exact check. For non-costly exact check, add
isbinaryfile
dependency for your project.
Parameters:
Name | Type | Description |
---|---|---|
b |
Buffer |
Returns:
- Type
- Boolean
(inner) isBinaryFile(o) → {Boolean}
You should use isBinaryPath(p)
mostly. This is only for
compatibility because isbinaryfile
dependency is dropped.
Parameters:
Name | Type | Description |
---|---|---|
o |
String | Buffer |
Returns:
- Type
- Boolean
(inner) isBinaryPath(p) → {Boolean}
Check whether a path is a binary via ext name. For non-costly
exact check, add isbinaryfile
dependency for your project.
Parameters:
Name | Type | Description |
---|---|---|
p |
String |
Returns:
- Type
- Boolean
(inner) isBuffer(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
- Type
- Boolean
(inner) isCurrentHostFn(baseURL, rootDiropt) → {isCurrentHost}
Get a function to handle if parameter is on current host.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
baseURL |
String | Site baseURL. |
|
rootDir |
String |
<optional> |
Site rootDir. |
Returns:
- Type
- isCurrentHost
(inner) isCurrentPathFn(rootDiropt, currentPathopt) → {isCurrentPath}
Get a function to handle if parameter is current path.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
rootDir |
String |
<optional> |
Site rootDir. |
currentPath |
String |
<optional> |
current page's path. |
Returns:
- Type
- isCurrentPath
(inner) isFunction(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
- Type
- Boolean
(inner) isNumber(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
- Type
- Boolean
(inner) isObject(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
Return false
when o == null
.
- Type
- Boolean
(inner) isReadableSync(p) → {Boolean}
Node.js marks fs.exists()
deprecated and suggest to use
fs.access()
, but it throws error instead of return a boolean, this is a
wrapper for it.
Parameters:
Name | Type | Description |
---|---|---|
p |
String |
Returns:
- Type
- Boolean
(inner) isString(o) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
o |
* |
Returns:
- Type
- Boolean
(async, inner) loadJSON(path) → {Promise.<Object>}
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
Returns:
- Type
- Promise.<Object>
(inner) loadJSONSync(path) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
Returns:
- Type
- Object
(async, inner) loadYAML(path) → {Promise.<Object>}
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
Returns:
- Type
- Promise.<Object>
(inner) loadYAMLSync(path) → {Object}
Parameters:
Name | Type | Description |
---|---|---|
path |
String |
Returns:
- Type
- Object
(inner) localeCompareFn(locales) → {localCompare}
Get a function to compare strings, with locale support if Intl
is available.
Parameters:
Name | Type | Description |
---|---|---|
locales |
String |
- Source:
- See:
Returns:
- Type
- localCompare
(inner) localeCompareSimple(a, b) → {Number}
Compare strings.
Parameters:
Name | Type | Description |
---|---|---|
a |
String | |
b |
String |
Returns:
- Type
- Number
(inner) matchFiles(pattern, optsopt) → {Promise.<Array.<String>>}
A Promised glob.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
pattern |
String | |||||||||||||||||||||||||||
opts |
Objects |
<optional> |
Optional match opts. Properties
|
Returns:
- Type
- Promise.<Array.<String>>
(inner) nodesEach(node, callback)
Recursively Pre-Order Traversal of parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | Root parse5 Node of a tree. |
callback |
traversalCallback |
- Source:
- See:
(inner) nodesFilter(node, callback) → {Array.<Object>}
Recursively Pre-Order Traversal of parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | Root parse5 Node of a tree. |
callback |
filterCallback |
- Source:
- See:
Returns:
An Array of filtered parse5 Nodes.
- Type
- Array.<Object>
(inner) paginate(p, posts, perPageopt) → {Array.<File>}
Paginate page's posts.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
p |
File | Original page. |
||
posts |
Array.<File> | Page related posts. |
||
perPage |
Number |
<optional> |
10 | How many posts per page. |
Returns:
Paginated pages, original page's index is 0.
- Type
- Array.<File>
(inner) paginateCategoriesPosts(categories, parentPath, docDir, perPageopt) → {Array.<File>}
Generate pages and paginate posts of categories.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
categories |
Array.<Category> | |||
parentPath |
String | Parent category's dir. |
||
docDir |
docDir | |||
perPage |
Number |
<optional> |
10 | How many posts per page. |
Returns:
All category and it's subs pages.
- Type
- Array.<File>
(inner) parseFrontMatter(file) → {File}
Parse front-matter and set properties to file.
Parameters:
Name | Type | Description |
---|---|---|
file |
File |
Returns:
- Type
- File
(inner) parseNode(nodeopt, html, optionsopt) → {Object}
Parse HTML string into parse5 Node.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
Object |
<optional> |
If specified, given fragment will be parsed as it was
set to the context element's |
html |
String | HTML string to parse. |
|
options |
Object |
<optional> |
parse5 options. |
- Source:
- See:
Returns:
- Type
- Object
(inner) putSite(site, key, file)
Put file into an array in site, will replace file with the same destination.
Parameters:
Name | Type | Description |
---|---|---|
site |
Site | |
key |
String | |
file |
File |
(inner) removeControlChars(str) → {String}
Remove XML control chars.
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Returns:
XML string.
- Type
- String
(inner) removeHTMLTags(str) → {String}
Remove all HTML tags.
Parameters:
Name | Type | Description |
---|---|---|
str |
String |
Returns:
String without HTML tags.
- Type
- String
(inner) replaceNode(node, html)
Quick and not so dirty way to replace a Node with given HTML string.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node to replace. |
html |
String |
(inner) resolveAnchors(node, baseURL, rootDir, docPath, optsopt)
Update site's internal link to absolute path, and add attributes for external link.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
Object | parse5 Node. |
|
baseURL |
String | Site baseURL. |
|
rootDir |
String | Site rootDir. |
|
docPath |
String | ||
opts |
Object |
<optional> |
(inner) resolveCodeBlocks(node, optsopt)
Update code blocks.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
node |
Object | parse5 Node. |
|||||||||||
opts |
Object |
<optional> |
Properties
|
(inner) resolveHeadingIDs(node, optsopt)
Update headings' IDs for bootstrap scrollspy.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
node |
Object | parse5 Node. |
|||||||||||
opts |
Object |
<optional> |
Properties
|
(inner) resolveImages(node, rootDir, docPath, optsopt)
Update site's internal image src to absolute path.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
Object | parse5 Node. |
|
rootDir |
String | Site rootDir. |
|
docPath |
String | ||
opts |
Object |
<optional> |
(inner) serializeNode(node, optionsopt) → {String}
Serialize parse5 Node into HTML string.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
node |
Object | parse5 Node to serialize. |
|
options |
Object |
<optional> |
parse5 options. |
- Source:
- See:
Returns:
- Type
- String
(inner) setNodeAttr(node, attrName, attrValue)
Set an attribute value to parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |
attrName |
String | |
attrValue |
String |
(inner) setNodeText(node, html)
Set text content (or innerHTML) of a parse5 Node.
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |
html |
String |
Type Definitions
CategoriesData
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
categories |
Array.<Category> | |
categoriesLength |
Number |
FrontMatter
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
attributes |
Object | Parsed front-matter properties. |
body |
String | String after front-matter. |
frontMatter |
String | Front-matter string. |
TagsData
Type:
- Object
Properties:
Name | Type | Description |
---|---|---|
tags |
Array.<Tag> | |
tagsLength |
Number |
compareCallback(a, b) → {Number}
Comparing function accepted by Array.sort()
.
Parameters:
Name | Type | Description |
---|---|---|
a |
* | |
b |
* |
Returns:
- Type
- Number
filterCallback(node) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |
Returns:
True to collect a node into an Array.
- Type
- Boolean
formatDateTime(dtopt) → {String}
Format date and time, with locale support if Intl
is
available.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
dt |
* |
<optional> |
new Date() |
Returns:
- Type
- String
getPath(docPathopt, skipEncodeopt) → {String}
Get full website path starts from /
after domain. This
function can only handle site internal path.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
docPath |
String |
<optional> |
||
skipEncode |
Boolean |
<optional> |
false | If true, skip |
Returns:
Full path that starts with site rootDir.
- Type
- String
getURL(docPathopt) → {URL}
Get full website URL including the domain. This function can only handle site internal path.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
docPath |
String |
<optional> |
Returns:
Full website URL.
- Type
- URL
isCurrentHost(testURLopt) → {Boolean}
Test if given URL is on current host. This function does not care about query string and hash.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
testURL |
String |
<optional> |
URL needed to test. |
Returns:
- Type
- Boolean
isCurrentPath(testPathopt, strictopt) → {Boolean}
Test if given path is current path. This function does not care about query string and hash. This function can only handle site internal path.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
testPath |
String |
<optional> |
Path needed to test. |
|
strict |
Boolean |
<optional> |
false | If not strict, true is also returned if given path is parent path of current path. |
Returns:
- Type
- Boolean
localeCompare(a, b) → {Number}
Compare strings, with locale support if Intl
is available.
Parameters:
Name | Type | Description |
---|---|---|
a |
String | |
b |
String |
Returns:
- Type
- Number
traversalCallback(node)
Parameters:
Name | Type | Description |
---|---|---|
node |
Object | parse5 Node. |