Skip to content

Commit

Permalink
已经发布的页面按照发布日期倒序排列
Browse files Browse the repository at this point in the history
  • Loading branch information
tywei90 committed Feb 18, 2018
1 parent a44d228 commit 6cc94c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
},
"dependencies": {
"antd": "^2.5.2",
"arr-sort": "^1.0.0",
"autobind-decorator": "^1.3.4",
"babel-eslint": "^7.1.1",
"babel-polyfill": "^6.26.0",
Expand Down
19 changes: 17 additions & 2 deletions server/routes/released.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var express = require('express');
var router = express.Router();
var fs = require('fs');
var arrSort = require('arr-sort');

/* GET home page. */
router.get('/', function(req, res, next) {
let filepath = './data/';
let tmpArr = [];
let existDirname = [];
fs.readdir(filepath, function(err, files) {
if (err) {
Expand All @@ -12,10 +15,22 @@ router.get('/', function(req, res, next) {
files.forEach(function(file) {
let stats = fs.statSync(filepath + file);
if(stats.isDirectory() && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(file)){
existDirname.push(file);
tmpArr.push({
name: file,
date: +stats.birthtime || +new Date()
});
}
});
// console.log(existDirname);
// 按照发布日期倒序排
tmpArr = arrSort(tmpArr,
[{
attr: 'date',
asc: false
}]
);
for(var i=0, len=tmpArr.length; i<len; i++){
existDirname.push(tmpArr[i].name);
}
if(existDirname.length > 0){
res.render('released', {
data: {
Expand Down

0 comments on commit 6cc94c9

Please sign in to comment.