- MarkdownPages
- new MarkdownPages(userOptions)
- .init() ⇒
Promise.<module:lokijs> - .middleware(request, response, next) ⇒
Promise.<void> - .getPage(url) ⇒
Promise.<(Page|null)> - .getImage(url) ⇒
Promise.<(Image|null)> - .getPageData(page, [queryParams]) ⇒
Promise.<PageData>
Kind: global class
- MarkdownPages
- new MarkdownPages(userOptions)
- .init() ⇒
Promise.<module:lokijs> - .middleware(request, response, next) ⇒
Promise.<void> - .getPage(url) ⇒
Promise.<(Page|null)> - .getImage(url) ⇒
Promise.<(Image|null)> - .getPageData(page, [queryParams]) ⇒
Promise.<PageData>
Create a new instance of the Markdown pages
| Param | Type | Description |
|---|---|---|
| userOptions | Options |
Client options |
Example
const markdownPages = new MarkDownPages({ source: './docs' });Initialises the database for your app's pages and images. This is not required but enables you to store a reference to the database for use in your app.
Kind: instance method of MarkdownPages
Example
const db = await markdownPages.init();
const pages = db.getCollection('pages');
const homePage = db.by('url', '/');An Express compatible route handler which appends page data to response.locals or serves image files.
Kind: instance method of MarkdownPages
| Param | Type |
|---|---|
| request | module:express~Request |
| response | module:express~Response |
| next | module:express~NextFunction |
Example
app.get('/docs/*', markdownPages.middleware, (req, res) => {});Fetches the content for the page with the given URL.
Kind: instance method of MarkdownPages
| Param | Type |
|---|---|
| url | String |
Example
const aboutPage = markdownPages.getPage('/about-us');Fetches metadata for an image with the given URL.
Kind: instance method of MarkdownPages
| Param | Type |
|---|---|
| url | String |
Example
const dogImage = markdownPages.getImage('/images/dog.jpg');markdownPages.getPageData(page, [queryParams]) ⇒ Promise.<PageData>
Fetches all data for the given page, including navigation and taxonomies/results for index pages.
Kind: instance method of MarkdownPages
| Param | Type | Default |
|---|---|---|
| page | Page |
|
| [queryParams] | module:qs~ParsedQs |
{} |
Example
const aboutPage = markdownPages.getPage('/about-us');
const pageData = markdownPages.getDataForPage(aboutPage);Kind: global typedef Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [source] | String |
"./pages" |
The directory containing your markdown and image content files |
| [pathPrefix] | String |
"/" |
Prepends generated URL paths with this prefix (this should match the route mounted) |
| [taxonomies] | Array.<String> |
["tags"] |
Frontmatter properties to use as a list of tags used to create logical groupings of content |
| [hideDraftPages] | Boolean |
true |
Exclude draft pages from navigation, defaults to true in production and false in development |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| filePath | String |
The full path to the file on disk |
| fileName | String |
The file base name |
| id | String |
A unique randomly generated ID for internal use |
| order | Number |
The sort order taken from the file name or parent folder name |
| url | String |
The generated friendly URL for the page |
| html | String |
The transformed HTML content of the page |
| text | String |
The transformed text content of the page |
| childIDs | Array.<String> |
The IDs of pages one level deeper in the navigation hierarchy |
| parentID | String |
The ID of any parent page |
| [title] | String |
Title for the page taken from page frontmatter |
| [description] | String |
Description for the page taken from page frontmatter |
| [cloneContentFrom] | String |
A relative path to another page to clone content from |
| [redirect] | String |
A URL or relative path to redirect to instead of displaying the page |
| [draft] | Boolean |
Pages set to draft status will be excluded from navigation properties in production only |
| [hidden] | Boolean |
Pages set to hidden will always be excluded from navigation properties |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| filePath | String |
The full path to the file on disk |
| fileName | String |
The file base name |
| id | String |
A unique randomly generated ID for internal use |
| url | String |
The generated friendly URL for the image |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| ancestors | Array.<Page> |
Pages traversing up the navigation hierarchy from the current page, can be used to render a crumbtrail |
| siblings | Array.<Page> |
Pages at the same level in the navigation hierarchy as the current page |
| children | Array.<Page> |
Any immediate descendants in the navigation hierarchy for the current page |
| current | Page |
A reference to the current page |
Kind: global typedef Properties
| Name | Type |
|---|---|
| name | String |
| selected | Boolean |
| href | String |
Kind: global typedef Properties
| Name | Type |
|---|---|
| label | String |
| name | String |
| options | Array.<TaxonomyOption> |
Kind: global typedef Properties
| Name | Type | Description |
|---|---|---|
| page | Page |
|
| navigation | Navigation |
|
| taxonomies | Array.<Taxonomy> | null |
A list of taxonomies and tags used by any child pages. Only populated for index pages. |
| results | Array.<Page> | null |
A list of child pages filtered by selected tags. Only populated for index pages. |