Skip to content

Commit

Permalink
attempting to add directory listings...
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Krouse committed Aug 26, 2018
1 parent bcfc0ff commit 914c9b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
39 changes: 36 additions & 3 deletions 404.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
title: 404
---

# 404
<h1 id="title">404</h1>

Congrats, you've discovered my 404 page!
<h2 id="notFoundText">
Congrats, you've discovered my 404 page!
</h2>

<li id="directory" style="display:none">
</li>

<div id="fileElement" style="display:none">
{{ site.data.files | map: "fileName" }}
</div>

<script>

Expand Down Expand Up @@ -35,12 +44,36 @@ const moved = {

const movedKey = Object.keys(moved).find(url => window.location.pathname.includes(url))
movedKey && window.location.replace(moved[movedKey])
const sf = (a, b) => {
const aInt = parseInt(a.split("-")[0])
const bInt = parseInt(b.split("-")[0])
if (!isNaN(aInt) && !isNaN(bInt)) {
return aInt - bInt;
} else {
return a.localeCompare(b)
}
}

const endingSlash = window.location.pathname.endsWith("/") ? "" : "/"
const pathname = window.location.pathname + endingSlash
const files = document.getElementById('fileElement').innerText.split(".").filter(path => path.startsWith(pathname)).map(path => path.replace(pathname, "")).sort(sf)
if (files.length) {
window.title = pathname
document.getElementById('notFoundText').style.display = "none"
document.getElementById('directory').style.display = "block"
document.getElementById('title').innerText = pathname
files.forEach(file => {
document.getElementById('directory').innerHTML += '<li style="list-style-type: none;"><a href="./' + file + '">' + file + '</a></li>'
})
}




</script>


<script>

(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ First, `pip install git2json` as explained [here](https://github.com/tarmstrong/
Then create `.git/hooks/post-commit` with the following contents:

```bash
# to get the data for directory listings
echo 'fileName' > _data/files.csv && find . -regextype posix-egrep -regex ".*\.(md|html)$" -not -path "./_site/*" >> _data/files.csv

# get the data for git log
git2json > _data/git-log.json

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

if [ "$previousMessage" != "updated git log" ]
then
git add _data/git-log.json
git add _data/files.csv
git commit -m "updated git log"
fi

Expand Down
1 change: 0 additions & 1 deletion notes/index.html

This file was deleted.

0 comments on commit 914c9b9

Please sign in to comment.