BajoTemplate

new BajoTemplate()

BajoTemplate class definition.

Members

config

Properties
NameTypeDescription
configobject

Configuration object

Properties
NameTypeAttributesDefaultDescription
layoutobject<optional>
{}

Layout configuration

Properties
NameTypeAttributesDefaultDescription
fallbackboolean<optional>
true

Whether to fallback to default layout if not found

loopDetectorDurNumber | string<optional>
'1m'

Duration for loop detection

logobject<optional>
{}

Logging configuration

Properties
NameTypeAttributesDefaultDescription
resolverboolean<optional>
false

Whether to log resolver actions

cacheobject<optional>
{}

Cache configuration

Properties
NameTypeAttributesDefaultDescription
ttlDurNumber | string<optional>
'1s'

Time-to-live duration for cache

loopDetector

Properties
NameTypeDescription
loopDetectorobject

Loop detection object

Methods

buildCompileImports(locals, req) → {TImportsResult}

Build compile imports. Used to provide utility functions to templates.

Parameters:
NameTypeDescription
localsobject

Locals object

reqobject

Request object

Returns:

Imports object

Type: 
TImportsResult

(async) compile(content, locals, options) → {Promise.<function()>}

Compile a template with the given content and locals.

Parameters:
NameTypeDescription
contentstring

Template content

localsobject

Locals object

optionsobject

Options object

Properties
NameTypeDescription
ttlnumber

Time to live for cache

reqobject

Request object

Returns:

Compiled template function

Type: 
Promise.<function()>

getExcerpt(content, maxWords, trailChars) → {string}

Get an excerpt from the content.

Parameters:
NameTypeDescription
contentstring

Content string

maxWordsnumber

Maximum number of words

trailCharsstring

Trailing characters

Returns:

Excerpt

Type: 
string

getResource(name) → {object}

Get a resource by name.

Parameters:
NameTypeDescription
namestring

Resource name

Returns:

Resource object

Type: 
object

getTruncated(content, maxChars, trailChars) → {string}

Get a truncated version of the content.

Parameters:
NameTypeDescription
contentstring

Content string

maxCharsnumber

Maximum number of characters

trailCharsstring

Trailing characters

Returns:

Truncated content

Type: 
string

(async) parseFrontMatter(input, lang) → {Promise.<object>}

Parse front matter from the input string.

Parameters:
NameTypeDescription
inputstring

Input string

langstring

Language

Returns:

Parsed front matter

Type: 
Promise.<object>

(async) render(tpl, locals, opts) → {Promise.<string>}

Render a template with the given locals and options.

Parameters:
NameTypeDescription
tplstring

Template name

localsobject

Locals object

optsobject

Options object

Returns:

Rendered template

Type: 
Promise.<string>

(async) renderString(content, locals, opts) → {Promise.<string>}

Render a string with the given locals and options.

Parameters:
NameTypeDescription
contentstring

Content string

localsobject

Locals object

optsobject

Options object

Returns:

Rendered content

Type: 
Promise.<string>

resolveLayout(item, opts) → {object}

Resolve a layout by name.

Parameters:
NameTypeDescription
itemstring

Layout name

optsobject

Options object

Returns:

Resolved layout

Type: 
object

resolvePartial(item, opts) → {object}

Resolve a partial by name.

Parameters:
NameTypeDescription
itemstring

Partial name

optsobject

Options object

Returns:

Resolved partial

Type: 
object

resolveResource(type, item, opts, fallbackHandler) → {object}

Resolve a resource by type and name.

Parameters:
NameTypeDescription
typestring

Resource type

itemstring

Resource name

optsobject

Options object

fallbackHandlerfunction

Fallback handler function

Returns:

Resolved resource

Type: 
object

resolveTemplate(item, opts) → {object}

Resolve a template by name.

Parameters:
NameTypeDescription
itemstring

Template name

optsobject

Options object

Returns:

Resolved template

Type: 
object

splitContent(input, readFile) → {object}

Split content into front matter and body.

Parameters:
NameTypeDescription
inputstring

Input string or file path

readFileboolean

Whether to read the file

Returns:

Object containing frontMatter and content

