jekyll-hover-popup 0.3.0 → 0.3.1

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: cdae0cb64015858986ffe6c6dc11d44947b4e172dee08bccd68d191230416b26
4
- data.tar.gz: af148150f8a1890b082adbccc2c4665a56dacbad3eea581608dd02c0cbee8f36
3
+ metadata.gz: d904538318970368b8ae375e4e1296000b2e9a88a25ccbfd7273846cbc42d21b
4
+ data.tar.gz: e212207697ebb5f6f5a2474078276d242a3b3c6902461473ec9e68f6dac4d818
5
5
  SHA512:
6
- metadata.gz: a3192b0edd3563b6b267740ca86eff70b040b269d30aff9005366902be46d6f11026644757ea3f010296aa610f91f4969426e82c0bb1860ed473b7ed0cd07f44
7
- data.tar.gz: 203ad982a1a4dd62680ee9798179a224835fca23322b2744e1239d09dfcce0ac8a63e63e574f90a58acf893a43cd69204015160ba37d229b2d5d1a9f40076d30
6
+ metadata.gz: a1006d757734f03fe07bc223c1feb50ce98e4e557a5f5e4a39cfaba9403865bf1218fb99e332bc7e7cb98bad98e1b084d6dd6ceb5b121ecdcc39c1335ae74e6b
7
+ data.tar.gz: 8bf2a9bb8af64ababe2c3af6eed644c5ef16a3f2365da453966d0068270cac9c366109c518caad6aedd1b2cddb32671e05c4862e37e81d4ccdf8fe3759fbd83c
@@ -128,10 +128,16 @@
128
128
  });
129
129
  }
130
130
 
131
+ function stripHtmlExtension(pathname) {
132
+ return pathname.replace(/\.html?$/i, "");
133
+ }
134
+
131
135
  function normalizePath(pathname) {
132
136
  if (!pathname) return "/";
133
- const normalized = pathname.endsWith("/") ? pathname : `${pathname}/`;
134
- return normalized;
137
+ // Treat /page.html and /page/ as the same document for cache/same-page checks.
138
+ let path = stripHtmlExtension(pathname);
139
+ if (!path.endsWith("/")) path = `${path}/`;
140
+ return path || "/";
135
141
  }
136
142
 
137
143
  function normalizeLinkKey(url) {
@@ -145,6 +151,30 @@
145
151
  );
146
152
  }
147
153
 
154
+ // Prefer paths that static hosts (esp. Cloudflare Pages) resolve correctly.
155
+ // Never request `page.html/` — that often SPA-fallbacks to the site index.
156
+ function fetchPathCandidates(pathname) {
157
+ const paths = [];
158
+ const push = (p) => {
159
+ if (p && !paths.includes(p)) paths.push(p);
160
+ };
161
+
162
+ if (/\.html?$/i.test(pathname)) {
163
+ push(pathname);
164
+ const withoutExt = stripHtmlExtension(pathname) || "/";
165
+ push(withoutExt);
166
+ if (!withoutExt.endsWith("/")) push(`${withoutExt}/`);
167
+ return paths;
168
+ }
169
+
170
+ const withSlash = pathname.endsWith("/") ? pathname : `${pathname}/`;
171
+ const withoutSlash = pathname.endsWith("/") ? pathname.replace(/\/+$/, "") || "/" : pathname;
172
+ push(withSlash);
173
+ push(withoutSlash);
174
+ if (withoutSlash !== "/") push(`${withoutSlash}.html`);
175
+ return paths;
176
+ }
177
+
148
178
  function isImagePath(pathname) {
149
179
  return /\.(avif|bmp|gif|ico|jpe?g|png|svg|webp)$/i.test(pathname);
150
180
  }
@@ -281,30 +311,25 @@
281
311
  }
282
312
 
283
313
  async function fetchPageDocument(pathname) {
284
- const cacheKey = pathname.endsWith("/") ? pathname : `${pathname}/`;
314
+ const cacheKey = normalizePath(pathname);
285
315
  if (pageCache.has(cacheKey)) return pageCache.get(cacheKey);
286
316
 
287
- const fetchPath = cacheKey;
288
- const response = await fetch(fetchPath, { credentials: "same-origin" });
289
- if (!response.ok) {
290
- const fallback = pathname.endsWith("/") ? pathname.slice(0, -1) : `${pathname}/`;
291
- if (fallback !== fetchPath) {
292
- const retry = await fetch(fallback, { credentials: "same-origin" });
293
- if (retry.ok) {
294
- const html = await retry.text();
295
- const doc = new DOMParser().parseFromString(html, "text/html");
296
- pageCache.set(cacheKey, doc);
297
- pageCache.set(fallback, doc);
298
- return doc;
299
- }
317
+ let lastError;
318
+ for (const fetchPath of fetchPathCandidates(pathname)) {
319
+ try {
320
+ const response = await fetch(fetchPath, { credentials: "same-origin" });
321
+ if (!response.ok) continue;
322
+
323
+ const html = await response.text();
324
+ const doc = new DOMParser().parseFromString(html, "text/html");
325
+ pageCache.set(cacheKey, doc);
326
+ return doc;
327
+ } catch (err) {
328
+ lastError = err;
300
329
  }
301
- throw new Error(`Failed to load ${fetchPath}`);
302
330
  }
303
331
 
304
- const html = await response.text();
305
- const doc = new DOMParser().parseFromString(html, "text/html");
306
- pageCache.set(cacheKey, doc);
307
- return doc;
332
+ throw lastError || new Error(`Failed to load ${pathname}`);
308
333
  }
309
334
 
310
335
  async function loadLinkContent(anchor) {
@@ -312,7 +337,7 @@
312
337
  const hash = url.hash;
313
338
 
314
339
  let doc;
315
- if (url.pathname === window.location.pathname && url.search === window.location.search) {
340
+ if (isSamePage(url)) {
316
341
  doc = document;
317
342
  } else {
318
343
  doc = await fetchPageDocument(url.pathname);
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module HoverPopup
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - directsun