diff --git a/.prettierrc.yaml b/.prettierrc.yaml new file mode 100644 index 0000000..1d2127c --- /dev/null +++ b/.prettierrc.yaml @@ -0,0 +1,2 @@ +semi: false +singleQuote: true diff --git a/lib/index.js b/lib/index.js index 63534ca..f62f617 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,49 +1,49 @@ -import {createRequire} from 'module'; -import {unified} from 'unified' +import { createRequire } from 'module' +import { unified } from 'unified' import remarkParse from 'remark-parse' import remarkRehype from 'remark-rehype' import rehypeStringify from 'rehype-stringify' import fs from 'fs' import path from 'path' -const require = createRequire(import.meta.url); -const __dirname = path.dirname(new URL(import.meta.url).pathname); +const require = createRequire(import.meta.url) +const __dirname = path.dirname(new URL(import.meta.url).pathname) -const fastify = require('fastify'); -const fastifyView = require('@fastify/view'); -const fastifyStatic = require('@fastify/static'); -const ejs = require('ejs'); +const fastify = require('fastify') +const fastifyView = require('@fastify/view') +const fastifyStatic = require('@fastify/static') +const ejs = require('ejs') -const staticsPath = path.join(__dirname, 'public'); -const viewsPath = path.join(__dirname, 'views'); -const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md'); +const staticsPath = path.join(__dirname, 'public') +const viewsPath = path.join(__dirname, 'views') +const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md') const processor = unified() .use(remarkParse) .use(remarkRehype) .use(rehypeStringify) -const homepageMD = fs.readFileSync(homepagePath, 'utf8'); +const homepageMD = fs.readFileSync(homepagePath, 'utf8') const homepageHTML = processor.processSync(homepageMD) -const app = fastify({logger: true}); +const app = fastify({ logger: true }) -app.register(fastifyView, { engine: {ejs}, root: viewsPath }); +app.register(fastifyView, { engine: { ejs }, root: viewsPath }) -app.register(fastifyStatic, { root: staticsPath }); +app.register(fastifyStatic, { root: staticsPath }) app.get('/', (req, reply) => { - reply.view('homepage.ejs', {markdown: homepageHTML}); -}); + reply.view('homepage.ejs', { markdown: homepageHTML }) +}) app.get('/invite', (req, reply) => { - reply.view('invite.ejs'); -}); + reply.view('invite.ejs') +}) -app.listen({port: 3000}, (err, address) => { - app.log.info(`server listening on ${address}`); +app.listen({ port: 3000 }, (err, address) => { + app.log.info(`server listening on ${address}`) if (err) { - app.log.error(err); - process.exit(1); + app.log.error(err) + process.exit(1) } -}); +}) diff --git a/lib/public/invite.js b/lib/public/invite.js index df69afc..241ad77 100644 --- a/lib/public/invite.js +++ b/lib/public/invite.js @@ -1,25 +1,25 @@ -let hasFocus = true; +let hasFocus = true window.addEventListener('blur', () => { - hasFocus = false; -}); + hasFocus = false +}) window.addEventListener('focus', () => { - hasFocus = true; -}); + hasFocus = true +}) -const inviteLinkElem = document.getElementById('invite'); -const failureElem = document.getElementById('failure'); +const inviteLinkElem = document.getElementById('invite') +const failureElem = document.getElementById('failure') -const hash = window.location.hash; +const hash = window.location.hash if (hash) { - let uri = decodeURIComponent(hash.slice(1)); - if (!uri.startsWith('ppppp:')) uri = 'ppppp://invite' + uri; - inviteLinkElem.href = uri; + let uri = decodeURIComponent(hash.slice(1)) + if (!uri.startsWith('ppppp:')) uri = 'ppppp://invite' + uri + inviteLinkElem.href = uri // Autoredirect to the PPPPP URI as soon as possible setTimeout(() => { - console.log(uri); + console.log(uri) // window.location.replace(uri); - }, 100); + }, 100) // Redirect to uri or show failure state // FIXME: @@ -36,6 +36,6 @@ if (hash) { // window.location.replace(uri); // }; } else { - inviteLinkElem.classList.add('hidden'); - failureElem.classList.remove('hidden'); + inviteLinkElem.classList.add('hidden') + failureElem.classList.remove('hidden') }