added:友联本地和远程重写逻辑
This commit is contained in:
1 parent
c83c28fb9c
commit
c7e2f77893
4 files changed
+472
-4
No files matched your search
@@ -1,7 +1,8 @@
|
||||
{{ define "main" }}
|
||||
<div id="pjax-container">
|
||||
<div class="post-content" itemprop="articleBody">
|
||||
<div class="items" uk-scrollspy="target: > .item-box; cls: uk-animation-slide-bottom-small; delay: 0">
|
||||
<div id="links-container" class="items" uk-scrollspy="target: > .item-box; cls: uk-animation-slide-bottom-small; delay: 0">
|
||||
<!-- 静态生成的内容作为 SEO 兜底或构建时数据 -->
|
||||
{{ range site.Data.links.blogs }}
|
||||
<div class="item-box">
|
||||
<div class="website-img">
|
||||
@@ -24,5 +25,55 @@
|
||||
</div>
|
||||
<div style="clear:both;"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
// 配置:友链数据源地址 (与 new-links-lite.html 保持一致)
|
||||
// 1. 本地模块模式:使用 '/json/link_lite.json' (默认)
|
||||
// 2. 远程模式:修改为您的 GitHub + jsDelivr 链接
|
||||
const linksJsonUrl = '/json/link_lite.json';
|
||||
|
||||
const container = document.getElementById('links-container');
|
||||
if (!container) return;
|
||||
|
||||
fetch(linksJsonUrl)
|
||||
.then(response => {
|
||||
if (!response.ok) throw new Error('Network response was not ok');
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
if (data && Array.isArray(data) && data.length > 0) {
|
||||
// 清空现有的静态内容,使用动态数据
|
||||
container.innerHTML = '';
|
||||
|
||||
data.forEach(item => {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'item-box';
|
||||
div.innerHTML = `
|
||||
<div class="website-img">
|
||||
<img src="https://s0.wp.com/mshots/v1/${item.url}?w=800&h=600" alt="${item.name}">
|
||||
</div>
|
||||
<div class="link-info">
|
||||
<div class="link-avatar">
|
||||
<img src="${item.image}" alt="${item.name}">
|
||||
</div>
|
||||
<div class="link-des">
|
||||
<div class="link-name">${item.name}</div>
|
||||
<div class="link-des" style="color: #64748B;">${item.description || ''}</div>
|
||||
</div>
|
||||
</div>
|
||||
<a href="${item.url}" target="_blank">
|
||||
<div class="website-go-button">逛一逛</div>
|
||||
</a>
|
||||
`;
|
||||
container.appendChild(div);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.warn('友链动态加载失败,回退到静态内容:', error);
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
{{ end }}
|
||||
Reference in new issue
Block a user