jekyll-hover-popup 0.3.0 → 0.3.2
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 +4 -4
- data/assets/jekyll-hover-popup/hover_popup.js +47 -22
- data/lib/jekyll/hover_popup/hooks.rb +16 -2
- data/lib/jekyll/hover_popup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bb537e34ef0aa3bb1f5396179b65f549533f3c670cd4dffcd581f3b727c355c2
|
|
4
|
+
data.tar.gz: 552f8704d5da719123714a6f9bb22c8921ec38131a16f3c8d5d36bf5fcbbb8fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03eb03b79e05fa4b829562d5f11ebbf270e2b6e35fb8f61f0f4f45474fd580556795d4eceee5f8e53f5cf62d4f3e496aae0fd5a13b09d6726e1d0602f158bd43
|
|
7
|
+
data.tar.gz: 02e9f34463fdbaf23c1c3b2c231096d3e09d2853ce6b7aeaa27c780a65dd2cb75977b2cb3431cb95d773f2f73ad1b8deb6bbfa5d4a7bb20248de5f8083fd07c5
|
|
@@ -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
|
-
|
|
134
|
-
|
|
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
|
|
314
|
+
const cacheKey = normalizePath(pathname);
|
|
285
315
|
if (pageCache.has(cacheKey)) return pageCache.get(cacheKey);
|
|
286
316
|
|
|
287
|
-
|
|
288
|
-
const
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
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
|
|
340
|
+
if (isSamePage(url)) {
|
|
316
341
|
doc = document;
|
|
317
342
|
} else {
|
|
318
343
|
doc = await fetchPageDocument(url.pathname);
|
|
@@ -8,8 +8,7 @@ module Jekyll
|
|
|
8
8
|
next if cfg["enabled"] == false
|
|
9
9
|
next unless doc.respond_to?(:output_ext) && doc.output_ext == ".html"
|
|
10
10
|
|
|
11
|
-
assets_path = cfg
|
|
12
|
-
assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
|
|
11
|
+
assets_path = resolve_assets_path(site, cfg)
|
|
13
12
|
hover_delay_ms = cfg["hover_delay_ms"] || 0
|
|
14
13
|
nav_hover_preview = cfg.fetch("nav_hover_preview", false)
|
|
15
14
|
|
|
@@ -21,6 +20,21 @@ module Jekyll
|
|
|
21
20
|
end
|
|
22
21
|
end
|
|
23
22
|
|
|
23
|
+
# Site-root path (e.g. "/assets/jekyll-hover-popup"), with site.baseurl prepended.
|
|
24
|
+
def self.resolve_assets_path(site, cfg)
|
|
25
|
+
assets_path = cfg["assets_path"] || "/assets/jekyll-hover-popup"
|
|
26
|
+
assets_path = "/#{assets_path}" unless assets_path.start_with?("/")
|
|
27
|
+
|
|
28
|
+
baseurl = site.config["baseurl"].to_s
|
|
29
|
+
baseurl = "" if baseurl == "/"
|
|
30
|
+
baseurl = baseurl.chomp("/")
|
|
31
|
+
|
|
32
|
+
return assets_path if baseurl.empty?
|
|
33
|
+
return assets_path if assets_path == baseurl || assets_path.start_with?("#{baseurl}/")
|
|
34
|
+
|
|
35
|
+
"#{baseurl}#{assets_path}"
|
|
36
|
+
end
|
|
37
|
+
|
|
24
38
|
def self.inject_assets(html, assets_path:, hover_delay_ms:, nav_hover_preview: false)
|
|
25
39
|
return html if html.include?('data-hover-popup-root="true"')
|
|
26
40
|
|