roots-collections
所属分类:前端开发
开发工具:CoffeeScript
文件大小:0KB
下载次数:0
上传日期:2020-05-26 17:59:34
上 传 者:
sh-1993
说明: 用于Roots静态网站生成器的具有YAML frontmatter和Markdown的内容集合
(Content collections with YAML frontmatter and Markdown for the Roots static site generator)
文件列表:
LICENSE (1074, 2016-03-18)
lib/ (0, 2016-03-18)
lib/index.coffee (3739, 2016-03-18)
package.json (658, 2016-03-18)
testsite/ (0, 2016-03-18)
testsite/app.coffee (620, 2016-03-18)
testsite/app.production.coffee (539, 2016-03-18)
testsite/assets/ (0, 2016-03-18)
testsite/assets/css/ (0, 2016-03-18)
testsite/assets/css/_settings.styl (1556, 2016-03-18)
testsite/assets/css/master.styl (65, 2016-03-18)
testsite/assets/img/ (0, 2016-03-18)
testsite/assets/img/.keep (0, 2016-03-18)
testsite/assets/js/ (0, 2016-03-18)
testsite/assets/js/main.coffee (26, 2016-03-18)
testsite/package.json (369, 2016-03-18)
testsite/posts/ (0, 2016-03-18)
testsite/posts/2016-01-08-a-test-post.md (120, 2016-03-18)
testsite/views/ (0, 2016-03-18)
testsite/views/index.jade (233, 2016-03-18)
testsite/views/layout.jade (429, 2016-03-18)
testsite/views/post.jade (87, 2016-03-18)
# Roots Collections
Content Collections based on Markdown with Frontmatter for the [Roots](http://roots.cx/) static site generator.
## Installation
* make sure you're in your roots project directory
* `npm install roots-collections --save`
* modify your `app.coffee` file to include the extension
```coffee
collections = require 'roots-collections'
module.exports =
extensions: [collections(folder: 'posts', layout: 'post')]
```
## Usage
Once you've installed the extension, Roots will search the specified folder for collections and make them available in your templates.
Files in the folder should end with the extension `.md` and be written as markdown with YAML frontmatter:
```
---
title: This is the title
desc: A description
---
# I am markdown
Hello
```
If the file names follow the following patter:
```
/posts/2015-05-04-this-is-a-blog-post.md
```
The extension will automatically add a `date` to the entries based on the date in the filename.
If a `layout` is specified, each entry will be rendered with the specified layout. The layout template can access an `entry` variable with the title, date, slug, body, and other metadata from the entry.
```jade
extends layout
block content
h3.post-title= entry.title
.post-body!= entry.body
```
## Entry Listings
The name of the collection is based on the folder, unless you explicitly set a `name` when configuring the extension.
So if you configure the extension with `posts(folder: 'posts')` you will be able to use `posts.orderBy('date','desc')` in templates. If you configure the extension with `posts(folder: 'docs')`, you'll be able to use `docs.orderBy('title')` in templates.
Example:
```jade
.recent-posts-listing
each post in posts.orderBy('date', 'desc').slice(0, 10)
h3.title
a.post-title(href=post.permalink)= post.title
.body!= post.body
```
## Computed Entry Properties
By default the collections extension will compute the `slug`, `permalink`,`date` and `body` properties based on the filename of each entry, but you can also hook into the compilation phase to add your own computed properties or modify any of the default properties, by passing a `prepare` function to the extension:
Here's a simple example of adding an `upcased_title` property to each entry.
```coffee
module.exports =
extensions: [collections(
folder: 'posts',
layout: 'post',
prepare: (post) ->
post.upcased_title = post.title && post.title.toUpperCase()
)]
```
## License
This extension is published under the [MIT License](https://github.com/netlify/roots-collections/blob/master/LICENSE.md)
近期下载者:
相关文件:
收藏者: