-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
135 lines (124 loc) · 6 KB
/
index.html
File metadata and controls
135 lines (124 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI 人工智能 </title>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<style>
:root { --sidebar-w: 280px; --theme-color: #3498db; --bg-light: #f8f9fb; --border-color: #eaecef; }
body { margin: 0; font-family: "Segoe UI", sans-serif; display: flex; height: 100vh; overflow: hidden; }
/* 侧边栏 */
#sidebar { width: var(--sidebar-w); background: var(--bg-light); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header { padding: 25px; border-bottom: 1px solid var(--border-color); }
.logo { font-size: 24px; font-weight: bold; }
.logo span { color: var(--theme-color); }
.menu-container { flex: 1; overflow-y: auto; padding: 15px; }
.group-box { margin-bottom: 20px; }
.group-title { font-size: 12px; color: #999; margin: 10px 0 5px 10px; font-weight: bold; text-transform: uppercase; }
.menu-item {
padding: 10px 15px; margin: 2px 0; cursor: pointer; border-radius: 8px;
font-size: 14px; display: flex; align-items: center; color: #444; transition: 0.2s;
}
.menu-item:hover { background: #edf2f7; color: var(--theme-color); }
.menu-item.active { background: #e3f2fd; color: var(--theme-color); font-weight: bold; }
.menu-item i { margin-right: 10px; font-size: 14px; opacity: 0.7; }
/* 内容区 */
#content { flex: 1; overflow-y: auto; padding: 40px 60px; background: #fff; scroll-behavior: smooth; }
.markdown-body { line-height: 1.8; max-width: 850px; margin: 0 auto; font-size: 16px; }
.markdown-body h1 { border-bottom: 2px solid var(--border-color); padding-bottom: 10px; }
.markdown-body img { max-width: 100%; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.loading-tip { text-align: center; color: #999; margin-top: 50px; }
</style>
</head>
<body>
<div id="app" style="display: flex; width: 100%;">
<aside id="sidebar">
<div class="sidebar-header">
<div class="logo"><span>AI</span> 人工智能 </div>
</div>
<nav class="menu-container">
<div v-for="group in structuredList" :key="group.name" class="group-box">
<div class="group-title">{{ group.name }}</div>
<div
v-for="item in group.items"
:key="item.path"
:class="['menu-item', { active: currentPath === item.path }]"
@click="loadMarkdown(item.path)"
>
<i class="fa-regular fa-file-lines"></i>
<span>{{ item.title }}</span>
</div>
</div>
</nav>
</aside>
<main id="content">
<div v-if="loading" class="loading-tip"><i class="fa fa-spinner fa-spin"></i> 正在读取...</div>
<article v-else class="markdown-body" v-html="renderedHTML"></article>
</main>
</div>
<script>
new Vue({
el: '#app',
data: {
structuredList: [], // 解析后的结构化列表
currentPath: '', // 当前完整路径
renderedHTML: '',
loading: false
},
methods: {
async fetchList() {
try {
const response = await fetch('./posts/list.txt?t=' + Date.now());
const text = await response.text();
const lines = text.split('\n').map(l => l.trim()).filter(l => l.length > 0);
let currentGroup = { name: '默认分组', items: [] };
const groups = [currentGroup];
lines.forEach(line => {
if (line.startsWith('#')) {
// 发现新分组
if (currentGroup.items.length === 0) {
currentGroup.name = line.replace('#', '').trim();
} else {
currentGroup = { name: line.replace('#', '').trim(), items: [] };
groups.push(currentGroup);
}
} else {
// 发现文件路径
const fileName = line.split('/').pop();
currentGroup.items.push({
title: fileName.replace('.md', '').replace(/_/g, ' '),
path: line
});
}
});
this.structuredList = groups.filter(g => g.items.length > 0);
if (this.structuredList.length > 0) {
this.loadMarkdown(this.structuredList[0].items[0].path);
}
} catch (err) {
this.renderedHTML = `<h1>配置加载失败</h1><p>请检查 posts/list.txt</p>`;
}
},
async loadMarkdown(path) {
this.currentPath = path;
this.loading = true;
try {
const response = await fetch(`./posts/${path}`);
const text = await response.text();
this.renderedHTML = marked.parse(text);
document.getElementById('content').scrollTop = 0;
} catch (err) {
this.renderedHTML = `<h1>读取失败</h1><p>路径不存在: posts/${path}</p>`;
} finally {
this.loading = false;
}
}
},
mounted() { this.fetchList(); }
});
</script>
</body>
</html>