From 8a374940e59888e9b996b688a9acd604686d5a37 Mon Sep 17 00:00:00 2001 From: Avril Date: Fri, 14 Jun 2019 23:21:04 +0100 Subject: [PATCH] internal linking --- client/embed.js | 2 ++ client/posting.js | 17 +++++++++++++++++ common.js | 8 ++++++-- package.json | 4 +++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/client/embed.js b/client/embed.js index 3961f2c..60d90ed 100644 --- a/client/embed.js +++ b/client/embed.js @@ -1,3 +1,5 @@ +var internal_url_re = /(?:>>>)?(?:https?:\/\/)?flanchan\.moe\/s\/((?:\d|\w)(?:\d|\w|\/)*)/; + /* YOUTUBE */ // fairly liberal regexp that will accept things like diff --git a/client/posting.js b/client/posting.js index 2352f43..6940339 100644 --- a/client/posting.js +++ b/client/posting.js @@ -474,6 +474,23 @@ on_input: function (val) { end -= diff; } } + /* and internal links */ + while (true) { + var m = val.match(internal_url_re); + if (!m) + break; + var sc = '>>>/s/' + m[1]; + var old = m[0].length; + val = val.substr(0, m.index) + sc + val.substr(m.index + old); + changed = true; + ward = m.index; + ward_len = sc.length; + if (m.index < start) { + var diff = old - sc.length; + start -= diff; + end -= diff; + } + } /* and Twitter links */ while (true) { var m = val.match(twitter_url_re); diff --git a/common.js b/common.js index b105c1c..5d4e8bc 100644 --- a/common.js +++ b/common.js @@ -201,7 +201,7 @@ var OS = OneeSama.prototype; var break_re = new RegExp("(\\S{" + DEFINES.WORD_LENGTH_LIMIT + "})"); /* internal refs, embeds */ -var ref_re = />>(\d+|>\/watch\?v=[\w-]{11}(?:#t=[\dhms]{1,9})?|>\/soundcloud\/[\w-]{1,40}\/[\w-]{1,80}|>\/@\w{1,15}\/\d{4,20}(?:\?s=\d+)?|>\/(?:a|sysint|nap)\/\d{0,10})/; +var ref_re = />>(\d+|>\/s\/(?:\w|\d)(?:\w|\d|\/)*|>\/watch\?v=[\w-]{11}(?:#t=[\dhms]{1,9})?|>\/soundcloud\/[\w-]{1,40}\/[\w-]{1,80}|>\/@\w{1,15}\/\d{4,20}(?:\?s=\d+)?|>\/(?:a|sysint|nap)\/\d{0,10})/; OS.hook = function (name, func) { var hs = this.hooks[name]; @@ -241,10 +241,14 @@ OS.red_string = function (ref) { dest = 'https://www.youtube.com/' + ref.slice(2); linkClass = 'embed watch'; } - else if (prefix == '>/s') { + else if (prefix2 == '>/sou') { dest = 'https://soundcloud.com/' + ref.slice(13); linkClass = 'embed soundcloud'; } + else if (prefix == '>/s') { + dest ="/"+ ref.slice(2); + linkClass = 'embed' + } else if (prefix == '>/@') { var bits = ref.slice(3).split('/'); dest = 'https://twitter.com/' + bits[0] + '/status/' + bits[1]; diff --git a/package.json b/package.json index 338321b..de5947e 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,12 @@ "dependencies": { "async": "2.1.4", "chart.js": "^2.7.2", + "diskspace": "^2.0.0", "formidable": "1.0.17", + "hashloli": "file:../hashloli", "jsoncompress": "^0.1.3", "minimist": "1.2.0", - "nan": "2.5.0", + "nan": "^2.14.0", "recaptcha2": "^1.3.2", "redis": "2.6.3", "request": "2.79",