Skip to content

Commit e7054a5

Browse files
committed
mobile nav enhancements + changelog panel
1 parent dcb068d commit e7054a5

5 files changed

Lines changed: 353 additions & 213 deletions

File tree

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
end_of_line = crlf
7+
charset = utf-8
8+
trim_trailing_whitespace = false
9+
insert_final_newline = false

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</svg>
2222
</div>
2323

24-
<nav>
24+
<nav class="hidden">
2525
<div class="title">
2626
<h3>nav</h3>
2727

@@ -33,6 +33,14 @@ <h3>nav</h3>
3333
<div id="nav-container"></div>
3434
</nav>
3535

36+
<div id="changelog">
37+
<div class="title">
38+
<h3>changelog</h3>
39+
</div>
40+
41+
<div id="changelog-container"></div>
42+
</div>
43+
3644
<main>
3745
loading ...<br>
3846
<br>
@@ -57,6 +65,8 @@ <h3>nav</h3>
5765
<div><a href="https://github.com/Socketlike/socketlike.github.io">github</a></div>
5866
</footer>
5967

68+
<div id="nav-overlay"></div>
69+
6070
<script type="module" src="/src/index.js"></script>
6171
</body>
6272
</html>

scripts/make-changelog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { writeFile } from 'node:fs/promises'
44
const _default = () => writeFile(
55
'content/changelog.json',
66
JSON.stringify(
7-
shell.exec('git log --oneline -5', { silent: true }).stdout
7+
shell.exec('git log --oneline --no-abbrev-commit --decorate=short -5', { silent: true }).stdout
88
.trim()
99
.split('\n')
10-
.map((log) => [log.substring(0, 7), log.substring(8)])
10+
.map((log) => [log.substring(0, 40), log.substring(41)])
1111
)
1212
)
1313

src/index.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,22 @@ const nav = document.querySelector('nav')
1717
const navContainer = document.getElementById('nav-container')
1818
const navButton = document.getElementById('nav-button')
1919
const navCloseButton = document.getElementById('nav-close-button')
20+
const navOverlay = document.getElementById('nav-overlay')
21+
22+
const changelogRoot = document.getElementById('changelog')
23+
const changelogContainer = document.getElementById('changelog-container')
2024

2125
const responsiveEvent = window.matchMedia("only screen and (max-width: 768px)")
2226

2327
let navHidden = responsiveEvent.matches
28+
nav.classList.toggle('hidden', navHidden)
29+
30+
const recalcResponsiveSize = () => {
31+
const sideWidth = `calc(${main.getBoundingClientRect().x}px - 32px)`
2432

25-
const recalcNavSize = () =>
26-
nav.style.width = `calc(${main.getBoundingClientRect().x}px - 32px)`
33+
nav.style.width = sideWidth
34+
changelogRoot.style.width = sideWidth
35+
}
2736

2837
const recalcNavRight = (immediate = false) => {
2938
const outside = responsiveEvent.matches
@@ -52,12 +61,12 @@ const toggleNav = (force = undefined) => {
5261
recalcNavRight()
5362
}
5463

55-
const recalcNav = (immediate = false) => {
56-
recalcNavSize()
64+
const recalcResponsive = (immediate = false) => {
65+
recalcResponsiveSize()
5766
recalcNavRight(immediate)
5867
}
5968

60-
recalcNav(true)
69+
recalcResponsive(true)
6170

6271
navContainer.replaceChildren(
6372
...Object
@@ -76,7 +85,8 @@ navContainer.replaceChildren(
7685

7786
navButton.addEventListener('click', toggleNav)
7887
navCloseButton.addEventListener('click', () => toggleNav(false))
79-
responsiveEvent.addEventListener('change', recalcNav)
88+
responsiveEvent.addEventListener('change', recalcResponsive)
89+
navOverlay.addEventListener('click', () => toggleNav(false))
8090

8191
if (content)
8292
fetch(content)
@@ -94,6 +104,28 @@ const changelog = await fetch('/content/changelog.json')
94104
.then((r) => r.json())
95105
.catch(console.error)
96106

97-
if (changelog) {
98-
99-
}
107+
if (changelog)
108+
changelogContainer.replaceChildren(
109+
...changelog.map(([hash, title]) => {
110+
const line = document.createElement('div')
111+
line.className = 'line'
112+
113+
const hashLabel = document.createElement('code')
114+
hashLabel.className = 'hash'
115+
hashLabel.classList.toggle('latest', title.includes('origin/HEAD'))
116+
hashLabel.classList.toggle('local-latest', title.includes('HEAD ->'))
117+
hashLabel.textContent = hash.substring(0, 7)
118+
hashLabel.title = hash
119+
120+
const titleLabel = document.createElement('div')
121+
titleLabel.className = 'changelog-title'
122+
titleLabel.textContent = title.includes('origin/HEAD') || title.includes('HEAD ->')
123+
? title.replace(/^\(.+\)/, '')
124+
: title
125+
titleLabel.title = title
126+
127+
line.append(hashLabel, titleLabel)
128+
129+
return line
130+
})
131+
)

0 commit comments

Comments
 (0)