@@ -10,10 +10,8 @@ var Akismetor = require(path.join(__dirname, '..', 'services', 'akismetor'));
1010var moment = require ( 'moment' ) ;
1111var pluralize = require ( 'pluralize' ) ;
1212var expressValidator = require ( 'express-validator' ) ;
13- var _ = require ( 'lodash' ) ;
1413var config = require ( path . join ( __dirname , '..' , '..' , 'config' ) ) ;
1514
16-
1715var csrfProtection = csrf ( ) ;
1816var parseForm = bodyParser . urlencoded ( { extended : false } ) ;
1917var parseJson = bodyParser . json ( ) ;
@@ -136,63 +134,23 @@ router.
136134 if ( offset ) {
137135 Articles . paginated ( offset , function ( all ) {
138136 Articles . totalPublished ( function ( total ) {
139- var lastDay ;
140- // TODO: Move date functionality into a serivce. It'll be used practically
141- // everywhere. Oh, and refactor this blasphemy.
142- //
143- // TODO: We shouldn't be needing to use moment in order to make the time
144- // UTC. There's an issue with pg and it's parsing the dates from the db
145- // incorrectly. This is a temporary fix until I can snipe the bug.
146- all . map ( function ( item ) {
147- item . date = moment . utc ( item . published_at ) . format ( 'LL' ) ;
148- if ( item . date == moment . utc ( Date . now ( ) ) . format ( 'LL' ) ) {
149- item . date = 'Today'
150- } else if ( item . date == moment . utc ( Date . now ( ) ) . subtract ( 1 , 'days' ) . format ( 'LL' ) ) {
151- item . date = 'Yesterday'
152- } else {
153- item . date = moment ( item . date ) . format ( 'dddd, LL' ) ;
154- }
155- } ) ;
156- // There are strings and integers here - not so good.
157- if ( all . length ) {
158- lastDay = all [ all . length - 1 ] . date ;
159- }
160137 more = ( all . length == ( total [ 0 ] . count - offset ) ) ? false : true ;
161- all = _ . groupBy ( all , 'date' ) ;
162- res . json ( { flow : all , more : more , lastDay : lastDay } ) ;
138+ res . json ( { flow : all , more : more } ) ;
163139 } ) ;
164140 } ) ;
165141 } else {
166142 Articles . recent ( function ( all ) {
167143 Articles . totalPublished ( function ( total ) {
168- var flow = [ ] , news = [ ] , lastDay ;
169- // TODO: Move date functionality into a serivce. It'll be used practically
170- // everywhere. Oh, and refactor this blasphemy.
171- //
172- // TODO: We shouldn't be needing to use moment in order to make the time
173- // UTC. There's an issue with pg and it's parsing the dates from the db
174- // incorrectly. This is a temporary fix until I can snipe the bug.
144+ var flow = [ ] , news = [ ] ;
175145 all . map ( function ( item ) {
176- item . date = moment . utc ( item . published_at ) . format ( 'LL' ) ;
177- if ( item . date == moment . utc ( Date . now ( ) ) . format ( 'LL' ) ) {
178- item . date = 'Today'
179- } else if ( item . date == moment . utc ( Date . now ( ) ) . subtract ( 1 , 'days' ) . format ( 'LL' ) ) {
180- item . date = 'Yesterday'
181- } else {
182- item . date = moment ( item . date ) . format ( 'dddd, LL' ) ;
183- }
184146 if ( item . news ) {
185147 news . push ( item ) ;
186148 } else {
187149 flow . push ( item ) ;
188150 }
189151 } ) ;
190- if ( flow . length ) {
191- lastDay = flow [ flow . length - 1 ] . date ;
192- }
193152 more = ( flow . length === parseInt ( total [ 0 ] . count ) ) ? false : true ;
194- flow = _ . groupBy ( flow , 'date' ) ;
195- res . render ( 'news/index' , { flow_collection : flow , news_collection : news , more : more , lastDay : lastDay } ) ;
153+ res . render ( 'news/index' , { flow_collection : flow , news_collection : news , more : more } ) ;
196154 } ) ;
197155 } ) ;
198156 }
0 commit comments