forked from shadowfacts/shadowfacts.net
More markdown link heuristics
This commit is contained in:
parent
37c2c95881
commit
9599725e04
|
@ -58,8 +58,23 @@ md.renderer.rules.link_open = function(tokens, index, options, env, self) {
|
||||||
if (href != null) {
|
if (href != null) {
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(href);
|
const parsed = new URL(href);
|
||||||
|
let hostname = parsed.hostname;
|
||||||
|
|
||||||
|
// hide wwww from beginning of domain
|
||||||
|
if (hostname.startsWith("www.")) {
|
||||||
|
hostname = hostname.substr(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the path is /, omit it
|
||||||
const formattedPathname = parsed.pathname === "/" ? "" : parsed.pathname;
|
const formattedPathname = parsed.pathname === "/" ? "" : parsed.pathname;
|
||||||
let formatted = `${parsed.hostname}${formattedPathname}`;
|
|
||||||
|
let formatted = `${hostname}${formattedPathname}`;
|
||||||
|
|
||||||
|
if (hostname.endsWith("youtube.com") && formattedPathname == "/watch") {
|
||||||
|
// otherwise yt video links end up as `youtube.com/watch` which looks weird
|
||||||
|
formatted += parsed.search;
|
||||||
|
}
|
||||||
|
|
||||||
if (formatted.length > 40) {
|
if (formatted.length > 40) {
|
||||||
formatted = formatted.substr(0, 40) + "...";
|
formatted = formatted.substr(0, 40) + "...";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue