Improve video sharing functionality and page meta tags

Update `bunny-video-modal.tsx` to support custom share domains and modify `VideoPage.tsx` to dynamically update meta tags (title, description, Open Graph, Twitter Card) for enhanced social sharing, using `VITE_SHARE_DOMAIN` environment variable for custom domain configuration.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 074b0e4c-6171-43bd-aa98-f9e04623ca14
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/074b0e4c-6171-43bd-aa98-f9e04623ca14/Sy6XHzr
This commit is contained in:
sebastjanartic 2025-08-30 19:58:59 +00:00
parent 46add6e4d5
commit 4b415de2c9
2 changed files with 52 additions and 2 deletions

View File

@ -111,7 +111,9 @@ export default function BunnyVideoModal({ video, isOpen, onClose, onEdit, videos
const getShareUrl = () => { const getShareUrl = () => {
if (!video?.id) return window.location.origin; if (!video?.id) return window.location.origin;
return `${window.location.origin}?video=${video.id}`; // Use custom domain if set, otherwise current domain
const baseUrl = import.meta.env.VITE_SHARE_DOMAIN || window.location.origin;
return `${baseUrl}/video/${video.id}`;
}; };
const copyToClipboard = async () => { const copyToClipboard = async () => {

View File

@ -70,6 +70,52 @@ export default function VideoPage() {
const recommendedVideos = recommendedResponse?.videos?.filter(v => v.id !== videoId) || []; const recommendedVideos = recommendedResponse?.videos?.filter(v => v.id !== videoId) || [];
// Update page meta tags for social sharing
useEffect(() => {
if (currentVideo) {
// Update page title
document.title = `${currentVideo.title} | go4.video`;
// Update meta description
const metaDescription = document.querySelector('meta[name="description"]');
if (metaDescription) {
metaDescription.setAttribute('content', currentVideo.description || `Watch ${currentVideo.title} on go4.video`);
}
// Update Open Graph tags
const updateMetaTag = (property: string, content: string) => {
let meta = document.querySelector(`meta[property="${property}"]`);
if (!meta) {
meta = document.createElement('meta');
meta.setAttribute('property', property);
document.head.appendChild(meta);
}
meta.setAttribute('content', content);
};
updateMetaTag('og:title', currentVideo.title);
updateMetaTag('og:description', currentVideo.description || `Watch ${currentVideo.title} on go4.video`);
updateMetaTag('og:image', currentVideo.thumbnailUrl);
updateMetaTag('og:url', window.location.href);
updateMetaTag('og:type', 'video.other');
updateMetaTag('og:video:duration', currentVideo.duration.toString());
// Update Twitter Card tags
const updateTwitterTag = (name: string, content: string) => {
let meta = document.querySelector(`meta[name="${name}"]`);
if (!meta) {
meta = document.createElement('meta');
meta.setAttribute('name', name);
document.head.appendChild(meta);
}
meta.setAttribute('content', content);
};
updateTwitterTag('twitter:title', currentVideo.title);
updateTwitterTag('twitter:description', currentVideo.description || `Watch ${currentVideo.title} on go4.video`);
updateTwitterTag('twitter:image', currentVideo.thumbnailUrl);
}
}, [currentVideo]);
// Track video view // Track video view
@ -85,7 +131,9 @@ export default function VideoPage() {
const getShareUrl = () => { const getShareUrl = () => {
if (!currentVideo?.id) return window.location.origin; if (!currentVideo?.id) return window.location.origin;
return `${window.location.origin}/video/${currentVideo.id}`; // Use custom domain if set, otherwise current domain
const baseUrl = import.meta.env.VITE_SHARE_DOMAIN || window.location.origin;
return `${baseUrl}/video/${currentVideo.id}`;
}; };
const copyToClipboard = async () => { const copyToClipboard = async () => {