-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
147 lines (138 loc) · 4.96 KB
/
index.html
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
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OneSDK Documentation</title>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dompurify/dist/purify.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/components/prism-core.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/plugins/autoloader/prism-autoloader.min.js"></script>
<style>
body {
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";
line-height: 1.6;
color: #24292e;
display: flex;
margin: 0;
padding: 0;
}
#sidebar {
width: 250px;
height: 100vh;
overflow-y: auto;
padding: 20px;
background-color: #f6f8fa;
position: fixed;
left: 0;
top: 0;
border-right: 1px solid #e1e4e8;
}
#content {
margin-left: 290px; /* Increased to prevent overlap */
padding: 20px;
max-width: 800px;
width: calc(100% - 290px);
}
#sidebar ul {
list-style-type: none;
padding: 0;
}
#sidebar ul li {
margin-bottom: 10px;
}
#sidebar ul li a {
text-decoration: none;
color: #0366d6;
}
#sidebar ul li a:hover {
text-decoration: underline;
}
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
/* Override table styles */
.markdown-body table {
display: table;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
overflow: auto;
}
.markdown-body table th,
.markdown-body table td {
padding: 6px 13px;
border: 1px solid #dfe2e5;
}
.markdown-body table tr {
background-color: #fff;
border-top: 1px solid #c6cbd1;
}
.markdown-body table tr:nth-child(2n) {
background-color: #f6f8fa;
}
</style>
</head>
<body>
<div id="sidebar"></div>
<div id="content" class="markdown-body"></div>
<script>
const contentDiv = document.getElementById('content');
const sidebarDiv = document.getElementById('sidebar');
let markdownFile = 'README.md';
// 检查 URL 中是否有指定的文件
const urlParams = new URLSearchParams(window.location.search);
const file = urlParams.get('file');
if (file) {
markdownFile = 'docs/' + file; // 添加 'docs/' 前缀
}
fetch(markdownFile)
.then(response => response.text())
.then(markdown => {
contentDiv.innerHTML = DOMPurify.sanitize(marked.parse(markdown));
// 修改所有链接
document.querySelectorAll('#content a').forEach(link => {
if (link.href.endsWith('.md')) {
const fileName = link.href.split('/').pop();
link.href = '?file=' + fileName;
}
});
// 代码高亮
Prism.highlightAll();
// 生成目录
generateTableOfContents();
})
.catch(error => {
contentDiv.innerHTML = `<p>Error loading markdown: ${error}</p>`;
});
function generateTableOfContents() {
const headings = contentDiv.querySelectorAll('h1, h2, h3');
const toc = document.createElement('ul');
headings.forEach((heading, index) => {
const li = document.createElement('li');
const a = document.createElement('a');
a.textContent = heading.textContent;
a.href = `#heading-${index}`;
a.style.paddingLeft = `${(heading.tagName.charAt(1) - 1) * 20}px`;
li.appendChild(a);
toc.appendChild(li);
// 为每个标题添加 id
heading.id = `heading-${index}`;
});
sidebarDiv.innerHTML = '<h2>Table of Contents</h2>';
sidebarDiv.appendChild(toc);
}
</script>
</body>
</html>