From ed5ba1d5a91290d26aae672848c74f51078083f7 Mon Sep 17 00:00:00 2001 From: kifuan Date: Sun, 14 May 2023 17:56:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9D=9E=20`random`=20=E6=97=B6?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layout/includes/page/flink.pug | 119 ++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 45 deletions(-) diff --git a/layout/includes/page/flink.pug b/layout/includes/page/flink.pug index ee4e1a2..e34f158 100644 --- a/layout/includes/page/flink.pug +++ b/layout/includes/page/flink.pug @@ -1,50 +1,79 @@ #article-container .flink - script. - (()=>{ - const replaceSymbol = (str) => { - return str.replace(/[\p{P}\p{S}]/gu, "-") - } - - let result = "" - function add(str) { - for(let i = 0; i < str.length; i++){ - const replaceClassName = replaceSymbol(str[i].class_name) - const className = str[i].class_name ? `

${str[i].class_name}

` : "" - const classDesc = str[i].class_desc ? `` : "" - - let listResult = "" - const lists = str[i].link_list - if (!{page.random === true}) { - lists.sort(() => Math.random() - 0.5) - } - for(let j = 0; j < lists.length; j++){ - listResult += ` - ` - } - - result += `${className}${classDesc} ` + - let pageContent = page.content + if page.flink_url || page.random + script. + (()=>{ + const replaceSymbol = (str) => { + return str.replace(/[\p{P}\p{S}]/gu, "-") } - document.querySelector(".flink").insertAdjacentHTML("afterbegin", result) - window.lazyLoadInstance && window.lazyLoadInstance.update() - } + let result = "" + const add = (str) => { + for(let i = 0; i < str.length; i++){ + const replaceClassName = replaceSymbol(str[i].class_name) + const className = str[i].class_name ? `

${str[i].class_name}

` : "" + const classDesc = str[i].class_desc ? `` : "" - const linkData = !{JSON.stringify(site.data.link)} - if ("!{page.flink_url}") { - fetch("!{url_for(page.flink_url)}") - .then(response => response.json()) - .then(add) - } else if (linkData) { - add(linkData) - } - })() - != page.content + let listResult = "" + const lists = str[i].link_list + if (!{page.random === true}) { + lists.sort(() => Math.random() - 0.5) + } + for(let j = 0; j < lists.length; j++){ + listResult += ` + ` + } + + result += `${className}${classDesc} ` + } + + document.querySelector(".flink").insertAdjacentHTML("afterbegin", result) + window.lazyLoadInstance && window.lazyLoadInstance.update() + } + + const linkData = !{JSON.stringify(site.data.link)} + if ("!{page.flink_url}") { + fetch("!{url_for(page.flink_url)}") + .then(response => response.json()) + .then(add) + } else if (linkData) { + add(linkData) + } + })() + + else + if site.data.link + - let result = "" + each i in site.data.link + - let className = i.class_name ? markdown(`## ${i.class_name}`) : "" + - let classDesc = i.class_desc ? `` : "" + + - let listResult = "" + + each j in i.link_list + - + listResult += ` + ` + - + + - result += `${className}${classDesc} ` + + - pageContent = result + pageContent + != pageContent