Skip to content

Commit 3a0aeb3

Browse files
author
y-yamasaki
committed
Merge branch 'develop'
2 parents 87b3bca + 98b7121 commit 3a0aeb3

39 files changed

Lines changed: 296 additions & 104 deletions

WebSite/assets/js/blog.js

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,22 @@ document.addEventListener("DOMContentLoaded", () => {
266266
}
267267

268268
function createAndAppendCard(post) {
269-
const card = document.createElement("article");
269+
// If a contentPath exists, use an anchor so preview.js can detect links.
270+
// Otherwise, fall back to an article element for non-clickable cards.
271+
const isLink = !!post.contentPath;
272+
const card = isLink
273+
? document.createElement("a")
274+
: document.createElement("article");
275+
276+
// Preserve existing class names
270277
card.className = "card card--clickable blog-card";
271278

279+
if (isLink) {
280+
card.setAttribute("href", post.contentPath);
281+
// Optionally allow opening in same tab; preview.js intercepts long-press.
282+
card.setAttribute("role", "link");
283+
}
284+
272285
if (post.thumbnail) {
273286
const thumb = document.createElement("div");
274287
thumb.className = "card__thumb";
@@ -317,8 +330,30 @@ document.addEventListener("DOMContentLoaded", () => {
317330
const tag = document.createElement("span");
318331
tag.className = "tag";
319332
tag.textContent = t;
333+
334+
// Prevent navigation when pressing a tag (pointer/touch) so the card anchor doesn't activate.
335+
// Keep the click handler for filtering behavior.
336+
try {
337+
const onTagPrevent = (ev) => {
338+
try {
339+
ev.preventDefault && ev.preventDefault();
340+
ev.stopPropagation && ev.stopPropagation();
341+
} catch (_) {}
342+
};
343+
tag.addEventListener(
344+
"pointerdown",
345+
onTagPrevent,
346+
{ passive: false },
347+
);
348+
tag.addEventListener("touchstart", onTagPrevent, {
349+
passive: false,
350+
});
351+
} catch (_) {}
320352
tag.addEventListener("click", (e) => {
321-
e.stopPropagation();
353+
try {
354+
e.stopPropagation && e.stopPropagation();
355+
e.preventDefault && e.preventDefault();
356+
} catch (_) {}
322357
if (searchInput) searchInput.value = t;
323358
if (categorySelect) categorySelect.value = "";
324359
currentPage = 1;
@@ -330,10 +365,17 @@ document.addEventListener("DOMContentLoaded", () => {
330365
}
331366

332367
card.appendChild(body);
333-
card.addEventListener("click", () => {
334-
if (post.contentPath)
335-
window.location.href = post.contentPath;
336-
});
368+
// If not using an anchor, fall back to click handler for navigation.
369+
if (!isLink) {
370+
card.addEventListener("click", () => {
371+
if (post.contentPath) {
372+
window.location.href = post.contentPath;
373+
}
374+
});
375+
} else {
376+
// For anchors, optionally prevent middle-click/ctrl-click handling here if needed.
377+
// Keep default behavior for normal clicks (navigation) but preview.js handles long-press.
378+
}
337379
listEl.appendChild(card);
338380
}
339381

0 commit comments

Comments
 (0)