diff --git a/server/index.ts b/server/index.ts index 079cfa1..4a9c645 100644 --- a/server/index.ts +++ b/server/index.ts @@ -6,7 +6,7 @@ import path from 'path'; import fs from 'fs'; import { fileURLToPath } from 'url'; -import { initializeDatabase, questionnaireOps } from './database.js'; +import { initializeDatabase, questionnaireOps, participantOps } from './database.js'; import authRoutes from './routes/auth.js'; import adminRoutes from './routes/admin.js'; import questionnaireRoutes from './routes/questionnaire.js'; @@ -76,6 +76,21 @@ if (isProduction) { const clientPath = path.join(__dirname, '../client'); app.use(express.static(clientPath)); + // Helper function to generate OG tags HTML + function generateOgTags(baseUrl: string, pageUrl: string, title: string, description: string, ogImageUrl: string | null): string { + return ` + + + + + ${ogImageUrl ? `` : ''} + + + + ${ogImageUrl ? `` : ''} + `; + } + // Dynamic OG meta tags for questionnaire pages app.get('/q/:slug', (req, res) => { const questionnaire = questionnaireOps.findBySlug(req.params.slug); @@ -101,17 +116,53 @@ if (isProduction) { ogImageUrl = `${baseUrl}${ogImageUrl}`; } - const ogTags = ` - - - - - ${ogImageUrl ? `` : ''} - - - - ${ogImageUrl ? `` : ''} - `; + const ogTags = generateOgTags(baseUrl, pageUrl, title, description, ogImageUrl); + + // Insert OG tags before + html = html.replace('', `${ogTags}`); + + // Update title + html = html.replace(/