forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
116 lines (111 loc) · 4.22 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
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>';
});
};
window.addEventListener('hashchange', () => {
window.$docsify.loadSidebar = sidebar();
window.$docsify.pagination.previousText = isEn() ? 'PREVIOUS' : '上一题';
window.$docsify.pagination.nextText = isEn() ? 'NEXT' : '下一题';
});
window.$docsify = {
name: 'leetcode',
repo: 'doocs/leetcode',
lastModifiedText: isEn() ? 'Last updated: ' : '最近更新时间:',
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: isEn() ? 'PREVIOUS' : '上一题',
nextText: isEn() ? '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;
});
},
],
};