diff --git a/layout/includes/page/flink.pug b/layout/includes/page/flink.pug
index 549b67a..10d3893 100644
--- a/layout/includes/page/flink.pug
+++ b/layout/includes/page/flink.pug
@@ -1,7 +1,10 @@
#article-container
.flink
- - let pageContent = page.content
- if page.flink_url
+ - let { content, random, flink_url } = page
+ - let pageContent = content
+
+ if flink_url || random
+ - const linkData = flink_url ? false : site.data.link || false
script.
(()=>{
const replaceSymbol = (str) => {
@@ -9,35 +12,45 @@
}
let result = ""
- fetch("!{url_for(page.flink_url)}")
- .then(response => response.json())
- .then(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 ? `${str[i].class_desc}
` : ""
-
- let listResult = ""
- const lists = str[i].link_list
- for(let j = 0; j < lists.length; j++){
- listResult += `
- `
- }
+ 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 ? `${str[i].class_desc}
` : ""
- result += `${className}${classDesc} ${listResult}
`
+ let listResult = ""
+ const lists = str[i].link_list
+ if (!{random === true}) {
+ lists.sort(() => Math.random() - 0.5)
+ }
+ for(let j = 0; j < lists.length; j++){
+ listResult += `
+ `
}
- document.querySelector(".flink").insertAdjacentHTML("afterbegin", result)
- window.lazyLoadInstance && window.lazyLoadInstance.update()
- })
+ result += `${className}${classDesc} ${listResult}
`
+ }
+
+ document.querySelector(".flink").insertAdjacentHTML("afterbegin", result)
+ window.lazyLoadInstance && window.lazyLoadInstance.update()
+ }
+
+ const linkData = !{JSON.stringify(linkData)}
+ if (!{Boolean(flink_url)}) {
+ fetch("!{url_for(flink_url)}")
+ .then(response => response.json())
+ .then(add)
+ } else if (linkData) {
+ add(linkData)
+ }
})()
else
@@ -67,4 +80,3 @@
- pageContent = result + pageContent
!= pageContent
-