Module: CMS

Primary handler for the CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Error class for the CMS that adds HTTP status codes

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Configuration handler for the CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Handler for single files in the CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Handler for collection of files for CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Log handler for CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Template object for CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Template engine for CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean

Utilities for the CMS

Author:
  • Charlie Powell
License:
  • The MIT License (MIT)
Source:
See:

Classes

AttributeBuilder
Config
ConfigType
ConfigTypeLayout
CMS
CMSError
File
FileCollection
Log

Members

(inner, constant) FADE_IN_MS :number

Time (in ms) for the new content to fade in after content is swapped.

Type:
  • number
Source:

Methods

(static) basename(path, without_extensionopt) → {string}

Get the basename of a given file, optionally without the extension

Parameters:
Name Type Attributes Default Description
path string
without_extension boolean <optional>
false
Source:
Returns:
Type
string

(static) dirname(path) → {string}

Get the directory name of the requested file

Parameters:
Name Type Description
path string
Source:
Returns:
Type
string

(async, static) fetchLayout(layout, data) → {Promise.<string>}

Fetch the layout and return in the resolve

Parameters:
Name Type Description
layout string

Filename of layout.

data object

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) getDatetime(dateStr) → {Date}

Formats date string to a Date object converted to the user's local timezone

Accepts dashes or slashes between characters, (to support YYYY/MM/DD URL directories)

Parameters:
Name Type Description
dateStr string | Date

Date string to convert

Source:
Returns:

Rendered Date object

Type
Date

(async, static) loadTemplate(url, data) → {Promise.<string>}

Load template from URL.

Parameters:
Name Type Description
url string

URL of template to load.

data object

Data to load into template.

Source:
Throws:
CMSError
Returns:
Type
Promise.<string>

(static) pathJoin(args) → {string}

Function to join paths while ensuring each is separated by a slash

Parameters:
Name Type Description
args string
Source:
Returns:
Type
string
Example
pathJoin('posts', 'topic');
// Returns 'posts/topic'

pathJoin('posts', 'topic', 'README.md');
// Returns 'posts/topic/README.md'

(static) renderError(error) → {Promise}

Render an error to the browser

Parameters:
Name Type Description
error CMSError
Source:
Returns:
Type
Promise

(async, static) renderLayout(layout, data) → {Promise}

Renders the layout into the main container.

When the container already holds content (typically the static, server-side rendered version) the existing content is dimmed while the new content is being fetched and then swapped in, after which the new content fades back to full opacity. This avoids the abrupt flash that a same-frame content replacement would otherwise produce on first page load and on every in-app navigation.

The transition is skipped when the container is empty or when the user has requested reduced motion.

Parameters:
Name Type Description
layout string

Filename of layout.

data TemplateObject

Data passed to template.

Source:
Throws:
CMSError
Returns:
Type
Promise

(static) rtrim(str, copt, invertopt)

Remove trailing 'c's. Equivalent to str.replace(/c*$/, ''). /c*$/ is vulnerable to REDOS.

Parameters:
Name Type Attributes Default Description
str string
c string <optional>
' '
invert boolean <optional>
false

Remove suffix of non-c chars instead. Default falsey.

Source:
See:
  • marked/src/helpers.js

(static) setLoadingContainer(container)

Set the loading container

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemContainer(container)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
container HTMLElement
Source:

(static) setSystemLayoutPath(args)

Set the system layout directory (generally only called from the CMS)

Parameters:
Name Type Description
args string
Source:

(static) smartSort(listOfObjects, sort)

Sort a list of objects by a given key

Handles string and number based keys, performs the sort in place.

If the key ends with '-r', it will be sorted in reverse order.

Parameters:
Name Type Description
listOfObjects Array.<Object>
sort string
Source:

(inner) minimumDelay(ms) → {Promise}

Promise that resolves after at least the given number of milliseconds has elapsed.

Parameters:
Name Type Description
ms number
Source:
Returns:
Type
Promise

(inner) prefersReducedMotion() → {boolean}

Whether the current user has requested reduced motion.

Source:
Returns:
Type
boolean