Skip to content
This repository has been archived by the owner on Aug 17, 2023. It is now read-only.

Commit

Permalink
archive dates
Browse files Browse the repository at this point in the history
date information is now made available on the archive page
  • Loading branch information
chrisallenlane committed Jun 21, 2016
1 parent 442bd80 commit 8138cea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
19 changes: 15 additions & 4 deletions app/routes/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@ const archive = require('../util/archive');
const config = require('../boot/config');
const lodash = require('lodash');
const paginate = require('../util/paginate');
const xss = require('xss');
var configs = config();

module.exports = function (app, wit, callback) {

// archive by day
app.get('/blog/archive/:year/:month?/:day?', function(req, res) {

// sanitize the inputs (they will be fed into the response markup)
var year = xss(req.params.year);
var month = xss(req.params.month);
var day = xss(req.params.day);

// find the appropriate pages
var posts = archive(wit.posts, {
year : req.params.year,
month : req.params.month,
day : req.params.day,
year : year,
month : month,
day : day,
});

// drill into the posts by date
Expand All @@ -32,7 +39,11 @@ module.exports = function (app, wit, callback) {
url : req.url,
content : paginated.posts,
pagination : paginated.pagination,
// TODO: date here
date : {
year : year || '',
month : month || '',
day : day || '',
},
},
wit : wit,
});
Expand Down
3 changes: 3 additions & 0 deletions app/routes/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = function(app, wit, callback) {
// category index page
app.get('/blog/category/:category', function(req, res) {

// sanitize the input (it will be fed into the response markup)
var category = xss(req.params.category).toLowerCase();

// find the appropriate pages
var posts = lodash.filter(wit.posts, { categories: [ category ]});

// redirect to the 404 page if category is invalid
Expand Down
2 changes: 1 addition & 1 deletion app/routes/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function(app, wit, callback) {
app.get('/blog/tag/:tag', function(req, res) {

var tag = xss(req.params.tag).toLowerCase();
var posts = lodash.filter(wit.posts, { tags: [ tag ]});
var posts = lodash.filter(wit.posts, { tags: [ tag ]});

// redirect to the 404 page if tag is invalid
if (lodash.isEmpty(posts)) {
Expand Down

0 comments on commit 8138cea

Please sign in to comment.