mirror of https://codeberg.org/pzp/pzp-hub.git
apply prettier
This commit is contained in:
parent
09d14292b3
commit
13a8f59f44
|
@ -0,0 +1,2 @@
|
||||||
|
semi: false
|
||||||
|
singleQuote: true
|
44
lib/index.js
44
lib/index.js
|
@ -1,4 +1,4 @@
|
||||||
import {createRequire} from 'module';
|
import { createRequire } from 'module'
|
||||||
import { unified } from 'unified'
|
import { unified } from 'unified'
|
||||||
import remarkParse from 'remark-parse'
|
import remarkParse from 'remark-parse'
|
||||||
import remarkRehype from 'remark-rehype'
|
import remarkRehype from 'remark-rehype'
|
||||||
|
@ -6,44 +6,44 @@ import rehypeStringify from 'rehype-stringify'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const require = createRequire(import.meta.url)
|
||||||
const __dirname = path.dirname(new URL(import.meta.url).pathname);
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||||
|
|
||||||
const fastify = require('fastify');
|
const fastify = require('fastify')
|
||||||
const fastifyView = require('@fastify/view');
|
const fastifyView = require('@fastify/view')
|
||||||
const fastifyStatic = require('@fastify/static');
|
const fastifyStatic = require('@fastify/static')
|
||||||
const ejs = require('ejs');
|
const ejs = require('ejs')
|
||||||
|
|
||||||
const staticsPath = path.join(__dirname, 'public');
|
const staticsPath = path.join(__dirname, 'public')
|
||||||
const viewsPath = path.join(__dirname, 'views');
|
const viewsPath = path.join(__dirname, 'views')
|
||||||
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md');
|
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md')
|
||||||
|
|
||||||
const processor = unified()
|
const processor = unified()
|
||||||
.use(remarkParse)
|
.use(remarkParse)
|
||||||
.use(remarkRehype)
|
.use(remarkRehype)
|
||||||
.use(rehypeStringify)
|
.use(rehypeStringify)
|
||||||
|
|
||||||
const homepageMD = fs.readFileSync(homepagePath, 'utf8');
|
const homepageMD = fs.readFileSync(homepagePath, 'utf8')
|
||||||
const homepageHTML = processor.processSync(homepageMD)
|
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) => {
|
app.get('/', (req, reply) => {
|
||||||
reply.view('homepage.ejs', {markdown: homepageHTML});
|
reply.view('homepage.ejs', { markdown: homepageHTML })
|
||||||
});
|
})
|
||||||
|
|
||||||
app.get('/invite', (req, reply) => {
|
app.get('/invite', (req, reply) => {
|
||||||
reply.view('invite.ejs');
|
reply.view('invite.ejs')
|
||||||
});
|
})
|
||||||
|
|
||||||
app.listen({ port: 3000 }, (err, address) => {
|
app.listen({ port: 3000 }, (err, address) => {
|
||||||
app.log.info(`server listening on ${address}`);
|
app.log.info(`server listening on ${address}`)
|
||||||
if (err) {
|
if (err) {
|
||||||
app.log.error(err);
|
app.log.error(err)
|
||||||
process.exit(1);
|
process.exit(1)
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
let hasFocus = true;
|
let hasFocus = true
|
||||||
window.addEventListener('blur', () => {
|
window.addEventListener('blur', () => {
|
||||||
hasFocus = false;
|
hasFocus = false
|
||||||
});
|
})
|
||||||
window.addEventListener('focus', () => {
|
window.addEventListener('focus', () => {
|
||||||
hasFocus = true;
|
hasFocus = true
|
||||||
});
|
})
|
||||||
|
|
||||||
const inviteLinkElem = document.getElementById('invite');
|
const inviteLinkElem = document.getElementById('invite')
|
||||||
const failureElem = document.getElementById('failure');
|
const failureElem = document.getElementById('failure')
|
||||||
|
|
||||||
const hash = window.location.hash;
|
const hash = window.location.hash
|
||||||
if (hash) {
|
if (hash) {
|
||||||
let uri = decodeURIComponent(hash.slice(1));
|
let uri = decodeURIComponent(hash.slice(1))
|
||||||
if (!uri.startsWith('ppppp:')) uri = 'ppppp://invite' + uri;
|
if (!uri.startsWith('ppppp:')) uri = 'ppppp://invite' + uri
|
||||||
inviteLinkElem.href = uri;
|
inviteLinkElem.href = uri
|
||||||
|
|
||||||
// Autoredirect to the PPPPP URI as soon as possible
|
// Autoredirect to the PPPPP URI as soon as possible
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(uri);
|
console.log(uri)
|
||||||
// window.location.replace(uri);
|
// window.location.replace(uri);
|
||||||
}, 100);
|
}, 100)
|
||||||
|
|
||||||
// Redirect to uri or show failure state
|
// Redirect to uri or show failure state
|
||||||
// FIXME:
|
// FIXME:
|
||||||
|
@ -36,6 +36,6 @@ if (hash) {
|
||||||
// window.location.replace(uri);
|
// window.location.replace(uri);
|
||||||
// };
|
// };
|
||||||
} else {
|
} else {
|
||||||
inviteLinkElem.classList.add('hidden');
|
inviteLinkElem.classList.add('hidden')
|
||||||
failureElem.classList.remove('hidden');
|
failureElem.classList.remove('hidden')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue