Skip to content

Commit d1abf77

Browse files
author
Steve Krouse
committed
attempting to add directory listings...
1 parent 5f41ce0 commit d1abf77

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

404.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22
title: 404
33
---
44

5-
# 404
5+
<h1 id="title">404</h1>
66

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>
817

918
<script>
1019

@@ -35,12 +44,36 @@ const moved = {
3544

3645
const movedKey = Object.keys(moved).find(url => window.location.pathname.includes(url))
3746
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+
3872

3973
</script>
4074

4175

4276
<script>
43-
4477
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
4578
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
4679
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ First, `pip install git2json` as explained [here](https://github.com/tarmstrong/
4646
Then create `.git/hooks/post-commit` with the following contents:
4747

4848
```bash
49+
# to get the data for directory listings
50+
echo 'fileName' > _data/files.csv && find . -regextype posix-egrep -regex ".*\.(md|html)$" -not -path "./_site/*" >> _data/files.csv
51+
52+
# get the data for git log
4953
git2json > _data/git-log.json
5054

5155
previousMessage=$(git log -1 --pretty=%B)
5256

5357
if [ "$previousMessage" != "updated git log" ]
5458
then
5559
git add _data/git-log.json
60+
git add _data/files.csv
5661
git commit -m "updated git log"
5762
fi
5863

notes/index.html

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)