Update image links for gallery items
Update thumbnail, large, and full image URLs in server/gallery-data.json. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 517dfa7b-26ac-463d-a6e1-a58c6df97188 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 067bace9-cddb-4e5a-b83a-5d201af16aea Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/517dfa7b-26ac-463d-a6e1-a58c6df97188/EtK2Sno Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
30d1cde135
commit
25c3d0bb14
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,11 @@
|
||||
import express, { type Express } from "express";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import { storage } from "./storage";
|
||||
|
||||
function escapeHtml(str: string): string {
|
||||
return str.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
|
||||
export function serveStatic(app: Express) {
|
||||
const distPath = path.resolve(__dirname, "public");
|
||||
@ -12,8 +17,48 @@ export function serveStatic(app: Express) {
|
||||
|
||||
app.use(express.static(distPath));
|
||||
|
||||
// fall through to index.html if the file doesn't exist
|
||||
app.use("/{*path}", (_req, res) => {
|
||||
res.sendFile(path.resolve(distPath, "index.html"));
|
||||
app.use("/{*path}", async (req, res) => {
|
||||
const url = req.originalUrl;
|
||||
const indexPath = path.resolve(distPath, "index.html");
|
||||
|
||||
const articleMatch = url.match(/^\/article\/([^?#]+)/);
|
||||
if (articleMatch) {
|
||||
try {
|
||||
const slug = decodeURIComponent(articleMatch[1]);
|
||||
const article = await storage.getArticleBySlug(slug);
|
||||
if (article) {
|
||||
const host = req.get("host") || "folx.tv";
|
||||
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}`) : "";
|
||||
|
||||
let template = await fs.promises.readFile(indexPath, "utf-8");
|
||||
|
||||
const ogTags = [
|
||||
`<meta property="og:title" content="${escapeHtml(article.title)}" />`,
|
||||
`<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: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>`,
|
||||
].filter(Boolean).join("\n ");
|
||||
|
||||
template = template.replace(/<meta property="og:[^"]*"[^>]*\/>\s*/g, "");
|
||||
template = template.replace(/<title>.*?<\/title>/, ogTags);
|
||||
|
||||
res.status(200).set({ "Content-Type": "text/html" }).end(template);
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
res.sendFile(indexPath);
|
||||
});
|
||||
}
|
||||
|
||||
@ -79,18 +79,8 @@ export async function setupVite(server: Server, app: Express) {
|
||||
`<title>${escapeHtml(article.title)} - Folx Music Television</title>`,
|
||||
].filter(Boolean).join("\n ");
|
||||
|
||||
template = template.replace(
|
||||
/<title>.*?<\/title>/,
|
||||
ogTags
|
||||
);
|
||||
template = template.replace(
|
||||
/<meta property="og:title"[^>]*\/>\s*/,
|
||||
""
|
||||
);
|
||||
template = template.replace(
|
||||
/<meta property="og:description"[^>]*\/>\s*/,
|
||||
""
|
||||
);
|
||||
template = template.replace(/<meta property="og:[^"]*"[^>]*\/>\s*/g, "");
|
||||
template = template.replace(/<title>.*?<\/title>/, ogTags);
|
||||
}
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user