@@ -10,10 +10,11 @@ const api = require('../http/')
10
10
const confirmToken = require ( '../middleware/confirmToken' )
11
11
const unpublishedPermission = require ( '../middleware/unpublishedPermission' )
12
12
13
- // 获取文章列表 / 按分类筛选文章
13
+ // 获取文章列表 / 按分类 / 按标签 筛选文章
14
14
router . get ( '/api/front/article/gets' , unpublishedPermission , async ( req , res ) => {
15
15
const params = { publish : req . query . publish }
16
16
if ( req . query . categoryId ) params . categoryId = req . query . categoryId
17
+ if ( req . query . tag ) params . tag = { $in : [ req . query . tag ] }
17
18
const limit = parseInt ( req . query . limit ) || 10
18
19
const skip = req . query . page * limit - limit
19
20
const project = req . query . content == '0' ? { content : 0 } : { }
@@ -224,29 +225,35 @@ router.get('/api/front/article/search', unpublishedPermission, async (req, res)
224
225
} )
225
226
// 文章归档
226
227
router . get ( '/api/front/article/archives' , async ( req , res ) => {
227
- // const limit = parseInt(req.query.limit) || 10
228
- // const skip = req.query.page * limit - limit
228
+ const limit = parseInt ( req . query . limit ) || 10
229
+ const skip = req . query . page * limit - limit
230
+
229
231
try {
230
232
const doc = await db . article . aggregate ( [
231
233
{ $match : { } } ,
232
234
{ $sort : { _id : - 1 } } ,
233
- // { $skip: skip },
234
- // { $limit: limit },
235
+ { $skip : skip } ,
236
+ { $limit : limit } ,
235
237
{
236
238
$project : {
237
239
year : { $dateToString : { format : '%Y' , date : '$createTime' } } ,
238
240
month : { $dateToString : { format : '%Y-%m' , date : '$createTime' } } ,
239
241
title : 1 ,
240
242
createTime : 1 ,
241
- articleId : 1
243
+ articleId : 1 ,
244
+ headerPic : 1
242
245
}
243
246
} ,
244
247
{ $group : { _id : '$year' , total : { $sum : 1 } , months : { $push : '$$ROOT' } } } ,
245
- { $project : { year : '$_id' , _id : 0 , total : 1 , months : 1 } }
248
+ { $project : { year : '$_id' , _id : 0 , total : 1 , months : 1 } } ,
249
+ { $sort : { year : - 1 } }
246
250
] )
251
+ const total = await db . article . count ( { publish : 1 } )
252
+
247
253
res . json ( {
248
254
status : 200 ,
249
255
data : doc ,
256
+ total,
250
257
info : '归档查询成功'
251
258
} )
252
259
} catch ( e ) {
0 commit comments