Restored to '3905f52571b4fa7e048e16d7a3b94ee66307d072'
Replit-Restored-To: 3905f52571
This commit is contained in:
+14
-4
@@ -7,6 +7,15 @@ function escapeHtml(str: string): string {
|
||||
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
|
||||
function ogImageUrl(coverImage: string, baseUrl: string): string {
|
||||
if (!coverImage) return "";
|
||||
let imgPath = coverImage;
|
||||
if (imgPath.endsWith(".webp")) {
|
||||
imgPath = imgPath.replace(/\.webp$/, ".jpg");
|
||||
}
|
||||
return imgPath.startsWith("http") ? imgPath : `${baseUrl}${imgPath}`;
|
||||
}
|
||||
|
||||
export function serveStatic(app: Express) {
|
||||
const distPath = path.resolve(__dirname, "public");
|
||||
if (!fs.existsSync(distPath)) {
|
||||
@@ -31,7 +40,7 @@ export function serveStatic(app: Express) {
|
||||
const protocol = req.get("x-forwarded-proto") || "https";
|
||||
const baseUrl = `${protocol}://${host}`;
|
||||
const articleUrl = `${baseUrl}/article/${article.slug}`;
|
||||
const imageUrl = article.coverImage ? (article.coverImage.startsWith("http") ? article.coverImage : `${baseUrl}${article.coverImage}`) : "";
|
||||
const imageUrl = ogImageUrl(article.coverImage || "", baseUrl);
|
||||
|
||||
let template = await fs.promises.readFile(indexPath, "utf-8");
|
||||
|
||||
@@ -40,13 +49,14 @@ export function serveStatic(app: Express) {
|
||||
`<meta property="og:description" content="${escapeHtml(article.excerpt)}" />`,
|
||||
`<meta property="og:type" content="article" />`,
|
||||
`<meta property="og:url" content="${escapeHtml(articleUrl)}" />`,
|
||||
imageUrl ? `<meta property="og:image" content="${escapeHtml(imageUrl)}" />` : "",
|
||||
`<meta property="og:image" content="${escapeHtml(imageUrl || `${baseUrl}/og-image.jpg`)}" />`,
|
||||
`<meta property="og:site_name" content="Folx Music Television" />`,
|
||||
`<meta name="twitter:card" content="summary_large_image" />`,
|
||||
`<meta name="twitter:title" content="${escapeHtml(article.title)}" />`,
|
||||
`<meta name="twitter:description" content="${escapeHtml(article.excerpt)}" />`,
|
||||
imageUrl ? `<meta name="twitter:image" content="${escapeHtml(imageUrl)}" />` : "",
|
||||
`<title>${escapeHtml(article.title)} - Folx Music Television</title>`,
|
||||
`<meta name="twitter:image" content="${escapeHtml(imageUrl || `${baseUrl}/og-image.jpg`)}" />`,
|
||||
`<meta name="description" content="${escapeHtml(article.excerpt)}" />`,
|
||||
`<title>${escapeHtml(article.title)} - Volksmusik & Schlager | Folx Music Television</title>`,
|
||||
].filter(Boolean).join("\n ");
|
||||
|
||||
template = template.replace(/<meta property="og:[^"]*"[^>]*\/>\s*/g, "");
|
||||
|
||||
Reference in New Issue
Block a user