summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bucky.js2
-rw-r--r--lib/db/index.js9
-rw-r--r--public/assets/js/lib/views/details/comments.js2
-rw-r--r--public/assets/js/lib/views/index/hootbox.js2
-rw-r--r--public/assets/js/util/format.js21
5 files changed, 29 insertions, 7 deletions
diff --git a/lib/bucky.js b/lib/bucky.js
index ad2018f..a429fb3 100644
--- a/lib/bucky.js
+++ b/lib/bucky.js
@@ -54,7 +54,7 @@ var bucky = module.exports = {
})
},
ensureHootbox: function (req, res, next){
- db.getCommentsForThread(1, 9).then(function(hootbox){
+ db.getCommentsForThread(1, 9, 0, "desc").then(function(hootbox){
res.hootbox = hootbox
next()
})
diff --git a/lib/db/index.js b/lib/db/index.js
index 7452f3d..1ebae57 100644
--- a/lib/db/index.js
+++ b/lib/db/index.js
@@ -88,14 +88,15 @@ db.getFileSizes = function(ids){
/* COMMENTS */
-db.getCommentsForThread = function (id, limit, offset){
+db.getCommentsForThread = function (id, limit, offset, order){
+ order = order || "asc"
return Comment.query(function(qb){
- qb.where("thread", "=", id).orderBy("id", "asc")
+ qb.where("thread", "=", id).orderBy("id", order)
if (limit) {
- qb = qb.limit(limit)
+ qb.limit(limit)
}
if (offset) {
- qb = qb.offset(offset)
+ qb.offset(offset)
}
}).fetchAll().then(function(comments){
comments.forEach(function(comment){
diff --git a/public/assets/js/lib/views/details/comments.js b/public/assets/js/lib/views/details/comments.js
index 168cc3f..399c90d 100644
--- a/public/assets/js/lib/views/details/comments.js
+++ b/public/assets/js/lib/views/details/comments.js
@@ -17,7 +17,7 @@ var CommentsView = FormView.extend({
parse: function(comment){
var datetime = verbose_date(comment.date, true)
var t = this.template.replace(/{{username}}/g, comment.username)
- .replace(/{{comment}}/g, comment.comment)
+ .replace(/{{comment}}/g, tidy_urls(comment.comment))
.replace(/{{date}}/g, datetime[0])
.replace(/{{time}}/g, datetime[1])
return t
diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js
index 15de06b..9d1cc3d 100644
--- a/public/assets/js/lib/views/index/hootbox.js
+++ b/public/assets/js/lib/views/index/hootbox.js
@@ -17,7 +17,7 @@ var HootBox = FormView.extend({
parse: function(comment){
var t = this.template.replace(/{{username}}/g, comment.username)
- .replace(/{{comment}}/g, comment.comment)
+ .replace(/{{comment}}/g, tidy_urls(comment.comment, true))
return t
},
diff --git a/public/assets/js/util/format.js b/public/assets/js/util/format.js
index b789602..00cc94c 100644
--- a/public/assets/js/util/format.js
+++ b/public/assets/js/util/format.js
@@ -169,4 +169,25 @@ function get_age (t) {
if (age < 12) { return r(age) + "m" }
age /= 12
return r(age) + "y"
+}
+
+function tidy_urls (s, short_urls) {
+ var ret = s.split("\n").map(function(line){
+ if (line.indexOf("<") !== -1) {
+ return line
+ }
+ return line.replace(/https?:\/\/[^ ]+/g, function(str){
+ if (short_urls) {
+ return '<a href="' + str + '" target="_blank">[' + get_domain(str) + ']</a>'
+ }
+ else {
+ return '<a href="' + str + '" target="_blank">' + str + '</a>'
+ }
+ });
+
+ }).join("<br>\n")
+ return ret
+}
+function get_domain(url){
+ return url.replace(/https?:\/\//,"").replace(/\/.*/,"").replace(/www\./, "")
} \ No newline at end of file