feat(pre-matricula): dynamic open graph metadata for rich previews
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 2m5s
Details
Build and Deploy (Gitea) / build-and-deploy (push) Successful in 2m5s
Details
This commit is contained in:
parent
2db8d5687d
commit
a47f23d95a
|
|
@ -68,12 +68,21 @@ app.use(cors());
|
||||||
const cancelCache = new Set();
|
const cancelCache = new Set();
|
||||||
|
|
||||||
// === Gerador da Página Pública de Pré-Matrícula ===
|
// === Gerador da Página Pública de Pré-Matrícula ===
|
||||||
function getPreMatriculaHTML(slug) {
|
function getPreMatriculaHTML(slug, meta = {}) {
|
||||||
|
const titulo = meta.titulo || 'Pré-Matrícula Online';
|
||||||
|
const descricao = meta.descricao || 'Faça sua pré-matrícula.';
|
||||||
|
const logoUrl = meta.logoUrl || '';
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html lang="pt-BR">
|
<html lang="pt-BR">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
|
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
<title>Pré-Matrícula Online</title>
|
<title>${titulo}</title>
|
||||||
|
<meta name="description" content="${descricao}">
|
||||||
|
<meta property="og:title" content="${titulo}">
|
||||||
|
<meta property="og:description" content="${descricao}">
|
||||||
|
${logoUrl ? `<meta property="og:image" content="${logoUrl}"><meta property="og:image:width" content="300"><meta property="og:image:height" content="300">` : ''}
|
||||||
|
<meta property="og:type" content="website">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap" rel="stylesheet">
|
||||||
<style>
|
<style>
|
||||||
*{margin:0;padding:0;box-sizing:border-box}
|
*{margin:0;padding:0;box-sizing:border-box}
|
||||||
|
|
@ -4393,12 +4402,35 @@ async function startServer() {
|
||||||
try {
|
try {
|
||||||
// Verifica se a slug atual corresponde a alguma configuração de pré-matrícula publicada
|
// Verifica se a slug atual corresponde a alguma configuração de pré-matrícula publicada
|
||||||
const { rows } = await pool.query(
|
const { rows } = await pool.query(
|
||||||
'SELECT slug FROM prematricula_config WHERE slug = $1 LIMIT 1',
|
'SELECT slug, titulo, descricao, logo_url FROM prematricula_config WHERE slug = $1 LIMIT 1',
|
||||||
[slug]
|
[slug]
|
||||||
);
|
);
|
||||||
if (rows.length > 0) {
|
if (rows.length > 0) {
|
||||||
|
const cfg = rows[0];
|
||||||
|
// Buscar também dados da escola (logo global e nome) caso a logo específica não esteja definida
|
||||||
|
const configResult = await pool.query('SELECT nome, logo FROM configuracoes LIMIT 1');
|
||||||
|
const firstRow = configResult.rows[0];
|
||||||
|
const escolaNome = firstRow?.nome || 'EduManager';
|
||||||
|
const escolaLogo = firstRow?.logo || '';
|
||||||
|
|
||||||
|
const titulo = cfg.titulo || 'Pré-Matrícula Online';
|
||||||
|
const descricao = cfg.descricao || `Formulário de pré-matrícula para ${escolaNome}.`;
|
||||||
|
|
||||||
|
let logo = cfg.logo_url || escolaLogo;
|
||||||
|
let logoUrl = '';
|
||||||
|
if (logo) {
|
||||||
|
if (logo.startsWith('http')) {
|
||||||
|
logoUrl = logo;
|
||||||
|
} else {
|
||||||
|
const host = req.get('x-forwarded-host') || req.get('host') || 'localhost';
|
||||||
|
const protocol = req.get('x-forwarded-proto') || req.protocol || 'http';
|
||||||
|
const baseUrl = protocol + '://' + host;
|
||||||
|
logoUrl = baseUrl + (logo.startsWith('/') ? logo : '/' + logo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Se bater, serve a página pública renderizando a slug dinâmica!
|
// Se bater, serve a página pública renderizando a slug dinâmica!
|
||||||
return res.send(getPreMatriculaHTML(slug));
|
return res.send(getPreMatriculaHTML(slug, { titulo, descricao, logoUrl }));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('[PreMatricula:Router] Erro de roteamento dinâmico:', e);
|
console.error('[PreMatricula:Router] Erro de roteamento dinâmico:', e);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue