Constructor
new FileCollection(type, layout, config)
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | The type of file collection (i.e. posts, pages). |
layout |
ConfigTypeLayout | The layouts of the file collection type. |
config |
Config | Configuration from the CMS |
- Source:
Members
[undefined] :Array.<File>
Filtered and sorted list of files matched
Populates the dynamic property based on the type of file
Type:
- Array.<File>
- Source:
allFiles :Array.<File>
All raw files available in this collection
Type:
- Array.<File>
- Source:
currentPage :null|number
Type:
- null | number
- Source:
directories :Array.<string>
List of directories to scan when server-side is not available
Type:
- Array.<string>
- Source:
filteredFiles :Array.<File>
Filtered list of files available in this collection
This gets updated as filters are applied, but DOES NOT get updated with pagination!
Type:
- Array.<File>
- Source:
layout :ConfigTypeLayout
Layout to use for rendering this collection
Type:
- ConfigTypeLayout
- Source:
resultsPerPage :null|number
Type:
- null | number
- Source:
totalPages :null|number
Type:
- null | number
- Source:
totalResults :null|number
Type:
- null | number
- Source:
type :string
Type of files, as defined by the configuration.
Usually something like "pages" or "posts"
Type:
- string
- Source:
Methods
_getTags(sortopt, weightMaxopt, allopt) → {Object}
Get all tags located from this collection
Each set will contain the properties name, count, url, and weight.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sort |
string | null |
<optional> |
null | Key ['name', 'count', 'url'] to sort results |
weightMax |
number |
<optional> |
10 | Max weight |
all |
boolean |
<optional> |
false | If true, get all tags, otherwise only get tags of currently filtered files |
- Source:
Returns:
{{name: string, count: number, url: string, weight: int}[]}
- Type
- Object
clone() → {FileCollection}
Clone the file collection
- Source:
Returns:
- Type
- FileCollection
filterAttributeSearch(search, modeopt) → {Array.<File>}
Search file collection by arbitrary attributes
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
search |
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:
- See:
-
- module:CMS~File#matchesAttributeSearch for full documentation of usage
Returns:
Set of filtered files
- Type
- Array.<File>
filterPermalink(url) → {Array.<File>}
Filter results by a URL regex (Convenience method)
Parameters:
| Name | Type | Description |
|---|---|---|
url |
string | URL fragment/regex to filter against |
- Source:
- See:
-
- filterAttributeSearch
Returns:
Set of filtered files
- Type
- Array.<File>
(async) filterSearch(search) → {Promise.<Array.<File>>}
Search file collection by attribute.
Filters the collection to files matching the query and keeps
filteredFiles in sync with the visible this[type] set so that
pagination operates on the actual search results. When server results
are available they are ranked by relevance; the local fallback matches
against the in-memory content.
Parameters:
| Name | Type | Description |
|---|---|---|
search |
string | Search query. |
- Source:
Returns:
Set of filtered files
- Type
- Promise.<Array.<File>>
filterSort(paramopt)
Sort results by a given parameter
If a function is requested, that is used to sort the results. If a string is requested, only specific keywords are supported. Use -r to inverse results. If NULL is requested, the default sort for this collection type is used.
Common sort parameters:
- title - Sort by page title
- random - Sort randomly
- recent - Sort by most recent
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
param |
function | string | null |
<optional> |
null | A function, string, or empty value to sort by |
- Source:
filterTag(query) → {Array.<File>}
Filter content to display by a tag (Convenience method)
Simple usage is to pass a single tag name to filter by. If a comma-separated string is provided, ALL tags in the string are matched. If a pipe-separated string is provided, ANY tag in the string is matched.
Parameters:
| Name | Type | Description |
|---|---|---|
query |
string | Array.<string> | Search query. |
- Source:
- See:
-
- filterAttributeSearch
Returns:
Set of filtered files
- Type
- Array.<File>
getFileByPermalink(permalink) → {File}
Get file by permalink.
Parameters:
| Name | Type | Description |
|---|---|---|
permalink |
string | Permalink to search. |
- Source:
Throws:
Returns:
File object.
- Type
- File
getFileElements(data) → {Array.<string>}
Get list of file elements from either the returned listing page scan (or JSON data for GITHUB)
Parameters:
| Name | Type | Description |
|---|---|---|
data |
string | HTML code from directory listing |
- Source:
Returns:
URLs of files and directories located
- Type
- Array.<string>
getFileListUrl() → {string}
Get file list URL
- Source:
Returns:
URL of file list
- Type
- string
(async) getFiles() → {Promise}
Get files from file listing and set to file collection.
- Source:
Returns:
- Type
- Promise
(async) getFilesByServer() → {Promise}
Get files from file listing and set to file collection.
- Source:
Returns:
- Type
- Promise
getFilteredTags(sortopt, weightMaxopt) → {Object}
Get tags of only currently filtered files located from this collection
Each set will contain the properties name, count, url, and weight.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sort |
string | null |
<optional> |
null | Key ['name', 'count', 'url'] to sort results |
weightMax |
number |
<optional> |
10 | Max weight |
- Source:
Returns:
{{name: string, count: number, url: string, weight: int}[]}
- Type
- Object
getNextPageUrl() → {string}
Get the URL for the next page (when pagination is enabled)
- Source:
Returns:
- Type
- string
getPageTagUrl(tag) → {string}
Get the URL for the requested tag
If the tag is already present, it will remove it. If the tag is not present, it will add it. If other tags are present, an AND is used to combine them
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string |
- Source:
Returns:
- Type
- string
getPageUrl(page) → {string}
Get the URL for the requested page (when pagination is enabled)
Parameters:
| Name | Type | Description |
|---|---|---|
page |
number |
- Source:
Returns:
- Type
- string
getPreviousPageUrl() → {string}
Get the URL for the previous page (when pagination is enabled)
- Source:
Returns:
- Type
- string
getSearchParams() → {URLSearchParams}
Get the search parameters for this FileCollection based on the current filters and pagination.
- Source:
Returns:
- Type
- URLSearchParams
getTags(sortopt, weightMaxopt) → {Object}
Get all tags located from this collection
Each set will contain the properties name, count, url, and weight.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
sort |
string | null |
<optional> |
null | Key ['name', 'count', 'url'] to sort results |
weightMax |
number |
<optional> |
10 | Max weight |
- Source:
Returns:
{{name: string, count: number, url: string, weight: int}[]}
- Type
- Object
hasFilterTag(tag) → {boolean}
Check if the given tag is currently filtered
Parameters:
| Name | Type | Description |
|---|---|---|
tag |
string |
- Source:
Returns:
- Type
- boolean
(async) init() → {Promise}
Initialize file collection
- Source:
Returns:
- Type
- Promise
(async) loadFiles() → {Promise}
Load files and get file content.
- Source:
Returns:
- Type
- Promise
paginate(results, page)
Set pagination (total number of results) for this collection
Parameters:
| Name | Type | Description |
|---|---|---|
results |
number | Total number of results per page |
page |
number | Current page number (1-based) or NULL to retrieve from URL |
- Source:
(async) render() → {Promise}
Renders file collection.
- Source:
Throws:
Returns:
- Type
- Promise
resetFilters()
Reset filters and sorting
- Source:
(async) scanDirectory(directory) → {Promise.<Array.<string>>}
Perform the underlying directory lookup
Parameters:
| Name | Type | Description |
|---|---|---|
directory |
string | Directory URL to scan |
- Source:
Returns:
Array of subdirectories found
- Type
- Promise.<Array.<string>>