diff --git a/controllers/story.js b/controllers/story.js index e32a81aba0..36ae133107 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -1,14 +1,11 @@ var R = require('ramda'), - debug = require('debug')('freecc:cntr:post'), + debug = require('debug')('freecc:cntr:story'), Story = require('./../models/Story'), Comment = require('./../models/Comment'), User = require('./../models/User'), + moment = require('../public/js/lib/moment/moment.js'), resources = require('./resources'); -/** - * Post Controller - */ - exports.json = function(req, res, next) { var story = Story.find({}).sort({'rank': -1}); story.exec(function(err, stories) { @@ -25,7 +22,7 @@ exports.index = function(req, res, next) { if (err) { throw err; } - res.render('post/index'); + res.render('stories/index'); }); }; @@ -55,16 +52,17 @@ exports.returnIndividualStory = function(req, res, next) { } debug('Story', story); - res.render('post/show', { + res.render('stories/show', { title: story.headline, - dashedName: story.link, + link: story.link, author: story.author, body: story.body, rank: story.rank, upVotes: story.upVotes, comments: story.comments, id: story._id, - user: req.user + user: req.user, + timeAgo: moment(story.timePosted).fromNow() }); }); }; diff --git a/models/Story.js b/models/Story.js index ba000b0a7d..79e41d774e 100644 --- a/models/Story.js +++ b/models/Story.js @@ -6,6 +6,10 @@ var storySchema = new mongoose.Schema({ type: String, unique: false }, + timePosted: { + type: Number, + default: 0 + }, link: { type: String, unique: false diff --git a/public/css/main.less b/public/css/main.less index d22fc4ea05..027540edec 100644 --- a/public/css/main.less +++ b/public/css/main.less @@ -719,7 +719,6 @@ iframe.iphone { -ms-transition: background .2s ease-in-out, border .2s ease-in-out; -o-transition: background .2s ease-in-out, border .2s ease-in-out; transition: background .2s ease-in-out, border .2s ease-in-out; - } .hamburger { @@ -751,6 +750,14 @@ iframe.iphone { .big-ion-up-arrow { font-size: 45px; margin-top: -10px; + text-align: center; + margin-bottom: -15px; +} + +.story-up-votes { + padding-top: 0px; + margin-left: -5px; + text-align: center; } //uncomment this to see the dimensions of all elements outlined in red diff --git a/public/js/application.js b/public/js/application.js index f792928b2b..eeebfa316b 100644 --- a/public/js/application.js +++ b/public/js/application.js @@ -15,5 +15,5 @@ //= require lib/jquery-2.1.1.min //= require lib/bootstrap.min -//= require lib/together/togetherjs +//= require lib/moment/moment //= require main diff --git a/seed_data/stories.json b/seed_data/stories.json index fd1a3a1c4f..ccaedb7bd7 100644 --- a/seed_data/stories.json +++ b/seed_data/stories.json @@ -5,36 +5,39 @@ "body": "cats love keyboards you know", "rank": 0, "upVotes": [], + "timePosted": 1425429660000, "author": { - "username": "terakilobyte", + "username": "testuser", "userId": "a2ad135e2aa27c14fc73ee11", - "picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413" + "picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif" }, "comments": [] }, - { - "headline": "Cat sits on keyboard 1", - "link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards", - "body": "cats love keyboards you know", - "rank": 1, - "upVotes": [], - "author": { - "username": "terakilobyte", - "userId": "a2ad135e2aa27c14fc73ee22", - "picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413" - }, - "comments": [] + { + "headline": "Cat sits on keyboard 1", + "link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards", + "body": "cats love keyboards you know", + "rank": 1, + "upVotes": [], + "timePosted": 1425429660000, + "author": { + "username": "testuser", + "userId": "a2ad135e2aa27c14fc73ee22", + "picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif" }, + "comments": [] + }, { "headline": "Cat sits on keyboard 3", "link": "http://kotaku.com/5991046/why-cats-love-sitting-on-keyboards", "body": "cats love keyboards you know", "rank": 3, "upVotes": [], + "timePosted": 1425429660000, "author": { - "username": "terakilobyte", + "username": "testuser", "userId": "a2ad135e2aa27c14fc73ee33", - "picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413" + "picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif" }, "comments": [] }, @@ -44,12 +47,15 @@ "body": "ipsizzle dolizzle sit amet, ghetto adipiscing elit. Nullam fo shizzle velizzle, aliquet volutpizzle, suscipizzle shiz, gravida vizzle, arcu. Pellentesque izzle tortor. Sizzle doggy. Boom shackalack izzle dolizzle dapibizzle ass tempizzle tellivizzle. Ma nizzle we gonna chung shiz izzle tellivizzle. Vestibulum dizzle tortor. Pellentesque pimpin' rhoncus you son of a bizzle. In dizzle habitasse platea dictumst. Donec dapibizzle. Curabitizzle pot yippiyo, pretizzle da bomb, mattis izzle, da bomb vitae, nunc. Ass suscipizzle. Cool sempizzle bow wow wow sed purus.", "rank": 20, "upVotes": [], + "timePosted": 1425429660000, "author": { - "username": "terakilobyte", + "username": "testuser", "userId": "a2ad135e2aa27c14fc73ee44", - "picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413" + "picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif" }, - "comments": ["54f61b0e43f0c2b90f162ec4"] + "comments": [ + "54f61b0e43f0c2b90f162ec4" + ] }, { "headline": "Cat sits on keyboard 2", @@ -57,10 +63,11 @@ "body": "cats love keyboards you know", "rank": 2, "upVotes": [], + "timePosted": 1425429660000, "author": { - "username": "terakilobyte", + "username": "testuser", "userId": "a2ad135e2aa27c14fc73ee55", - "picture": "https://www.google.com/search?q=cat+photo+google+images&tbm=isch&imgil=7dFgV4OZlJObjM%253A%253BDGoqtUgH7IKDWM%253Bhttp%25253A%25252F%25252Fwww.wired.co.uk%25252Fnews%25252Farchive%25252F2012-06%25252F26%25252Fgoogle-brain-recognises-cats&source=iu&pf=m&fir=7dFgV4OZlJObjM%253A%252CDGoqtUgH7IKDWM%252C_&usg=__yxi54C0GOssHCOLnh1StLAH7KNk%3D&biw=1920&bih=981&ved=0CDYQyjc&ei=n3n1VL6ENcHZoATjvYDABQ#imgrc=7dFgV4OZlJObjM%253A%3BDGoqtUgH7IKDWM%3Bhttp%253A%252F%252Fcdni.wired.co.uk%252F620x413%252Fs_v%252Fshutterstock_65735200.jpg%3Bhttp%253A%252F%252Fwww.wired.co.uk%252Fnews%252Farchive%252F2012-06%252F26%252Fgoogle-brain-recognises-cats%3B620%3B413" + "picture": "http://www.cutecatgifs.com/wp-content/uploads/2013/11/little_guy_sleeping_in_lap.gif" }, "comments": [] } diff --git a/views/partials/navbar.jade b/views/partials/navbar.jade index 221abeebf0..9c19b96b52 100644 --- a/views/partials/navbar.jade +++ b/views/partials/navbar.jade @@ -16,7 +16,7 @@ li a(href='/chat') Chat li - a(href='http://forum.freecodecamp.com' target='_blank') Forum + a(href='/stories') News li a(href='/bonfires') Bonfires if !user diff --git a/views/post/posts.jade b/views/post/posts.jade deleted file mode 100644 index 84ddbedb23..0000000000 --- a/views/post/posts.jade +++ /dev/null @@ -1,37 +0,0 @@ -h3 - ul#story-list.story-list - - script(src="https://cdn.jsdelivr.net/ramda/0.10.0/ramda.min.js") - script. - var getLinkedName = function getLinkedName(name) { - return name.toLowerCase().replace(/\s/g, '-'); - } - $.ajax({ - url: '/stories/index', - type: 'GET' - }) - .success( - function(data) { - for (var i = 0; i < data.length; i++) { - var li = document.createElement('li'); - var linkedName = getLinkedName(data[i].headline); - var rank = data[i].rank; - - $(li).html("