Explorar o código

`data-instant` attribute allows external links

Alexandre Dieulot %!s(int64=6) %!d(string=hai) anos
pai
achega
b007f34a70
Modificáronse 2 ficheiros con 2 adicións e 2 borrados
  1. 1 1
      instantpage.js
  2. 1 1
      test/app.js

+ 1 - 1
instantpage.js

@@ -99,7 +99,7 @@ function isPreloadable(linkElement) {
 
   const urlObject = new URL(linkElement.href)
 
-  if (!allowExternalLinks && urlObject.origin != location.origin) {
+  if (!allowExternalLinks && urlObject.origin != location.origin && !('instant' in linkElement.dataset)) {
     return
   }
 

+ 1 - 1
test/app.js

@@ -77,7 +77,7 @@ async function requestListener(req, res) {
     content += `<a href="/${page}?${Math.random()}#anchor" ${dataInstantAttribute}><span>Other page anchor</span></a>`
     content += `<a href="${req.url}#anchor" id="anchor"><span>Same-page anchor</span></a>`
     content += `<a href="/${page}?${Math.random()}" data-no-instant><span>Manually blacklisted link</span></a>`
-    content += `<a href="https://www.google.com/"><span>External link</span></a>`
+    content += `<a href="https://www.google.com/" ${dataInstantAttribute}><span>External link</span></a>`
     content += `<a><span>&lt;a&gt; without <code>href</code></span></a>`
 
     let footer = await fsPromises.readFile(path.resolve(__dirname, 'footer.html'))