Initial commit

This commit is contained in:
Joshua Seigler 2020-12-02 10:06:38 -05:00
commit f3d555f01c
12 changed files with 370 additions and 0 deletions

14
solutions/index.html Normal file
View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Advent of Code Template</title>
<style> html, body { font-family: sans-serif; }</style>
</head>
<body>
<h1>Advent of Code Template</h1>
<ul>
<li><a href="/solutions/template/viewer.html">solutions/template</a></li>
</ul>
</body>
</html>

View file

@ -0,0 +1 @@
PASTE YOUR INPUT HERE

View file

@ -0,0 +1,24 @@
const path = require('path')
const { read, position } = require('promise-path')
const fromHere = position(__dirname)
const report = (...messages) => console.log(`[${require(fromHere('../../package.json')).logName} / ${__dirname.split(path.sep).pop()}]`, ...messages)
async function run () {
const input = (await read(fromHere('input.txt'), 'utf8')).trim()
await solveForFirstStar(input)
await solveForSecondStar(input)
}
async function solveForFirstStar (input) {
const solution = 'UNSOLVED'
report('Input:', input)
report('Solution 1:', solution)
}
async function solveForSecondStar (input) {
const solution = 'UNSOLVED'
report('Solution 2:', solution)
}
run()

View file

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title>Solution Viewer</title>
<style>
html, body { font-family: sans-serif; }
pre { border-radius: 0.5em; padding: 0.5em; background: #eee; }
</style>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<div id="viewer">
<h1>Solution Viewer ({{ solutionTitle }})</h1>
<p>For interesting problems; this page can be used as a dynamic viewer.</p>
<h3><a href="./input.txt">input.txt</a></h3>
<pre><code>{{ inputText }}</code></pre>
<h3><a href="./solution.js">solution.js</a></h3>
<pre><code>{{ solutionText }}</code></pre>
</div>
<script>
const app = new Vue({
el: '#viewer',
data: () => {
return {
solutionText: '[Loading]',
inputText: '[Loading]'
}
},
computed: {
solutionTitle() {
const parts = (document.location + '').split('/')
return parts.reverse()[1]
}
},
async mounted () {
this.solutionText = (await axios.get('./solution.js')).data
this.inputText = (await axios.get('./input.txt')).data
}
})
</script>
</body>
</html>

View file

@ -0,0 +1,49 @@
const path = require('path')
const express = require('express')
const { position, find, write } = require('promise-path')
const fromHere = position(__dirname)
const report = (...messages) => console.log(`[${require(fromHere('../package.json')).logName} / ${__filename.split(path.sep).pop().split('.js').shift()}]`, ...messages)
const app = express()
const packageData = require('../package.json')
async function generateIndexHTML () {
const title = packageData.logName
const solutions = await find(fromHere('/*'))
const links = solutions
.filter(n => n.indexOf('.js') === -1 && n.indexOf('.html') === -1)
.map(solution => {
const folder = solution.substr(fromHere('../').length)
return ` <li><a href="/${folder}/viewer.html">${folder}</a></li>`
})
const html = `<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
<style> html, body { font-family: sans-serif; }</style>
</head>
<body>
<h1>${title}</h1>
<ul>
${links.join('\n')}
</ul>
</body>
</html>
`
report('Updated hard coded index:', fromHere('index.html'))
await write(fromHere('index.html'), html, 'utf8')
return html
}
app.use('/solutions', express.static(fromHere('')))
app.get('/', async (req, res) => {
const html = await generateIndexHTML()
res.send(html)
})
const port = 8080
app.listen(port, () => report(`Listening on http://localhost:${port}/`))