From a55912fa332169a25cade2af8b4bf40686bb7921 Mon Sep 17 00:00:00 2001 From: reco_luan Date: Tue, 26 Nov 2019 15:50:55 +0800 Subject: [PATCH] fix: add sticky article sort feature --- example/docs/views/category2/2016/121501.md | 2 +- example/docs/views/category2/2017/092101.md | 1 + mixins/index.js | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/example/docs/views/category2/2016/121501.md b/example/docs/views/category2/2016/121501.md index 97f80fc..40463dc 100644 --- a/example/docs/views/category2/2016/121501.md +++ b/example/docs/views/category2/2016/121501.md @@ -5,7 +5,7 @@ tags: - tag3 categories: - category2 -sticky: true +sticky: 1 --- first page in category2 \ No newline at end of file diff --git a/example/docs/views/category2/2017/092101.md b/example/docs/views/category2/2017/092101.md index 8e65e5b..2979f45 100644 --- a/example/docs/views/category2/2017/092101.md +++ b/example/docs/views/category2/2017/092101.md @@ -7,6 +7,7 @@ categories: - category2 keys: - '1232' +sticky: 2 --- second page in category2 \ No newline at end of file diff --git a/mixins/index.js b/mixins/index.js index ee216a3..22832f4 100644 --- a/mixins/index.js +++ b/mixins/index.js @@ -18,8 +18,16 @@ export default { ? !(home == true || title == undefined || date === undefined || publish === false) : !(home == true || title == undefined || publish === false) }) + this._sortstickyArr(stickyArr) return stickyArr.concat(posts) }, + _sortstickyArr (posts) { + if (posts.length > 0) { + posts.sort((a, b) => { + return b.sticky - a.sticky + }) + } + }, _sortPostData (posts) { posts.sort((a, b) => { return this._getTimeNum(b) - this._getTimeNum(a)