Skip to content

Commit 12410ef

Browse files
author
joeltaylor
committed
Remove date logic and simplify locales
1 parent 51acb2c commit 12410ef

File tree

3 files changed

+48
-94
lines changed

3 files changed

+48
-94
lines changed

client/javascripts/components/modules/loadStories.js

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,30 @@ JS.Modules.LoadStories = (function() {
3939
var stories = data.flow,
4040
markup = '';
4141

42-
for (group in stories) {
43-
44-
stories[group].forEach(function(story) {
45-
markup +=
46-
'<li class="list-item">' +
47-
'<article class="bucket">' +
48-
'<div class="bucket-media">' +
49-
'<img class="thumb" src="' + story.avatar_url + '" width="50"/>' +
50-
'</div>' +
51-
'<div class="bucket-content">' +
52-
'<h2 class="h h--4">' +
53-
'<a class="externalLink tct twb" href="' + story.url + '" target="_blank">' + story.title +
54-
'<svg width="16" height="16" class="icon externalLink-icon">' +
55-
'<use xlink:href="#icon-external"/>' +
56-
'</svg>' +
57-
'</a>' +
58-
'</h2>' +
59-
'<p class="mbf tcs tfh tss">' +
60-
'via ' + '<span class="twsb">' + story.name + '</span>' +
61-
' | ' + '<a class="' + commentClass(story.comment_count) + '" href="/news/' + story.slug + '#comments">View Discussion ' + commentNumber(story.comment_count) + '</a>' +
62-
'</p>' +
63-
'</div>' +
64-
'</article>' +
65-
'</li>';
66-
});
42+
stories.forEach(function(story) {
43+
markup +=
44+
'<li class="list-item">' +
45+
'<article class="bucket">' +
46+
'<div class="bucket-media">' +
47+
'<img class="thumb" src="' + story.avatar_url + '" width="50"/>' +
48+
'</div>' +
49+
'<div class="bucket-content">' +
50+
'<h2 class="h h--4">' +
51+
'<a class="externalLink tct twb" href="' + story.url + '" target="_blank">' + story.title +
52+
'<svg width="16" height="16" class="icon externalLink-icon">' +
53+
'<use xlink:href="#icon-external"/>' +
54+
'</svg>' +
55+
'</a>' +
56+
'</h2>' +
57+
'<p class="mbf tcs tfh tss">' +
58+
'via ' + '<span class="twsb">' + story.name + '</span>' +
59+
' | ' + '<a class="' + commentClass(story.comment_count) + '" href="/news/' + story.slug + '#comments">View Discussion ' + commentNumber(story.comment_count) + '</a>' +
60+
'</p>' +
61+
'</div>' +
62+
'</article>' +
63+
'</li>';
64+
});
6765

68-
}
6966

7067
_settings.$list.append(markup);
7168
};

server/routes/news.js

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ var Akismetor = require(path.join(__dirname, '..', 'services', 'akismetor'));
1010
var moment = require('moment');
1111
var pluralize = require('pluralize');
1212
var expressValidator = require('express-validator');
13-
var _ = require('lodash');
1413

1514

1615
var 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
}

server/views/news/index.jade

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,28 @@ block content
4343
.mbxl.js-loadFeed
4444
ul.list.list--divided.js-loadFeed-list
4545

46-
- for group, title in flow_collection
47-
48-
- for story in group
49-
50-
li.list-item
51-
article.bucket
52-
.bucket-media
53-
img.thumb(src=story.avatar_url width='50')
54-
.bucket-content
55-
h2.h.h--4
56-
a.externalLink.tct.twb(href=story.url target='_blank')
57-
= story.title
58-
- iconPartial = { name: 'external', className: 'externalLink-icon', size: 16 }
59-
include /views/partials/_icon
60-
p.mbf.tcs.tfh.tss
61-
| via
62-
span.twsb= story.name
63-
| |
64-
a(href='/news/' + story.slug + '#comments')
65-
| View Discussion
66-
if story.comment_count > 0
67-
| (
68-
= story.comment_count
69-
| )
46+
- for story in flow_collection
47+
48+
li.list-item
49+
article.bucket
50+
.bucket-media
51+
img.thumb(src=story.avatar_url width='50')
52+
.bucket-content
53+
h2.h.h--4
54+
a.externalLink.tct.twb(href=story.url target='_blank')
55+
= story.title
56+
- iconPartial = { name: 'external', className: 'externalLink-icon', size: 16 }
57+
include /views/partials/_icon
58+
p.mbf.tcs.tfh.tss
59+
| via
60+
span.twsb= story.name
61+
| |
62+
a(href='/news/' + story.slug + '#comments')
63+
| View Discussion
64+
if story.comment_count > 0
65+
| (
66+
= story.comment_count
67+
| )
7068

7169
if more
7270
.well.well--l.mbl.mbxl--m.bdrtl.ptl.tac

0 commit comments

Comments
 (0)