Skip to content

Commit 933a5b8

Browse files
committed
Update time right away
1 parent 2889b25 commit 933a5b8

File tree

3 files changed

+7
-51
lines changed

3 files changed

+7
-51
lines changed

public/sw-destroy.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/components/BaseHead.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ const { title, description, image = '/blog-placeholder.jpg' } = Astro.props
4242
<meta property="twitter:description" content={description} />
4343
<meta property="twitter:image" content={new URL(image, Astro.url)} />
4444

45-
<script is:inline src="/sw-destroy.js"></script>
45+
<script is:inline src="/js/sw-destroy.js"></script>

src/components/Footer.astro

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ if (hour < 6) timeOfDay = 'night'
1111

1212
<footer>
1313
<hr />
14-
<p>Good {timeOfDay}! It's <time :datetime={today}>{hourFormatted}:{minFormatted}</time>.</p>
14+
<p>
15+
Good <span class="js-time-of-day">{timeOfDay}</span>! It's <time :datetime={today}
16+
>{hourFormatted}:{minFormatted}</time
17+
>.
18+
</p>
1519

1620
<div class="links">
1721
<a href="mailto:[email protected]"> E-mail me! Write about anything.</a>
@@ -27,29 +31,7 @@ if (hour < 6) timeOfDay = 'night'
2731
</div>
2832
</footer>
2933

30-
<script type="module">
31-
const datetime = document.querySelector('time')
32-
33-
function updateTime() {
34-
if (!datetime) return
35-
36-
const today = new Date()
37-
const hour = today.getHours()
38-
const hourFormatted = hour < 10 ? '0' + hour : hour
39-
const min = today.getMinutes()
40-
const minFormatted = min < 10 ? '0' + min : min
41-
let timeOfDay = hour < 12 ? 'morning' : hour < 18 ? 'afternoon' : 'evening'
42-
43-
if (hour < 6) timeOfDay = 'night'
44-
45-
const time = `${hourFormatted}:${minFormatted}`
46-
const greeting = `Good ${timeOfDay}! It's ${time}.`
47-
datetime.textContent = greeting
48-
datetime.setAttribute('datetime', today.toISOString())
49-
}
50-
51-
setInterval(updateTime, 30 * 1000)
52-
</script>
34+
<script is:inline type="module" src="/js/update-time.js"></script>
5335

5436
<style>
5537
footer {

0 commit comments

Comments
 (0)