119 lines
3.8 KiB
HTML
119 lines
3.8 KiB
HTML
{{ define "main" }}
|
|
<div id="pjax-container">
|
|
<style>
|
|
.links ul>li {
|
|
position: relative;
|
|
padding-left: 1.75em;
|
|
}
|
|
|
|
.links a {
|
|
color: var(--link-color-light);
|
|
font-weight: 500;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.links li {
|
|
margin-top: .5em;
|
|
margin-bottom: .5em;
|
|
}
|
|
|
|
.links ul>li:before {
|
|
content: "";
|
|
position: absolute;
|
|
background-color: #d1d5db;
|
|
border-radius: 50%;
|
|
width: .375em;
|
|
height: .375em;
|
|
top: .6875em;
|
|
left: .25em;
|
|
}
|
|
|
|
.url-name {
|
|
position: relative;
|
|
display: inline-block;
|
|
}
|
|
|
|
.url-name::before {
|
|
content: "";
|
|
position: absolute;
|
|
height: 12px;
|
|
bottom: 3px;
|
|
left: -4px;
|
|
z-index: -1;
|
|
background-color: #5d5d5d;
|
|
opacity: .3;
|
|
transform: skew(-35deg);
|
|
transition: opacity .2s ease;
|
|
border-radius: 3px 8px 10px 6px;
|
|
transition: 0.1s ease background-color;
|
|
width: 112%;
|
|
/* 宽度根据a标签的内容动态变化 */
|
|
}
|
|
|
|
.url-name:hover::before {
|
|
opacity: 0.5;
|
|
/* 鼠标悬浮时可以改变不透明度 */
|
|
}
|
|
|
|
[data-theme="dark"] .links a {
|
|
color: var(--link-color-dark);
|
|
}
|
|
|
|
[data-theme="dark"] .url-name::before {
|
|
background-color: #e5e7eb;
|
|
opacity: 0.18;
|
|
}
|
|
|
|
[data-theme="dark"] .url-name:hover::before {
|
|
opacity: 0.35;
|
|
}
|
|
</style>
|
|
<div class="post-content" itemprop="articleBody">
|
|
<div class="links">
|
|
<ul id="links-list" uk-scrollspy="target: > li; cls: uk-animation-slide-bottom-small; delay: 0">
|
|
<!-- 静态生成的内容作为 SEO 兜底或构建时数据 -->
|
|
{{ range site.Data.links.blogs }}
|
|
<li><a href="{{ .url }}" class="url-name" target="_blank">{{ .name }}</a><span style="margin-left: 13px;">{{ .description }}</span></li>
|
|
{{ end }}
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
(function() {
|
|
// 配置:友链数据源地址
|
|
// 1. 本地模块模式:使用 '/json/link_lite.json' (默认)
|
|
// 2. 远程模式:修改为您的 GitHub + jsDelivr 链接
|
|
// 例如:const linksJsonUrl = 'https://cdn.jsdelivr.net/gh/您的用户名/您的仓库名@main/link_lite.json';
|
|
const linksJsonUrl = '/json/link_lite.json';
|
|
|
|
const list = document.getElementById('links-list');
|
|
if (!list) 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) {
|
|
// 清空现有的静态内容,使用动态数据
|
|
list.innerHTML = '';
|
|
|
|
data.forEach(item => {
|
|
const li = document.createElement('li');
|
|
// 保持原有的 DOM 结构和类名
|
|
li.innerHTML = `<a href="${item.url}" class="url-name" target="_blank">${item.name}</a><span style="margin-left: 13px;">${item.description || ''}</span>`;
|
|
list.appendChild(li);
|
|
});
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.warn('友链动态加载失败,回退到静态内容:', error);
|
|
// 加载失败时保留静态内容 (Hugo 生成的)
|
|
});
|
|
})();
|
|
</script>
|
|
</div>
|
|
{{ end }}
|