Class: File

CMS~File(url, type, layout, config)

Represents a Markdown file installed in one of the collection directories

Constructor

new File(url, type, layout, config)

Parameters:
Name Type Description
url string

The URL of the file

type string

The type of file (i.e. posts, pages)

layout string

The layout templates of the file

config Config

Configuration from the CMS

Source:

Members

ProtectedAttributes :Array.<string>

Set of keys which cannot be set from the FrontMatter content These generally have a built-in or reserved purpose

Type:
  • Array.<string>
Source:

author :string|null

Author name - pulled from FrontMatter

Type:
  • string | null
Source:

Banner alt/label and URL for this page, useful for pretty headers on pages

Type:
  • Object | null
Source:

body :string

Rendered HTML body for this File

Type:
  • string
Source:

bodyLoaded :boolean

Set to true when the HTML body has been parsed (performance tracker)

Type:
  • boolean
Source:

config :Config

System configuration

Type:
  • Config
Source:

content :string

Raw Markdown contents of this File

Type:
  • string
Source:

date :string|null

Date published - pulled from FrontMatter or URL Will be converted into the requested format from Config.dateParser

Type:
  • string | null
Source:
See:
  • Config#dateParser for rendering info

datetime :Date|null

Date object holding the date published - pulled from Last-Modified header if date is not set otherwise

Type:
  • Date | null
Source:

draft :boolean

Set to TRUE to flag this File as draft (and not rendered to the site)

Type:
  • boolean
Source:

excerpt :string|null

Short excerpt or teaser about the page, useful on listing pages

Type:
  • string | null
Source:

image :Object|null

Image alt/label and URL for this page

Type:
  • Object | null
Source:

layout :string

Default layout for rendering this file

Type:
  • string
Source:

name :string

Base filename of this File (without the extension)

Type:
  • string
Source:

Browseable link to this File (includes .html)

Type:
  • string
Source:

seotitle :string|null

Window title / SEO title for this page, useful for differing from page title

Type:
  • string | null
Source:

tags :Array.<string>|null

List of tags associated with this page

Type:
  • Array.<string> | null
Source:

timestamp :null|int

Timestamp of the last modification, as pulled from Meta loader (when available)

Type:
  • null | int
Source:

title :string|null

Title for this page, generally rendered as an H1

Type:
  • string | null
Source:

type :string

Collection type this file resides under

Type:
  • string
Source:

url :string

Path to the raw Markdown source file

Type:
  • string
Source:

Methods

_parseFrontMatterKey(value) → {Object|Array|string|boolean|null|number}

Parse a FrontMatter value for special functionality

Parameters:
Name Type Description
value Object | Array | string | boolean | null | number
Source:
Returns:
Type
Object | Array | string | boolean | null | number

getMeta(lookup)

Get a specific meta field from this file

Parameters:
Name Type Description
lookup string

Key to retrieve, or period-separated lookup for nested values

Source:

getTags(sort) → {Object}

Get all tags located in this file

Each set will contain the properties name, count, url, and weight.

Parameters:
Name Type Default Description
sort null | string null

Key ['name', 'count', 'url'] to sort results

Source:
Returns:

{{name: string, count: number, url: string, weight: int}[]}

Type
Object

(async) loadContent() → {Promise.<string>}

Load file content from the server

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

matchesAttributeSearch(query, modeopt) → {boolean}

Perform an attribute search on this file to see if its metadata matches the query

Parameters:
Name Type Attributes Default Description
query Object

Dictionary containing key/values to search

mode string <optional>
AND

"OR" or "AND" if we should check all keys or any of them

Source:
Returns:
Type
boolean
Example
// Match if this file is authored by Alice
file.matchesAttributeSearch({author: 'Alice'});

// Match if this file is authored by Alice or Bob
file.matchesAttributeSearch({author: ['Alice', 'Bob']});

// Match if this file is authored by Alice or Bob AND has the tag Configuration
file.matchesAttributeSearch({author: ['Alice', 'Bob'], tags: 'Configuration'});

// Match if this file is authored by Bob OR has the tag HR
file.matchesAttributeSearch({author: 'Bob', tags: 'HR'}, 'OR');

matchesSearch(query) → {boolean}

Perform a text search on this file to see if the content contains a given search query

Parameters:
Name Type Description
query string

Query to check if this file matches against

Source:
Returns:
Type
boolean

(async) parseBody()

Parse file body from the markdown content

Source:

parseContent()

Parse file content

Sets all file attributes and content.

Source:

parseDate()

Parse file date from either the FrontMatter or server Last-Modified header

Source:

parseFilename()

Parse filename from the URL of this file and sets to name

Source:

parseFrontMatter()

Parse front matter, the content in the header of the file.

Will scan through and retrieve any key:value pair within --- tags at the beginning of the file.

These values get set directly on the File object for use within templates or system use.

Source:

parseFrontMatterData(data)

Parse the actual metadata located from the frontmatter

Parameters:
Name Type Description
data object
Source:

Parse permalink from the URL of this file and sets to permalink

Source:

(async) render() → {Promise}

Renders file with a configured layout

Source:
Throws:
Error
Returns:
Type
Promise