Skip to content

Commit

Permalink
Use 404.html as a catch all route
Browse files Browse the repository at this point in the history
  • Loading branch information
artemave committed Oct 20, 2023
1 parent 7b26086 commit d7d3591
Show file tree
Hide file tree
Showing 14 changed files with 1,730 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
stylesheets/.sass-cache
node_modules
25 changes: 25 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/styles.css" media="screen" type="text/css" />
<script type="module" src="/js/404.js" defer></script>
<title>Starlogs</title>
</head>
<body>
<div id="scene">
<div id="crawlContainer"></div>
</div>

<audio id="mainTheme" loop>
<source src="/assets/theme.ogg" type="audio/ogg; codecs=vorbis" />
<source src="/assets/theme.mp3" type="audio/mpeg" />
</audio>

<audio id="imperialMarch">
<source src="/assets/imperial_march.ogg" type="audio/ogg; codecs=vorbis" />
<source src="/assets/imperial_march.mp3" type="audio/mpeg" />
</audio>
</body>
</html>
3 changes: 0 additions & 3 deletions 404.md

This file was deleted.

2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="styles.css" media="screen" type="text/css" />
<script src="index.js" defer></script>
<script type="module" src="js/index.js" defer></script>
<title>Starlogs</title>
</head>
<body>
Expand Down
81 changes: 0 additions & 81 deletions index.js

This file was deleted.

21 changes: 21 additions & 0 deletions js/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { imperialMarch, mainTheme } from "./domRefs"
import fetchCommitMessages from "./fetchCommitMessages"
import performCrawl from "./performCrawl"
import registerScrollSoundEffect from "./registerScrollSoundEffect"

const [, userOrg, repo] = window.location.pathname.split('/')

fetchCommitMessages(`${userOrg}/${repo}`).then(messages => {
performCrawl(messages)
mainTheme.play()

}).catch(() => {
performCrawl([
"Tun dun dun, da da dun, 404",
"404, da da dun, 404",
"..."
])
imperialMarch.play()
})

registerScrollSoundEffect()
11 changes: 11 additions & 0 deletions js/domRefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const inputContainer = document.getElementById('inputContainer')
export const crawlContainer = document.getElementById('crawlContainer')
/** @type HTMLMediaElement */
// @ts-ignore
export const mainTheme = document.getElementById('mainTheme')
/** @type HTMLMediaElement */
// @ts-ignore
export const falconFly = document.getElementById('falconFly')
/** @type HTMLMediaElement */
// @ts-ignore
export const imperialMarch = document.getElementById('imperialMarch')
9 changes: 9 additions & 0 deletions js/fetchCommitMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* @param {string} repo
* @returns {Promise<Array<string>>} messages
*/
export default async function fetchCommitMessages(repo) {
const response = await fetch(`https://api.github.com/repos/${repo}/commits?per_page=100`)
const commits = await response.json()
return commits.map(commit => commit.commit.message)
}
33 changes: 33 additions & 0 deletions js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fetchCommitMessages from './fetchCommitMessages.js'
import { inputContainer, mainTheme, falconFly, imperialMarch } from './domRefs.js'
import performCrawl from './performCrawl.js'
import registerScrollSoundEffect from './registerScrollSoundEffect.js'

let fetchCommitMessagesPromise

inputContainer.onkeydown = function (e) {
if (e.keyCode === 13) {
inputContainer.classList.add('zoomed')
falconFly.play()

const repo = inputContainer.querySelector('input').value
fetchCommitMessagesPromise = fetchCommitMessages(repo)
}
}

inputContainer.ontransitionend = () => {
fetchCommitMessagesPromise.then((messages) => {
performCrawl(messages)
mainTheme.play()

}).catch(() => {
performCrawl([
"Tun dun dun, da da dun, 404",
"404, da da dun, 404",
"..."
])
imperialMarch.play()
})
}

registerScrollSoundEffect()
25 changes: 25 additions & 0 deletions js/performCrawl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { crawlContainer } from './domRefs.js'

export default function performCrawl(messages) {
messages.forEach((message, index) => {
const block = document.createElement('div');
block.classList.add('block');
block.innerText = message;

if (index === 0) {
block.style.paddingTop = `${crawlContainer.clientHeight}px`;
}
if (index === messages.length - 1) {
block.style.paddingBottom = '10000px';
}

crawlContainer.appendChild(block);
});

const scroll = () => {
crawlContainer.scrollBy({ top: window.innerHeight > 1000 ? 2 : 1 });
requestAnimationFrame(scroll);
};
requestAnimationFrame(scroll);
}

24 changes: 24 additions & 0 deletions js/registerScrollSoundEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { mainTheme, crawlContainer } from './domRefs.js'

export default function registerScrollSoundEffect() {
let scrollEndTimeout

function performScrollSoundEffect() {
if (scrollEndTimeout) {
clearTimeout(scrollEndTimeout)
}
mainTheme.playbackRate = 4

scrollEndTimeout = setTimeout(() => {
mainTheme.playbackRate = 1
}, 50)
}

crawlContainer.ontouchmove = performScrollSoundEffect
if (crawlContainer.onwheel !== undefined) {
crawlContainer.onwheel = performScrollSoundEffect
} else { // Safari
// @ts-ignore
crawlContainer.onmousewheel = performScrollSoundEffect
}
}
Loading

0 comments on commit d7d3591

Please sign in to comment.