循环通过帖子'日期,以便在DocPad中进行存档
Loop through posts' date in order to make archive in DocPad
下面是我想要实现的一些伪代码:
for year in post.date
h1 year
for month in post.date
h2 month
ul
li post entry
这就是伪代码。然而,我没有足够的经验来做到这一点。发生这种情况的文件如下:https://github.com/Greduan/eduantech.docpad/blob/master/src/documents/posts.html.eco
这将是生态语言。我也在使用Moment.js,以备不时之需。
即使您没有提供确切的代码,我们也将非常感谢您的指导。:)
编辑:我想要实现的目标与此类似:http://swannodette.github.io/archive.html
第2版:以下是我想出的一些代码:
for post in @getCollection('posts').toJSON()
for year in post.date
h1 @moment(post.date).format('YYYY')
for month in post.date
h2 @moment(post.date).format('MMMM')
ul ->
li ->
@postDatetime(post.date, 'll') + ' » '
a href:'post.url', post.title
目前,它什么也没输出。所以我想我只是弄错了一些变量名,我想我确实弄错了。我很感激任何帮助。:)
BTW不必担心@postDatetime
函数。在其他地方工作没有问题。:)
如果您已经按日期对帖子进行了排序,那么您的收藏已经按年、月进行了分组。您所需要做的就是遍历整个集合,并在年/月值更改时插入年和月标题。类似这样的东西:
yr = -1 //temporary vars for storing current year value in loop
mnth = -1 //same for month value
monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
div style:'text-align:left;font-size:20px;width:500px;margin-right:auto;margin-left:auto', ->
for post in @getCollection('posts').toJSON()
if post.date.getFullYear() isnt yr
yr = post.date.getFullYear()
mnth = -1
h1 yr.toString()
if post.date.getMonth() isnt mnth
mnth = post.date.getMonth()
h2 style:'padding-left:10px;', monthNames[mnth]
ul style:'padding-left:50px;', ->
li ->
post.date.toDateString()
这听起来像你想要的吗?
相关文章:
- 比较从函数和生成的日期对象
- Json数据包含日期和时间格式
- Javascript日期格式类似于ISO,但本地
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 如何在JavaScript中延长当前日期
- 两位数的月份日期验证
- 更改angularjs中的日期-时间格式
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 将日期时间从json转换为可读格式
- NodeJS日期格式不起作用
- jquerydatetimepicker日期和时间应在框默认值中,而无需单击框
- 使用当前日期生成随机id
- primefaces日历可以禁用过去的日期和时间吗
- 提前阅读日期
- 在JavaScript中拆分日期字符串的更好方法是什么
- 查找最短和最长日期
- 将日期和时间转换为UTC格式的日期-Javascript
- jquery日期选择器年份范围默认值
- jquery日期选择器失去了交互性
- 循环通过帖子'日期,以便在DocPad中进行存档