From e995dbf8b10fb1bdfdb46d6bdadc722140ce114f Mon Sep 17 00:00:00 2001 From: luckyasme <807254037@qq.com> Date: Thu, 6 Mar 2025 20:04:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=8B=E4=B8=80?= =?UTF-8?q?=E9=A1=B5=E6=97=A0=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/partials/scripts.html | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 5332d1574..b7db0cbd2 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -88,6 +88,18 @@ } } } + function getNextOrPrevHref(arr, startIndex, step) { + let i = startIndex; + let href = arr[i].href; + while (href == null && i > 0 && i < arr.length) { + i += step; + if (i > 0 && i < arr.length) { + href = arr[i].href; + } + } + + return href; + } // 获取上一页、下一页 function nextAndPevious(arr, id) { for (var i = 0; i < arr.length; i++) { @@ -95,12 +107,14 @@ if (i === 0) { result.push(null); } else { - result.push(arr[i - 1].href); + const hrefPrev = getNextOrPrevHref(arr, i - 1, -1); + result.push(hrefPrev); } if (i === arr.length - 1) { result.push(null); } else { - result.push(arr[i + 1].href); + const hrefNext = getNextOrPrevHref(arr, i + 1, 1); + result.push(hrefNext); } } } -- Gitee