@@ -10,7 +10,6 @@ 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' ) ;
1413
1514
1615var csrfProtection = csrf ( ) ;
@@ -135,63 +134,23 @@ router.
135134 if ( offset ) {
136135 Articles . paginated ( offset , function ( all ) {
137136 Articles . totalPublished ( function ( total ) {
138- var lastDay ;
139- // TODO: Move date functionality into a serivce. It'll be used practically
140- // everywhere. Oh, and refactor this blasphemy.
141- //
142- // TODO: We shouldn't be needing to use moment in order to make the time
143- // UTC. There's an issue with pg and it's parsing the dates from the db
144- // incorrectly. This is a temporary fix until I can snipe the bug.
145- all . map ( function ( item ) {
146- item . date = moment . utc ( item . published_at ) . format ( 'LL' ) ;
147- if ( item . date == moment . utc ( Date . now ( ) ) . format ( 'LL' ) ) {
148- item . date = 'Today'
149- } else if ( item . date == moment . utc ( Date . now ( ) ) . subtract ( 1 , 'days' ) . format ( 'LL' ) ) {
150- item . date = 'Yesterday'
151- } else {
152- item . date = moment ( item . date ) . format ( 'dddd, LL' ) ;
153- }
154- } ) ;
155- // There are strings and integers here - not so good.
156- if ( all . length ) {
157- lastDay = all [ all . length - 1 ] . date ;
158- }
159137 more = ( all . length == ( total [ 0 ] . count - offset ) ) ? false : true ;
160- all = _ . groupBy ( all , 'date' ) ;
161- res . json ( { flow : all , more : more , lastDay : lastDay } ) ;
138+ res . json ( { flow : all , more : more } ) ;
162139 } ) ;
163140 } ) ;
164141 } else {
165142 Articles . recent ( function ( all ) {
166143 Articles . totalPublished ( function ( total ) {
167- var flow = [ ] , news = [ ] , lastDay ;
168- // TODO: Move date functionality into a serivce. It'll be used practically
169- // everywhere. Oh, and refactor this blasphemy.
170- //
171- // TODO: We shouldn't be needing to use moment in order to make the time
172- // UTC. There's an issue with pg and it's parsing the dates from the db
173- // incorrectly. This is a temporary fix until I can snipe the bug.
144+ var flow = [ ] , news = [ ] ;
174145 all . map ( function ( item ) {
175- item . date = moment . utc ( item . published_at ) . format ( 'LL' ) ;
176- if ( item . date == moment . utc ( Date . now ( ) ) . format ( 'LL' ) ) {
177- item . date = 'Today'
178- } else if ( item . date == moment . utc ( Date . now ( ) ) . subtract ( 1 , 'days' ) . format ( 'LL' ) ) {
179- item . date = 'Yesterday'
180- } else {
181- item . date = moment ( item . date ) . format ( 'dddd, LL' ) ;
182- }
183146 if ( item . news ) {
184147 news . push ( item ) ;
185148 } else {
186149 flow . push ( item ) ;
187150 }
188151 } ) ;
189- if ( flow . length ) {
190- lastDay = flow [ flow . length - 1 ] . date ;
191- }
192152 more = ( flow . length === parseInt ( total [ 0 ] . count ) ) ? false : true ;
193- flow = _ . groupBy ( flow , 'date' ) ;
194- 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 } ) ;
195154 } ) ;
196155 } ) ;
197156 }
0 commit comments