Related questions
+Answered by Nate
+diff --git a/server.js b/server.js index 4ae15ef..22a8310 100644 --- a/server.js +++ b/server.js @@ -2531,7 +2531,8 @@ app.get('/api/admin-questions', requireAdminAuth, (_req, res) => { // Get only approved public questions (for homepage) app.get('/api/questions', (_req, res) => { - const publicQuestions = questions.filter(q => q.isApproved === true && q.answer && q.answer.trim().length > 0) + const sourceQuestions = draftQuestions ?? questions + const publicQuestions = sourceQuestions.filter(q => q.isApproved === true && q.answer && q.answer.trim().length > 0) res.json({ questions: publicQuestions }) }) @@ -2917,6 +2918,59 @@ app.use('/images', express.static(DIST_IMAGES_DIR)) app.use('/images', express.static(PUBLIC_IMAGES_DIR)) app.use('/uploads', express.static(UPLOADS_DIR)) +// Per-question social share stub — serves question-specific OG tags so +// platforms (X, Facebook) render a rich preview card. After the crawl +// delay the page immediately redirects the human visitor to the real SPA URL. +app.get('/questions/share/:id', (req, res) => { + const id = req.params.id + if (!id || !/^[\w-]{1,120}$/.test(id)) { + res.redirect(302, '/questions') + return + } + const sourceQuestions = draftQuestions ?? questions + const question = sourceQuestions.find(q => q.id === id && q.isApproved === true && q.answer) + if (!question) { + res.redirect(302, '/questions') + return + } + + const BASE = 'https://versebyversewithnate.us' + const canonicalUrl = `${BASE}/questions#qa-${encodeURIComponent(id)}` + const shareUrl = `${BASE}/questions/share/${encodeURIComponent(id)}` + const ogTitle = escapeHtml(question.question.length > 100 + ? `${question.question.slice(0, 97)}\u2026` + : question.question) + const answerSnippet = question.answer.replace(/\n+/g, ' ').trim() + const ogDescription = escapeHtml(answerSnippet.length > 200 + ? `${answerSnippet.slice(0, 197)}\u2026` + : answerSnippet) + const ogImage = `${BASE}/images/banner.png` + + res.type('html').send(` + +
+ +Loading questions…
+Loading questions...
) : questions.length === 0 ? (No questions have been answered yet. Submit yours below!
No matching questions found. Submit your question
+No matches for this search yet.
+ {topSuggestedTopic && ( ++ Try browsing questions. +
+ )} + {mostHelpfulQuestion && ( ++ Or jump to . +
+ )} +Submit your question and Nate may add it here.
{question.question}
- {expanded[question.id] ? '▲' : '▼'} -Related questions
-- — Answered by Nate -
-+ {filteredQuestions.length} result{filteredQuestions.length === 1 ? '' : 's'} + {normalizedSearch && for "{normalizedSearch}"} + {filteredQuestions.length > 0 && · Showing {pageStart + 1}-{pageEnd}} +
+Related questions
+Answered by Nate
+