|
2 | 2 | title: 404
|
3 | 3 | ---
|
4 | 4 |
|
5 |
| -# 404 |
| 5 | +<h1 id="title">404</h1> |
6 | 6 |
|
7 |
| -Congrats, you've discovered my 404 page! |
| 7 | +<h2 id="notFoundText"> |
| 8 | + Congrats, you've discovered my 404 page! |
| 9 | +</h2> |
| 10 | + |
| 11 | +<li id="directory" style="display:none"> |
| 12 | +</li> |
| 13 | + |
| 14 | +<div id="fileElement" style="display:none"> |
| 15 | + {{ site.data.files | map: "fileName" }} |
| 16 | +</div> |
8 | 17 |
|
9 | 18 | <script>
|
10 | 19 |
|
@@ -35,12 +44,36 @@ const moved = {
|
35 | 44 |
|
36 | 45 | const movedKey = Object.keys(moved).find(url => window.location.pathname.includes(url))
|
37 | 46 | movedKey && window.location.replace(moved[movedKey])
|
| 47 | +const sf = (a, b) => { |
| 48 | + const aInt = parseInt(a.split("-")[0]) |
| 49 | + const bInt = parseInt(b.split("-")[0]) |
| 50 | + if (!isNaN(aInt) && !isNaN(bInt)) { |
| 51 | + return aInt - bInt; |
| 52 | + } else { |
| 53 | + return a.localeCompare(b) |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +const endingSlash = window.location.pathname.endsWith("/") ? "" : "/" |
| 58 | +const pathname = window.location.pathname + endingSlash |
| 59 | +const files = document.getElementById('fileElement').innerText.split(".").filter(path => path.startsWith(pathname)).map(path => path.replace(pathname, "")).sort(sf) |
| 60 | +if (files.length) { |
| 61 | + window.title = pathname |
| 62 | + document.getElementById('notFoundText').style.display = "none" |
| 63 | + document.getElementById('directory').style.display = "block" |
| 64 | + document.getElementById('title').innerText = pathname |
| 65 | + files.forEach(file => { |
| 66 | + document.getElementById('directory').innerHTML += '<li style="list-style-type: none;"><a href="./' + file + '">' + file + '</a></li>' |
| 67 | + }) |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | + |
38 | 72 |
|
39 | 73 | </script>
|
40 | 74 |
|
41 | 75 |
|
42 | 76 | <script>
|
43 |
| - |
44 | 77 | (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
45 | 78 | (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
46 | 79 | m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
|
0 commit comments