Type: 
object

BajoTemplate

new BajoTemplate()

Constructor

Members

config

Properties
NameTypeDescription
configobject

Configuration object

Properties
NameTypeAttributesDefaultDescription
layoutobject<optional>
{}

Layout configuration

Properties
NameTypeAttributesDefaultDescription
fallbackboolean<optional>
true

Whether to fallback to default layout if not found

loopDetectorDurNumber | string<optional>
'1m'

Duration for loop detection

logobject<optional>
{}

Logging configuration

Properties
NameTypeAttributesDefaultDescription
resolverboolean<optional>
false

Whether to log resolver actions

cacheobject<optional>
{}

Cache configuration

Properties
NameTypeAttributesDefaultDescription
ttlDurNumber | string<optional>
'1s'

Time-to-live duration for cache

loopDetector

Properties
NameTypeDescription
loopDetectorobject

Loop detection object

Methods

buildCompileImports(locals, req) → {TImportsResult}

Build compile imports. Used to provide utility functions to templates.

Parameters:
NameTypeDescription
localsobject

Locals object

reqobject

Request object

Returns:

Imports object

Type: 
TImportsResult

(async) compile(content, locals, options) → {Promise.<function()>}

Compile a template with the given content and locals.

Parameters:
NameTypeDescription
contentstring

Template content

localsobject

Locals object

optionsobject

Options object

Properties
NameTypeDescription
ttlnumber

Time to live for cache

reqobject

Request object

Returns:

Compiled template function

Type: 
Promise.<function()>

getExcerpt(content, maxWords, trailChars) → {string}

Get an excerpt from the content.

Parameters:
NameTypeDescription
contentstring

Content string

maxWordsnumber

Maximum number of words

trailCharsstring

Trailing characters

Returns:

Excerpt

Type: 
string

getResource(name) → {object}

Get a resource by name.

Parameters:
NameTypeDescription
namestring

Resource name

Returns:

Resource object

Type: 
object

getTruncated(content, maxChars, trailChars) → {string}

Get a truncated version of the content.

Parameters:
NameTypeDescription
contentstring

Content string

maxCharsnumber

Maximum number of characters

trailCharsstring

Trailing characters

Returns:

Truncated content

Type: 
string

(async) parseFrontMatter(input, lang) → {Promise.<object>}

Parse front matter from the input string.

Parameters:
NameTypeDescription
inputstring

Input string

langstring

Language

Returns:

Parsed front matter

Type: 
Promise.<object>

(async) render(tpl, locals, opts) → {Promise.<string>}

Render a template with the given locals and options.

Parameters:
NameTypeDescription
tplstring

Template name

localsobject

Locals object

optsobject

Options object

Returns:

Rendered template

Type: 
Promise.<string>

(async) renderString(content, locals, opts) → {Promise.<string>}

Render a string with the given locals and options.

Parameters:
NameTypeDescription
contentstring

Content string

localsobject

Locals object

optsobject

Options object

Returns:

Rendered content

Type: 
Promise.<string>

resolveLayout(item, opts) → {object}

Resolve a layout by name.

Parameters:
NameTypeDescription
itemstring

Layout name

optsobject

Options object

Returns:

Resolved layout

Type: 
object

resolvePartial(item, opts) → {object}

Resolve a partial by name.

Parameters:
NameTypeDescription
itemstring

Partial name

optsobject

Options object

Returns:

Resolved partial

Type: 
object

resolveResource(type, item, opts, fallbackHandler) → {object}

Resolve a resource by type and name.

Parameters:
NameTypeDescription
typestring

Resource type

itemstring

Resource name

optsobject

Options object

fallbackHandlerfunction

Fallback handler function

Returns:

Resolved resource

Type: 
object

resolveTemplate(item, opts) → {object}

Resolve a template by name.

Parameters:
NameTypeDescription
itemstring

Template name

optsobject

Options object

Returns:

Resolved template

Type: 
object

splitContent(input, readFile) → {object}

Split content into front matter and body.

Parameters:
NameTypeDescription
inputstring

Input string or file path

readFileboolean

Whether to read the file

Returns:

Object containing frontMatter and content

Type: 
object