Skip to content

Commit 2f5269a

Browse files
committed
feat: 适配“无效友链”
添加无效友链功能,用于展示当前不可访问的友链。 TODO: “无效友链”默认折叠,点击展示更多
1 parent 09bfe58 commit 2f5269a

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

_config.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,18 @@ links:
10471047
avatar: "/img/favicon.png"
10481048
}
10491049

1050+
# 失效/未激活的友链
1051+
inactive:
1052+
enable: false
1053+
label: "异常友链 | 长时间不可访问站点"
1054+
inactiveItems:
1055+
- {
1056+
title: "404 Links",
1057+
intro: "404 Links",
1058+
link: "https://hexo.fluid-dev.com/404",
1059+
avatar: "/img/favicon.png"
1060+
}
1061+
10501062
# 当成员头像加载失败时,替换为指定图片
10511063
# When the member avatar fails to load, replace the specified image
10521064
onerror_avatar: /img/avatar.png

layout/links.ejs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ page.comment = theme.links.comments.type
1212
<% for(const each of theme.links.items || []) { %>
1313
<% if (!each.title || !each.link) continue %>
1414
<div class="card col-lg-4 col-md-6 col-sm-12">
15-
<a href="<%= url_for(each.link) %>" class="card-body hover-with-bg" target="_blank" rel="noopener">
15+
<a href="<%= url_for(each.link) %>" class="card-body hover-with-bg" target="_blank" rel="noopener" aria-label="<%= `访问 ${each.title}` %>">
1616
<div class="card-content">
1717
<% if (each.avatar || each.image) { %>
1818
<div class="link-avatar my-auto">
1919
<img src="<%= url_for(each.avatar || each.image) %>" alt="<%= each.title %>"
20+
loading="lazy"
2021
onerror="this.onerror=null; this.src=this.srcset='<%= url_for(theme.links.onerror_avatar) %>'"/>
2122
</div>
2223
<% } %>
@@ -30,6 +31,37 @@ page.comment = theme.links.comments.type
3031
<% } %>
3132
</div>
3233

34+
<% if (theme.links.inactive && theme.links.inactive.enable && theme.links.inactive.inactiveItems) { %>
35+
<hr/>
36+
<% if (theme.links.inactive.label) { %>
37+
<p class="inactive-label"><%- theme.links.inactive.label %></p>
38+
<% } %>
39+
40+
<div class="row links">
41+
<% for(const item of theme.links.inactive.inactiveItems || []) { %>
42+
<% if (!item.title || !item.link) continue %>
43+
<div class="card col-lg-4 col-md-6 col-sm-12">
44+
<a href="<%= url_for(item.link) %>" class="card-body hover-with-bg" target="_blank" rel="noopener" aria-label="<%= `访问 ${item.title}` %>">
45+
<div class="card-content">
46+
<% if (item.avatar || item.image) { %>
47+
<div class="link-avatar my-auto">
48+
<img src="<%= url_for(item.avatar || item.image) %>" alt="<%= item.title %>"
49+
loading="lazy"
50+
onerror="this.onerror=null; this.src=this.srcset='<%= url_for(theme.links.onerror_avatar) %>'"/>
51+
</div>
52+
<% } %>
53+
<div class="link-text">
54+
<div class="link-title"><%- item.title %></div>
55+
<div class="link-intro"><%- item.intro || '' %></div>
56+
</div>
57+
</div>
58+
</a>
59+
</div>
60+
<% } %>
61+
</div>
62+
<% } %>
63+
64+
3365
<% if(theme.links.custom && theme.links.custom.enable && theme.links.custom.content) { %>
3466
<!-- Custom -->
3567
<div class="custom mx-auto">

0 commit comments

Comments
 (0)