jekyll-hover-popup 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb537e34ef0aa3bb1f5396179b65f549533f3c670cd4dffcd581f3b727c355c2
4
- data.tar.gz: 552f8704d5da719123714a6f9bb22c8921ec38131a16f3c8d5d36bf5fcbbb8fb
3
+ metadata.gz: ef86f67414cd583b5deed738fcf315d2522f91bb1ecdaa8e51324dd1a07b28bf
4
+ data.tar.gz: 72bb69e7957b9e4a3e6a99a44672684620af0435bf039d74a0c7a372f53cba8c
5
5
  SHA512:
6
- metadata.gz: 03eb03b79e05fa4b829562d5f11ebbf270e2b6e35fb8f61f0f4f45474fd580556795d4eceee5f8e53f5cf62d4f3e496aae0fd5a13b09d6726e1d0602f158bd43
7
- data.tar.gz: 02e9f34463fdbaf23c1c3b2c231096d3e09d2853ce6b7aeaa27c780a65dd2cb75977b2cb3431cb95d773f2f73ad1b8deb6bbfa5d4a7bb20248de5f8083fd07c5
6
+ metadata.gz: 7f2de59b3a55001b7ce83e7d8d9f96db7b5fc8d6dd5af2ed011cccdf4697e5b242a24c6ba0fb325c0e42fbf1cb7a74d40cc10095748adcdf6124d72217db9bd8
7
+ data.tar.gz: 2e760d83ba01e8e77be429d21c7600c829588445e7c8ce16c7c2bb66917e34089af1aef16b5de07bddbfb6de56b1e6025c65c292f455eddeb6dc029537632aaf
@@ -199,6 +199,22 @@
199
199
  color: var(--jhp-error-color);
200
200
  }
201
201
 
202
+ .jhp-hwin__notice {
203
+ padding: 1rem;
204
+ font-size: 0.8125rem;
205
+ line-height: 1.4;
206
+ word-break: break-word;
207
+ }
208
+
209
+ .jhp-hwin__notice p {
210
+ margin: 0 0 0.5rem;
211
+ opacity: 0.85;
212
+ }
213
+
214
+ .jhp-hwin__notice a {
215
+ color: var(--jhp-link-color, inherit);
216
+ }
217
+
202
218
  .jhp-resize {
203
219
  position: absolute;
204
220
  touch-action: none;
@@ -310,6 +310,54 @@
310
310
  return cloneSectionFromRoot(root, doc);
311
311
  }
312
312
 
