forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
198 lines (184 loc) · 7.18 KB
/
main.js
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
const isEn = () => location.hash.includes('README_EN');
const isRoot = () => ['', '#/', '#/README', '#/README_EN'].includes(location.hash);
const sidebar = () => (isRoot() ? false : isEn() ? 'summary_en.md' : 'summary.md');
const cleanedHtml = html => {
return html.replace(/<pre>([\s\S]*?)<\/pre>/g, (_, group) => {
return '<pre>' + group.replace(/<code>([\s\S]*?)<\/code>/g, '$1') + '</pre>';
});
};
const getLang = () => (isEn() ? 'en' : 'zh-CN');
const giscusTheme = () =>
localStorage.getItem('DARK_LIGHT_THEME') === 'light' ? 'light' : 'noborder_dark';
const getTerm = () => decodeURI(location.hash.slice(1, location.hash.lastIndexOf('/')) || '/index');
window.addEventListener('hashchange', () => {
window.$docsify.loadSidebar = sidebar();
});
window.$docsify = {
name: 'leetcode',
repo: 'doocs/leetcode',
lastModifiedText: {
'/README_EN': 'Last updated: ',
'/': '最近更新时间:',
},
giscus: {
repo: 'doocs/leetcode',
repoId: 'MDEwOlJlcG9zaXRvcnkxNDkwMDEzNjU',
category: 'Announcements',
categoryId: 'DIC_kwDOCOGUlc4CZmhe',
mapping: 'specific',
term: getTerm(),
reactionsEnabled: '0',
strict: '1',
emitMetadata: '0',
inputPosition: 'top',
crossorigin: 'anonymous',
loading: 'lazy',
theme: giscusTheme(),
lang: getLang(),
},
logo: '/images/doocs-leetcode.png',
search: {
depth: 2,
hideOtherSidebarContent: true,
pathNamespaces: ['/', '/solution', '/lcof', '/lcof2', '/lcci', '/lcs', '/lcp', '/basic'],
},
loadSidebar: sidebar(),
auto2top: true,
subMaxLevel: 2,
alias: {
'/lcs/.*/summary.md': '/lcs/summary.md',
'/lcp/.*/summary.md': '/lcp/summary.md',
'/lcci/.*/summary.md': '/lcci/summary.md',
'/lcof/.*/summary.md': '/lcof/summary.md',
'/lcof2/.*/summary.md': '/lcof2/summary.md',
'/solution/.*/summary.md': '/solution/summary.md',
'/basic/.*/summary.md': '/basic/summary.md',
'/lcs/.*/summary_en.md': '/lcs/summary_en.md',
'/lcp/.*/summary_en.md': '/lcp/summary_en.md',
'/lcci/.*/summary_en.md': '/lcci/summary_en.md',
'/lcof/.*/summary_en.md': '/lcof/summary_en.md',
'/lcof2/.*/summary_en.md': '/lcof2/summary_en.md',
'/solution/.*/summary_en.md': '/solution/summary_en.md',
'/basic/.*/summary_en.md': '/basic/summary_en.md',
},
contributors: {
repo: 'doocs/leetcode',
ignores: [
'/README.md',
'/README_EN.md',
'/solution/README.md',
'/solution/README_EN.md',
'/summary.md',
],
image: {
margin: '0.2em',
isRound: true,
},
},
darklightTheme: {
defaultTheme: 'light',
siteFont: 'Source Sans Pro,Helvetica Neue,Arial,sans-serif',
codeFontFamily: 'Roboto Mono, Monaco, courier, monospace',
bodyFontSize: '15px',
dark: {
background: '#191919',
highlightColor: '#e96900',
codeBackgroundColor: '#202020',
codeTextColor: '#b4b4b4',
},
light: {
highlightColor: '#e96900',
},
},
pagination: {
previousText: {
'/README_EN': 'PREVIOUS',
'/': '上一题',
},
nextText: {
'/README_EN': 'NEXT',
'/': '下一题',
},
crossChapter: true,
crossChapterText: true,
},
tabs: {
persist: true,
sync: true,
theme: 'classic',
tabComments: true,
tabHeadings: true,
},
plugins: [
(hook, vm) => {
hook.beforeEach(html => {
const { file } = vm.route;
const isUserContent = /githubusercontent\.com/.test(file);
const url = isUserContent
? file
.replace('raw.githubusercontent.com', 'github.com')
.replace(/\/main/, '/blob/main')
: `https://github.com/doocs/leetcode/blob/main/${file}`;
const github = `[GitHub](${url})`;
const gitee = `[Gitee](${url.replace('github', 'gitee')})`;
html = cleanedHtml(html);
const editHtml = isEn()
? `:memo: Edit on ${github} / ${gitee}\n`
: `:memo: 在 ${github} / ${gitee} 编辑\n`;
return editHtml + html;
});
hook.afterEach(html => {
const copyright = isEn() ? '. All Rights Reserved' : ' 版权所有';
const currentYear = new Date().getFullYear();
const footer = `<footer>Copyright © 2018-${currentYear} <a href="https://github.com/doocs" target="_blank">Doocs</a>${copyright}</footer>`;
return html + footer;
});
hook.doneEach(() => {
const term = getTerm();
const lang = getLang();
var giscusScript = document.createElement('script');
const {
repo,
repoId,
category,
categoryId,
mapping,
reactionsEnabled,
strict,
emitMetadata,
inputPosition,
crossorigin,
loading,
theme,
} = $docsify.giscus;
giscusScript.type = 'text/javascript';
giscusScript.async = true;
giscusScript.setAttribute('src', 'https://giscus.app/client.js');
giscusScript.setAttribute('data-repo', repo);
giscusScript.setAttribute('data-repo-id', repoId);
giscusScript.setAttribute('data-category', category);
giscusScript.setAttribute('data-category-id', categoryId);
giscusScript.setAttribute('data-mapping', mapping);
giscusScript.setAttribute('data-reactions-enabled', reactionsEnabled);
giscusScript.setAttribute('data-strict', strict);
giscusScript.setAttribute('data-emit-metadata', emitMetadata);
giscusScript.setAttribute('data-input-position', inputPosition);
giscusScript.setAttribute('crossorigin', crossorigin);
giscusScript.setAttribute('data-loading', loading);
giscusScript.setAttribute('data-theme', theme);
giscusScript.setAttribute('data-term', term);
giscusScript.setAttribute('data-lang', lang);
document
.getElementById('main')
.insertBefore(giscusScript, document.getElementById('main').lastChild);
document.getElementById('docsify-darklight-theme').addEventListener('click', () => {
const frame = document.querySelector('.giscus-frame');
frame.contentWindow.postMessage(
{ giscus: { setConfig: { theme } } },
'https://giscus.app',
);
});
});
},
],
};