Fix profile generation without specified protocol

This commit is contained in:
Yarmo Mackenbach 2021-05-02 22:48:18 +02:00
parent 3761879667
commit d1f194128d
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 53 additions and 47 deletions

View file

@ -27,18 +27,18 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router(); const router = require('express').Router()
const md = require('markdown-it')({typographer: true}); const md = require('markdown-it')({typographer: true})
const fs = require('fs'); const fs = require('fs')
md.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalinkClass": 'header-anchor', "permalinkSymbol": '¶', "permalinkBefore": false }); md.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalinkClass": 'header-anchor', "permalinkSymbol": '¶', "permalinkBefore": false })
md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" }); md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" })
md.use(require('markdown-it-title')); md.use(require('markdown-it-title'))
if (process.env.ONION_URL) { if (process.env.ONION_URL) {
router.get('/*', (req, res, next) => { router.get('/*', (req, res, next) => {
res.header('Onion-Location', process.env.ONION_URL); res.header('Onion-Location', process.env.ONION_URL)
next(); next()
}); });
} }
@ -55,47 +55,47 @@ router.get('/', (req, res) => {
} }
} }
res.render('index', { highlights: highlights, demoData: require('../server/demo.js').data }); res.render('index', { highlights: highlights, demoData: require('../server/demo.js').data })
}); })
router.get('/about', (req, res) => { router.get('/about', (req, res) => {
let rawContent = fs.readFileSync(`./content/about.md`, "utf8"); let rawContent = fs.readFileSync(`./content/about.md`, "utf8")
const content = md.render(rawContent); const content = md.render(rawContent)
res.render(`long-form-content`, { title: `About Keyoxide`, content: content }); res.render(`long-form-content`, { title: `About Keyoxide`, content: content })
}); })
router.get('/getting-started', (req, res) => { router.get('/getting-started', (req, res) => {
let rawContent = fs.readFileSync(`./content/getting-started.md`, "utf8"); let rawContent = fs.readFileSync(`./content/getting-started.md`, "utf8")
const content = md.render(rawContent); const content = md.render(rawContent)
res.render(`long-form-content`, { title: `Getting started`, content: content }); res.render(`long-form-content`, { title: `Getting started`, content: content })
}); })
router.get('/faq', (req, res) => { router.get('/faq', (req, res) => {
const mdAlt = require('markdown-it')({typographer: true}); const mdAlt = require('markdown-it')({typographer: true})
mdAlt.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalinkClass": 'header-anchor', "permalinkSymbol": '¶', "permalinkBefore": false }); mdAlt.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalinkClass": 'header-anchor', "permalinkSymbol": '¶', "permalinkBefore": false })
mdAlt.use(require("markdown-it-table-of-contents"), { "includeLevel": [2], "listType": "ul" }); mdAlt.use(require("markdown-it-table-of-contents"), { "includeLevel": [2], "listType": "ul" })
let rawContent = fs.readFileSync(`./content/faq.md`, "utf8"); let rawContent = fs.readFileSync(`./content/faq.md`, "utf8")
rawContent = rawContent.replace('${domain}', req.app.get('domain')); rawContent = rawContent.replace('${domain}', req.app.get('domain'))
const content = mdAlt.render(rawContent); const content = mdAlt.render(rawContent)
res.render(`long-form-content`, { title: `Frequently Asked Questions`, content: content }); res.render(`long-form-content`, { title: `Frequently Asked Questions`, content: content })
}); })
router.get('/guides', (req, res) => { router.get('/guides', (req, res) => {
res.render('guides', { title: `Guides - Keyoxide` }); res.render('guides', { title: `Guides - Keyoxide` })
}); })
router.get('/guides/:guideId', (req, res) => { router.get('/guides/:guideId', (req, res) => {
let env = {}; let env = {}
fs.readFile(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => { fs.readFile(`./content/guides/${req.params.guideId}.md`, "utf8", (err, data) => {
if (err) { if (err) {
res.render(`404`); res.render(`404`)
return return
} }
const content = md.render(data, env); const content = md.render(data, env)
res.render(`long-form-content`, { title: `${env.title} - Keyoxide`, content: content }); res.render(`long-form-content`, { title: `${env.title} - Keyoxide`, content: content })
}); })
}); })
module.exports = router; module.exports = router

View file

@ -62,8 +62,14 @@ router.get('/keybase/:username/:fingerprint', async (req, res) => {
res.render('profile', { mode: 'keybase', uid: `${req.params.username}/${req.params.fingerprint}` }) res.render('profile', { mode: 'keybase', uid: `${req.params.username}/${req.params.fingerprint}` })
}) })
router.get('/:input', async (req, res) => { router.get('/:id', async (req, res) => {
res.render('profile', { mode: 'auto', uid: req.params.input }) let data
if (req.params.id.includes('@')) {
data = await kx.generateWKDProfile(req.params.id)
} else {
data = await kx.generateHKPProfile(req.params.id)
}
res.render('profile', { data: data })
}) })
module.exports = router module.exports = router

View file

@ -27,34 +27,34 @@ You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary. For if any, to sign a "copyright disclaimer" for the program, if necessary. For
more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>. more information on this, and how to apply and follow the GNU AGPL, see <https://www.gnu.org/licenses/>.
*/ */
const router = require('express').Router(); const router = require('express').Router()
router.get('/profile-url', function(req, res) { router.get('/profile-url', function(req, res) {
res.render('util/profile-url') res.render('util/profile-url')
}); })
router.get('/profile-url/:input', function(req, res) { router.get('/profile-url/:input', function(req, res) {
res.render('util/profile-url', { input: req.params.input }) res.render('util/profile-url', { input: req.params.input })
}); })
router.get('/qr', function(req, res) { router.get('/qr', function(req, res) {
res.render('util/qr') res.render('util/qr')
}); })
router.get('/qr/:input', function(req, res) { router.get('/qr/:input', function(req, res) {
res.render('util/qr', { input: req.params.input }) res.render('util/qr', { input: req.params.input })
}); })
router.get('/qrfp', function(req, res) { router.get('/qrfp', function(req, res) {
res.render('util/qrfp') res.render('util/qrfp')
}); })
router.get('/qrfp/:input', function(req, res) { router.get('/qrfp/:input', function(req, res) {
res.render('util/qrfp', { input: req.params.input }) res.render('util/qrfp', { input: req.params.input })
}); })
router.get('/wkd', function(req, res) { router.get('/wkd', function(req, res) {
res.render('util/wkd') res.render('util/wkd')
}); })
router.get('/wkd/:input', function(req, res) { router.get('/wkd/:input', function(req, res) {
res.render('util/wkd', { input: req.params.input }) res.render('util/wkd', { input: req.params.input })
}); })
module.exports = router; module.exports = router