Skip to content

Commit d4b5472

Browse files
subdirectory list on home page
1 parent 12ea498 commit d4b5472

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Generate Subdirectory List
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout repo
13+
uses: actions/checkout@v3
14+
15+
- name: Generate directories.json
16+
run: |
17+
echo "[" > directories.json
18+
for dir in */ ; do
19+
if [[ "$dir" != "assets/" && "$dir" != ".github/" ]]; then
20+
echo " \"${dir%/}\"," >> directories.json
21+
fi
22+
done
23+
sed -i '$ s/,$//' directories.json
24+
echo "]" >> directories.json
25+
26+
- name: Commit and push
27+
run: |
28+
git config user.name "github-actions[bot]"
29+
git config user.email "github-actions[bot]@users.noreply.github.com"
30+
git add directories.json
31+
git commit -m "Update directories list" || echo "No changes"
32+
git push

app.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fetch('directories.json')
2+
.then(response => response.json())
3+
.then(directories => {
4+
const list = document.getElementById("subdirectoryList");
5+
directories.forEach(dir => {
6+
const li = document.createElement("li");
7+
const a = document.createElement("a");
8+
a.href = `${dir}/`;
9+
a.textContent = dir;
10+
li.appendChild(a);
11+
list.appendChild(li);
12+
});
13+
})
14+
.catch(err => {
15+
console.error("Failed to load directories.json", err);
16+
});

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<script src="app.js"></script>
4+
</head>
5+
<body>
6+
<h2>nothing here, check out the subdirectories:</h2>
7+
<ul id="subdirectoryList"></ul>
8+
</body>

0 commit comments

Comments
 (0)