~sircmpwn/cgi-scripts

f3d1c1b754f29e2746d4688d77c6219125533487 — Drew DeVault 4 years ago 2523a9c
web2gmi: rewrite links to route through proxy
1 files changed, 13 insertions(+), 6 deletions(-)

M web2gmi.js
M web2gmi.js => web2gmi.js +13 -6
@@ 32,15 32,22 @@ const convert = (dom, title) => {
    output += `# ${title}\n\n`;
  }

  const rewriteLink = href =>
    "?" + encodeURIComponent(href);

  const emitLink = link => {
      let desc = sanitize(link.innerHTML);
      if (desc === "") {
        const img = link.querySelector("img");
        if (img) {
          desc = `${img.alt ? " " + img.alt : ""}\n\n`;
        }
    let desc = sanitize(link.innerHTML);
    if (desc === "") {
      const img = link.querySelector("img");
      if (img) {
        desc = `${img.alt ? " " + img.alt : ""}\n\n`;
      }
    }
    if (link.protocol === "http:" || link.protocol === "https:") {
      output += `=> ${rewriteLink(link.href)} ${desc}\n`;
    } else {
      output += `=> ${link.href} ${desc}\n`;
    }
  };

  let visited = [];