Skip to content

Commit 1f366c7

Browse files
committed
接入历史上的今天
1 parent af40e65 commit 1f366c7

File tree

3 files changed

+119
-2
lines changed

3 files changed

+119
-2
lines changed

source/_posts/每日新闻.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
---
22
title: 必应每日壁纸/每日一天文图/维基百科每日一图/每日新闻
3-
date: 2099-12-31 01:17:13
3+
date: 2099-12-31 23:59:59
44
tags:
55
cover: https://cn.bing.com/th?id=OHR.SwordFern_ZH-CN2589382288_UHD.jpg
66
top: true
77
---
88

9+
# 历史上的今天
10+
11+
<div data-today-in-history></div>
12+
13+
914
# 每日必应壁纸
1015
<img src="https://bing.biturl.top/?resolution=1920&format=image&index=0&mkt=zh-CN" />
1116

@@ -20,4 +25,4 @@ top: true
2025
# 每日新闻
2126
<div data-news60></div>
2227

23-
<img src="https://api.03c3.cn/api/zb" width=400 />
28+
<img src="https://60s.viki.moe/v2/60s?encoding=image-proxy" width=400 />

themes/butterfly/_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ inject:
847847
- <script src="/js/apod.js"></script>
848848
- <script src="/js/news60.js"></script>
849849
- <script src="/js/wikiDaily.js"></script>
850+
- <script src="/js/todayInHistory.js"></script>
850851

851852
# CDN
852853
# Don't modify the following settings unless you know how they work
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
document.addEventListener('DOMContentLoaded', () => {
2+
const containers = document.querySelectorAll('[data-today-in-history]');
3+
if (containers.length === 0) return;
4+
5+
const apiUrl = 'https://60s.viki.moe/v2/today-in-history';
6+
7+
// 渲染加载态
8+
containers.forEach(container => {
9+
container.innerHTML = `
10+
<div style="display:flex;align-items:center;justify-content:center;padding:20px;">
11+
<div style="width:28px;height:28px;border:3px solid #93c5fd;border-top-color:transparent;border-radius:50%;animation:spin 0.8s linear infinite"></div>
12+
<span style="margin-left:10px;color:#666;">正在加载历史上的今天...</span>
13+
</div>
14+
<style>@keyframes spin{to{transform:rotate(360deg)}}</style>
15+
`;
16+
});
17+
18+
fetch(apiUrl)
19+
.then(r => {
20+
if (!r.ok) throw new Error(`HTTP 错误: ${r.status}`);
21+
return r.json();
22+
})
23+
.then(json => {
24+
if (!json || json.code !== 200 || !json.data) throw new Error('接口返回异常');
25+
26+
const { date, items = [] } = json.data;
27+
const titleText = `历史上的今天 - ${date || ''}`;
28+
29+
// 事件类型不再显示标签,颜色映射移除
30+
31+
const escapeHtml = s => String(s || '')
32+
.replace(/&/g, '&amp;')
33+
.replace(/</g, '&lt;')
34+
.replace(/>/g, '&gt;')
35+
.replace(/"/g, '&quot;')
36+
.replace(/'/g, '&#39;');
37+
38+
const buildItem = item => {
39+
const year = escapeHtml(item.year);
40+
const title = escapeHtml(item.title);
41+
const desc = escapeHtml(item.description || '');
42+
const link = item.link || '#';
43+
// 不展示事件类型标签
44+
45+
return `
46+
<li style="display:flex;gap:12px;padding:12px 0;border-bottom:1px solid #eee;">
47+
<div style="flex:0 0 auto;min-width:64px;height:28px;background:#f3f4f6;border-radius:14px;display:flex;align-items:center;justify-content:center;font-weight:700;color:#374151;">${year}</div>
48+
<div style="flex:1;min-width:0;">
49+
<div style="display:flex;align-items:flex-start;gap:10px;flex-wrap:wrap;">
50+
<a class="tih-link" href="${link}" target="_blank" rel="noopener" title="点击打开链接">${title}</a>
51+
</div>
52+
${desc ? `<div style="margin-top:6px;color:#4b5563;line-height:1.75;white-space:normal;overflow:visible;text-overflow:initial;word-break:break-word;overflow-wrap:anywhere;">${desc}</div>` : ''}
53+
</div>
54+
</li>
55+
`;
56+
};
57+
58+
const listHtml = items.length
59+
? items.map(buildItem).join('')
60+
: '<div style="padding:16px;color:#6b7280;">今天暂无记录</div>';
61+
62+
const cardHtml = `
63+
<style>
64+
.tih-link{
65+
display:inline-block;
66+
font-size:1.05rem;
67+
color:#1d4ed8; /* 蓝色强调,突出可点击 */
68+
text-decoration:none;
69+
background:rgba(37,99,235,0.08);
70+
border:1px solid rgba(37,99,235,0.15);
71+
padding:2px 8px;
72+
border-radius:8px;
73+
line-height:1.4;
74+
white-space:normal;
75+
overflow:visible;
76+
text-overflow:initial;
77+
word-break:break-word;
78+
overflow-wrap:anywhere;
79+
transition:background .2s ease, box-shadow .2s ease, color .2s ease;
80+
}
81+
.tih-link:hover{
82+
background:rgba(37,99,235,0.14);
83+
box-shadow:0 2px 10px rgba(37,99,235,0.18);
84+
text-decoration:underline;
85+
}
86+
.tih-link:focus-visible{
87+
outline:none;
88+
box-shadow:0 0 0 3px rgba(37,99,235,0.28);
89+
}
90+
</style>
91+
<div style="max-width:900px;margin:16px auto;padding:18px 20px;background:#fff;border-radius:12px;box-shadow:0 8px 24px rgba(149,157,165,0.2);">
92+
<div style="display:flex;align-items:center;justify-content:flex-start;margin-bottom:10px;">
93+
<h2 style="margin:0;font-size:20px;color:#111827;">${titleText}</h2>
94+
</div>
95+
<ol style="list-style:none;padding:0;margin:0;">${listHtml}</ol>
96+
</div>
97+
`;
98+
99+
containers.forEach(c => c.innerHTML = cardHtml);
100+
})
101+
.catch(err => {
102+
const errorHtml = `
103+
<div style="color:#b91c1c;padding:15px;background:#fee2e2;border-left:4px solid #ef4444;border-radius:8px;">
104+
加载历史上的今天失败: ${err.message}
105+
</div>
106+
`;
107+
containers.forEach(c => c.innerHTML = errorHtml);
108+
});
109+
});
110+
111+

0 commit comments

Comments
 (0)