313
+ function parseMetaRefreshUrl(content) {
314
+ if (!content) return null;
315
+ const match = String(content).match(/url\s*=\s*['"]?([^'";\s]+)/i);
316
+ return match ? match[1].trim() : null;
317
+ }
318
+
319
+ function looksLikeRedirectStub(doc) {
320
+ const title = (doc.title || "").trim().toLowerCase();
321
+ if (title.includes("redirect")) return true;
322
+ if (doc.querySelector('meta[http-equiv="refresh" i]')) return true;
323
+
324
+ for (const script of doc.querySelectorAll("script")) {
325
+ const text = script.textContent || "";
326
+ if (/location\s*=\s*["']/.test(text)) return true;
327
+ }
328
+ return false;
329
+ }
330
+
331
+ // jekyll-redirect-from (redirect_to) pages: no main content, meta refresh / JS location.
332
+ function detectExternalRedirect(doc) {
333
+ if (!doc || !looksLikeRedirectStub(doc)) return null;
334
+
335
+ const refresh = doc.querySelector('meta[http-equiv="refresh" i]');
336
+ let destination = refresh ? parseMetaRefreshUrl(refresh.getAttribute("content")) : null;
337
+
338
+ if (!destination) {
339
+ const canonical = doc.querySelector('link[rel="canonical"]');
340
+ if (canonical) destination = canonical.getAttribute("href");
341
+ }
342
+
343
+ if (!destination) {
344
+ const link = doc.querySelector("a[href]");
345
+ if (link) destination = link.getAttribute("href");
346
+ }
347
+
348
+ if (!destination) return null;
349
+
350
+ let destUrl;
351
+ try {
352
+ destUrl = new URL(destination, window.location.origin);
353
+ } catch {
354
+ return null;
355
+ }
356
+
357
+ if (destUrl.origin === window.location.origin) return null;
358
+ return destUrl.href;
359
+ }
360
+
313
361
  async function fetchPageDocument(pathname) {
314
362
  const cacheKey = normalizePath(pathname);
315
363
  if (pageCache.has(cacheKey)) return pageCache.get(cacheKey);
@@ -343,16 +391,27 @@
343
391
  doc = await fetchPageDocument(url.pathname);
344
392
  }
345
393
 
394
+ const pageUrl = url.pathname + url.search + url.hash;
395
+ const redirectTo = detectExternalRedirect(doc);
396
+ if (redirectTo) {
397
+ return {
398
+ kind: "redirect",
399
+ destination: redirectTo,
400
+ title: "External redirect",
401
+ pageUrl,
402
+ };
403
+ }
404
+
346
405
  const content = extractContent(doc, hash);
347
406
  if (!content) throw new Error("Section not found");
348
407
 
349
408
  const titleNode = content.querySelector("h1,h2,h3,h4,h5,h6");
350
409
  const title = titleNode ? titleNode.textContent.trim() : anchor.textContent.trim() || url.pathname;
351
- const pageUrl = url.pathname + url.search + url.hash;
352
410
 
353
411
  rewriteContentLinks(content, pageUrl);
354
412
 
355
413
  return {
414
+ kind: "content",
356
415
  content,
357
416
  title,
358
417
  pageUrl,
@@ -799,6 +858,25 @@
799
858
  setError(message) {
800
859
  contentEl.innerHTML = `<div class="jhp-hwin__error">${message}</div>`;
801
860
  },
861
+ setRedirectNotice(destination) {
862
+ contentEl.innerHTML = "";
863
+ const wrap = document.createElement("div");
864
+ wrap.className = "jhp-hwin__notice";
865
+
866
+ const label = document.createElement("p");
867
+ label.textContent = "This page redirects to an external site:";
868
+
869
+ const link = document.createElement("a");
870
+ link.href = destination;
871
+ link.target = "_blank";
872
+ link.rel = "noopener noreferrer";
873
+ link.textContent = destination;
874
+
875
+ wrap.appendChild(label);
876
+ wrap.appendChild(link);
877
+ contentEl.appendChild(wrap);
878
+ if (!rolledUp) fitWindowToContent(winEl, contentEl);
879
+ },
802
880
  setPosition(position) {
803
881
  setWindowPosition(winEl, contentEl, position);
804
882
  },
@@ -924,9 +1002,13 @@
924
1002
  return;
925
1003
  }
926
1004
 
927
- win.setContent(loaded.content);
928
1005
  win.setPageTitle(loaded.title);
929
1006
  win.el.querySelector(".jhp-hwin__btn--link").href = loaded.pageUrl;
1007
+ if (loaded.kind === "redirect") {
1008
+ win.setRedirectNotice(loaded.destination);
1009
+ } else {
1010
+ win.setContent(loaded.content);
1011
+ }
930
1012
  win.setPosition(getPositionFromEvent(evt, anchor));
931
1013
 
932
1014
  if (meta.isPermanent) {
@@ -1070,10 +1152,14 @@
1070
1152
 
1071
1153
  try {
1072
1154
  const loaded = await loadLinkContent(anchor);
1073
- win.setContent(loaded.content);
1074
1155
  win.setPageTitle(loaded.title);
1075
1156
  const followLink = win.el.querySelector(".jhp-hwin__btn--link");
1076
1157
  if (followLink) followLink.href = loaded.pageUrl;
1158
+ if (loaded.kind === "redirect") {
1159
+ win.setRedirectNotice(loaded.destination);
1160
+ } else {
1161
+ win.setContent(loaded.content);
1162
+ }
1077
1163
  win.setPosition(position);
1078
1164
  if (isPermanent) persistentUrls.add(linkKey);
1079
1165
  } catch {
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module HoverPopup
3
- VERSION = "0.3.2"
3
+ VERSION = "0.3.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-hover-popup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun