Skip to content

Commit

Permalink
toh.js: further link shortening
Browse files Browse the repository at this point in the history
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
  • Loading branch information
jow- committed Dec 6, 2023
1 parent 45a7bf9 commit d3a07ee
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions static/toh.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ function formatValue(colName, value) {

switch (colName) {
case 'oemdevicehomepageurl':
return formatLink(value, value);
if ((m = value.match(/^https?:\/\/(?:www\.)?([^\/]+)/)) != null)
return formatLink(value, m[1]);
else
return formatLink(value, value);

case 'owrt_forum_topic_url':
if ((m = value.match(/\bviewtopic\.php\?id=(\d+)\b/)) != null)
Expand Down Expand Up @@ -179,11 +182,20 @@ function formatValue(colName, value) {

case 'supportedsincerel':
case 'supportedcurrentrel':
return formatLink(`/releases/${value}`, value, true);
if (value.match(/^(snapshot|[0-9.]+)$/))
return formatLink(`/releases/${value}`, value, true);
else
return document.createTextNode(value ?? '');

case 'supportedsincecommit':
if ((m = value.match(/\bh=([0-9a-f]{8,40})\b/)) != null)
if ((m = value.match(/\bh=([0-9a-f]{8,})\b/)) != null || (m = value.match(/^https?:\/\/github\.com\/openwrt\/openwrt\/commit\/([0-9a-f]{8,})\b/)) != null)
return document.createElement('code').appendChild(formatLink(value, m[1].substring(0, 12))).parentNode;
else if ((m = value.match(/^https?:\/\/github\.com\/([^\/]+\/[^\/]+)\/commit\/([0-9a-f]{8,})\b/)) != null)
return formatLink(value, `GitHub: ${m[1]}@${m[2].substring(0, 12)}`);
else if ((m = value.match(/^https?:\/\/github\.com\/[^\/]+\/[^\/]+\/pull\/([0-9]+)\b/)) != null)
return formatLink(value, `GitHub: PR#${m[1]}`);
else if ((m = value.match(/^https?:\/\/github\.com\/([^\/]+\/[^\/]+)\b/)) != null)
return formatLink(value, `GitHub: ${m[1]}`);
else
return formatLink(value, value);

Expand Down

0 comments on commit d3a07ee

Please sign in to comment.