Module: utils

Members

(inner, constant) default404 :String

Hikaru's default 404 page content for server.

Type:
  • String
Source:

Methods

(inner) delSite(site, key, file)

Delete file from an array in site, which have the same input path.

Parameters:
Name Type Description
site Site
key String
file File
Source:

(inner) escapeHTML(str) → {String}

Escape HTML chars.

Parameters:
Name Type Description
str String
Source:
Returns:

Escaped HTML string.

Type
String

(inner) genCategories(posts) → {CategoriesData}

Generate categories from posts.

Parameters:
Name Type Description
posts Array.<File>
Source:
Returns:
Type
CategoriesData

(inner) genTags(posts) → {TagsData}

Generate tags from posts.

Parameters:
Name Type Description
posts Array.<File>
Source:
Returns:
Type
TagsData

(inner) genTOC($)

Generate TOC from HTML headers.

Parameters:
Name Type Description
$ Object

Cheerio context.

Source:

(inner) getContentType(docPath) → {String}

Detect Content-Type via filename.

Parameters:
Name Type Description
docPath String
Source:
Returns:

Content-Type value.

Type
String

(inner) getFrontMatter(str) → {FrontMatter}

Get front-matter from string, front-matter here is defined at the head of string (so don't use UTF-8 BOM), begins with one line that contains only ---, and write properties in YAML after this line, then also ends with such a line.

Parameters:
Name Type Description
str String
Source:
Returns:
Type
FrontMatter

(inner) getPathFn(rootDiropt) → {getPath}

Get a function to handle full website path.

Parameters:
Name Type Attributes Description
rootDir String <optional>

Site rootDir.

Source:
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.

Source:
Returns:
Type
getURL

(inner) getURLProtocol(url) → {String}

Get protocol of a URL.

Parameters:
Name Type Description
url String
Source:
Returns:

If no protocol return null.

Type
String

(inner) getVersion() → {String}

Get Hikaru version.

Source:
Returns:
Type
String

(inner) isArray(o) → {Boolean}

Parameters:
Name Type Description
o *
Source:
Returns:
Type
Boolean

(inner) isBinary(b) → {Boolean}

Parameters:
Name Type Description
b Buffer
Source:
Returns:
Type
Boolean

(inner) isBuffer(o) → {Boolean}

Parameters:
Name Type Description
o *
Source:
Returns:
Type
Boolean

(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.

Source:
Returns:
Type
isCurrentPath

(inner) isFunction(o) → {Boolean}

Parameters:
Name Type Description
o *
Source:
Returns:
Type
Boolean

(inner) isObject(o) → {Boolean}

Parameters:
Name Type Description
o *
Source:
Returns:

Return false when o == null.

Type
Boolean

(inner) isString(o) → {Boolean}

Parameters:
Name Type Description
o *
Source:
Returns:
Type
Boolean

(inner) matchFiles(pattern, optsopt) → {Promise.<Array.<String>>}

A Promised glob.

Parameters:
Name Type Attributes Description
pattern String
opts Objects <optional>

Optional glob opts.

Source:
Returns:
Type
Promise.<Array.<String>>

(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.

Source:
Returns:

Paginated pages, original page's index is 0.

Type
Array.<File>

(inner) paginateCategories(category, parentPath, site, perPageopt) → {Array.<File>}

Generate and paginate pages for category and its subs.

Parameters:
Name Type Attributes Default Description
category Category
parentPath String

Parent category's dir, into which sub categories need to be put.

site Site
perPage Number <optional>
10

How many posts per page.

Source:
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
Source:
Returns:
Type
File

(inner) putSite(site, key, file)

Put file into an array in site, will replace file with the same output path.

Parameters:
Name Type Description
site Site
key String
file File
Source:

(inner) removeControlChars(str) → {String}

Remove XML control chars.

Parameters:
Name Type Description
str String
Source:
Returns:

XML string.

Type
String

(inner) resolveHeaderIDs($)

Update headers' ID for bootstrap scrollspy.

Parameters:
Name Type Description
$ Object

Cheerio context.

Source:

(inner) resolveImage($, rootDiropt, docPathopt)

Update site's internal image src to absolute path.

Parameters:
Name Type Attributes Description
$ Object

Cheerio context.

rootDir String <optional>

Site rootDir.

docPath String <optional>
Source:

Update site's internal link to absolute path, and add attributes for external link.

Parameters:
Name Type Attributes Description
$ Object

Cheerio context.

baseURL String <optional>

Site baseURL.

rootDir String <optional>

Site rootDir.

docPath String <optional>
Source:

(inner) sortCategories(category)

Sort categories and their posts recursively.

Parameters:
Name Type Description
category Category
Source:

Type Definitions

CategoriesData

Type:
  • Object
Properties:
Name Type Description
categories Array.<Category>
categoriesLength Number
Source:

FrontMatter

Type:
  • Object
Properties:
Name Type Description
attributes Object

Parsed front-matter properties.

body String

String after front-matter.

frontMatter String

Front-matter string.

Source:

getPath(docPathopt) → {String}

Parameters:
Name Type Attributes Description
docPath String <optional>
Source:
Returns:

Encoded URI path for web link.

Type
String

getURL(docPathopt) → {URL}

Parameters:
Name Type Attributes Description
docPath String <optional>
Source:
Returns:

Full website URL.

Type
URL

isCurrentPath(testPathopt, strictopt) → {Boolean}

This function does not care query string and hash.

Parameters:
Name Type Attributes Default Description
testPath String <optional>

Path needed to test.

strict Boolean <optional>
false

If false, sub dir will return true.

Source:
Returns:
Type
Boolean

TagsData

Type:
  • Object
Properties:
Name Type Description
tags Array.<Category>
tagsLength Number
Source: