From ae422ca8370fccca4f9bd4e54a1cdcd636bca1b6 Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Wed, 5 May 2021 09:53:02 +0200 Subject: [PATCH] Put profile name in page title --- routes/profile.js | 18 ++++++++++++------ server/index.js | 2 ++ server/utils.js | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/routes/profile.js b/routes/profile.js index 080f19c..a8e8e72 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -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 diff --git a/server/index.js b/server/index.js index 883c422..4e45938 100644 --- a/server/index.js +++ b/server/index.js @@ -175,3 +175,5 @@ exports.generateWKDProfile = generateWKDProfile exports.generateHKPProfile = generateHKPProfile exports.generateKeybaseProfile = generateKeybaseProfile exports.generateSignatureProfile = generateSignatureProfile + +exports.utils = require('./utils') diff --git a/server/utils.js b/server/utils.js index f87b8c5..550312e 100644 --- a/server/utils.js +++ b/server/utils.js @@ -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 + } +}