apply prettier

This commit is contained in:
Andre Staltz 2023-06-06 14:24:59 +03:00
parent 09d14292b3
commit 13a8f59f44
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
3 changed files with 41 additions and 39 deletions

2
.prettierrc.yaml Normal file
View File

@ -0,0 +1,2 @@
semi: false
singleQuote: true

View File

@ -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)
}
});
})

View File

@ -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')
}