Put profile name in page title

This commit is contained in:
Yarmo Mackenbach 2021-05-05 09:53:02 +02:00
parent c36196ef05
commit ae422ca837
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
3 changed files with 30 additions and 6 deletions

View file

@ -37,27 +37,32 @@ router.get('/sig', (req, res) => {
router.post('/sig', bodyParser, async (req, res) => {
const data = await kx.generateSignatureProfile(req.body.signature)
res.render('profile', { data: data, isSignature: true, signature: req.body.signature })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data, isSignature: true, signature: req.body.signature })
})
router.get('/wkd/:id', async (req, res) => {
const data = await kx.generateWKDProfile(req.params.id)
res.render('profile', { data: data })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data })
})
router.get('/hkp/:id', async (req, res) => {
const data = await kx.generateHKPProfile(req.params.id)
res.render('profile', { data: data })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data })
})
router.get('/hkp/:server/:id', async (req, res) => {
const data = await kx.generateHKPProfile(req.params.id, req.params.server)
res.render('profile', { data: data })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data })
})
router.get('/keybase/:username/:fingerprint', async (req, res) => {
const data = await kx.generateKeybaseProfile(req.params.username, req.params.fingerprint)
res.render('profile', { data: data })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data })
})
router.get('/:id', async (req, res) => {
@ -67,7 +72,8 @@ router.get('/:id', async (req, res) => {
} else {
data = await kx.generateHKPProfile(req.params.id)
}
res.render('profile', { data: data })
const title = kx.utils.generatePageTitle('profile', data)
res.render('profile', { title: title, data: data })
})
module.exports = router

View file

@ -175,3 +175,5 @@ exports.generateWKDProfile = generateWKDProfile
exports.generateHKPProfile = generateHKPProfile
exports.generateKeybaseProfile = generateKeybaseProfile
exports.generateSignatureProfile = generateSignatureProfile
exports.utils = require('./utils')

View file

@ -34,3 +34,19 @@ exports.computeWKDLocalPart = async (message) => {
const hash = await openpgp.crypto.hash.sha1(data);
return openpgp.util.encodeZBase32(hash);
}
exports.generatePageTitle = (type, data) => {
switch (type) {
case 'profile':
try {
return `${data.keyData.users[data.keyData.primaryUserIndex].userData.name} - Keyoxide`
} catch (error) {
return 'Profile - Keyoxide'
}
break
default:
return 'Keyoxide'
break
}
}