Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: separate configuration #1663

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 1 addition & 108 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,114 +24,7 @@

<body>
<div id="app">LeetCode & Coding Interview Guide @Doocs</div>
<script>
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, function (match, 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 userContent = /githubusercontent\.com/.test(file)
const url = userContent ? 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
})
},
]
}
</script>
<script src="./main.js"></script>
<script src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/docsify@4.13.0/lib/docsify.min.js"></script>
<!-- components -->
<script src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/prismjs/components/prism-c.min.js"></script>
Expand Down
116 changes: 116 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userContent -> isUserContent, 一般bool 命名规范

const url = isUserContent
? file
.replace('raw.githubusercontent.com', 'github.com')
.replace(/\/main/, '/blob/main')
: `https://github.com/doocs/leetcode/blob/main/${file}`;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

换成模版字符串拼接


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;
});
},
],
};