|
26 | 26 | <div id="app">LeetCode & Coding Interview Guide @Doocs</div>
|
27 | 27 | <script>
|
28 | 28 | const isEn = () => location.hash.includes('README_EN');
|
29 |
| - const isRoot = () => ['', '#/', '#/README', '#/README_EN'].includes(location.hash); |
| 29 | + const isRoot = () => ['', '#/', '#/README', '#/README_EN'].includes(location.hash); |
30 | 30 | const sidebar = () => isRoot() ? false : (isEn() ? 'summary_en.md' : 'summary.md');
|
31 | 31 | const cleanedHtml = (html) => {
|
32 | 32 | return html.replace(/<pre>([\s\S]*?)<\/pre>/g, function (match, group) {
|
|
128 | 128 | return html + footer
|
129 | 129 | })
|
130 | 130 | },
|
| 131 | + (hook, vm) => { |
| 132 | + hook.beforeEach((html) => { |
| 133 | + function formatDateTime(dateTimeString) { |
| 134 | + const date = new Date(dateTimeString); |
| 135 | + const year = date.getFullYear(); |
| 136 | + const month = String(date.getMonth() + 1).padStart(2, '0'); |
| 137 | + const day = String(date.getDate()).padStart(2, '0'); |
| 138 | + const hours = String(date.getHours()).padStart(2, '0'); |
| 139 | + const minutes = String(date.getMinutes()).padStart(2, '0'); |
| 140 | + const seconds = String(date.getSeconds()).padStart(2, '0'); |
| 141 | + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; |
| 142 | + } |
| 143 | + const file = vm.route.file |
| 144 | + const lastIndex = file.lastIndexOf("/"); |
| 145 | + const filePath = vm.route.path === '/' ? '/README.md' : file.substring(0, lastIndex); |
| 146 | + const apiUrl = `https://api.github.com/repos/${$docsify.repo}/commits?path=${filePath}`; |
| 147 | + fetch(apiUrl, {method: 'GET'}).then(response => response.json()) |
| 148 | + .then(data => { |
| 149 | + const date = data[0].commit.committer.date |
| 150 | + const commitUrl = `https://github.com/${$docsify.repo}/commits/main/${file}` |
| 151 | + const lastModified = formatDateTime(date) |
| 152 | + const prompt = isEn() ? 'Last updated: ' : '最近更新时间:' |
| 153 | + const lastModifiedContent = ` |
| 154 | + <blockquote> |
| 155 | + <a href="${commitUrl}" target="_blank" style="color: #858585">${prompt + lastModified}</a> |
| 156 | + </blockquote> |
| 157 | + ` |
| 158 | + document.getElementById('last-modified').innerHTML = lastModifiedContent |
| 159 | + }) |
| 160 | + return ( |
| 161 | + html + '<span id="last-modified"></span>' |
| 162 | + ); |
| 163 | + }); |
| 164 | + }, |
| 165 | + |
131 | 166 | ]
|
132 | 167 | }
|
133 | 168 | </script>
|
|
0 commit comments