Skip to content

Commit

Permalink
v1.10.1 修复新版 Ghost 无法获取归档的问题 (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddiu8081 committed Mar 6, 2019
1 parent 30b2d5a commit 967a444
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Ghost 0.x版本默认的 Casper 十分好看,可惜1.0版本之后就改成 cm
* 2018.10.02 v1.9.5 取消依赖 BootCDN 公共库
* 2018.10.09 v1.9.6 修改 figcaption 样式 (#9)
* 2018.12.19 v1.10.0 增加内页导航栏;样式微调;修复作者页bug;fix #11
* 2019.03.06 v1.10.1 修复新版 Ghost 无法获取归档的问题 (#19)

## 下载与使用

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": [
"ghost-theme"
],
"version": "1.10.0",
"version": "1.10.1",
"engines": {
"ghost": ">=1.0.0",
"ghost-api": "v2"
Expand Down
53 changes: 52 additions & 1 deletion page-archives.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</section>
</header>

<div id="archives-list" class="typo">
{{!-- <div id="archives-list" class="typo">
{{#get "posts" limit="all" order="published_at desc"}}
{{#foreach posts }}
<h2>{{date published_at format="YYYY"}}</h2>
Expand All @@ -33,7 +33,58 @@
</ul>
{{/foreach}}
{{/get}}
</div> --}}

<ul id="archives-list" class="typo">
{{#get "posts" limit="all" order="published_at desc"}}
{{#foreach posts}}
<li class='archives-item' date="{{date format='YYYY'}}">
<time>{{date published_at format="MM-DD"}}</time>
<a href='{{url}}'>{{title}}</a>
</li>
{{/foreach}}
{{/get}}
</div>
</article>
</main>

<script>
// 方法1:先输出列表再添加年份,修改自 @xiaoluoboding
var yearArray = new Array();
$(".archives-item").each(function() {
var archivesYear = $(this).attr("date");
yearArray.push(archivesYear);
});
var uniqueYear = $.unique(yearArray);
for (var i = 0; i < uniqueYear.length; i++) {
var html = "<h2>" + uniqueYear[i] + "</h2>";
$("[date='" + uniqueYear[i] + "']:first").before(html);
}
//方法2:同时输出年份和列表,修改自 @ldsun
// $.get(ghost.url.api('posts', {
// limit: 'all',
// order: "published_at desc"
// })).done(function(data) {
// var posts = data.posts;
// var count = posts.length;
// for (var i = 0, pre_year = 0; i < count; i++) {
// //调用moment.js对时间戳进行操作
// var time = moment(posts[i].published_at);
// var year = time.year();
// var title = posts[i].title;
// var url = posts[i].url;
// if (year != pre_year) {
// var html = "<h2>"+year+"</h2>"+
// "<ul id='year-"+year+"'></ul>"
// $(html).appendTo("#archives-list");
// }
// var html = "<li><time>"+time.format("MM-DD")+"</time><a href='"+url+"'>"+title+"</a></li>";
// $(html).appendTo("#year-"+year);
// pre_year = year;
// }
// }).fail(function(err) {
// console.log(err);
// });
</script>

{{/post}}

0 comments on commit 967a444

Please sign in to comment.