feat: SEO-friendly share URLs for news posts
- News posts now share as /news/slug-shortguid - Native posts still use /p/id - Short guid (8 chars) appended to slug for uniqueness Example: /news/quebec-vows-protect-aerospace-55217e2d Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
cd9ab30ab7
commit
498b41a2bf
|
|
@ -695,8 +695,20 @@ export default function PostDetailModal({ post, onClose, onPostUpdated, onPostDe
|
|||
}, [postId, liked, post?.guid, post?.app_id]);
|
||||
|
||||
const handleShare = useCallback(async () => {
|
||||
if (!postId) return;
|
||||
const shareUrl = `${window.location.origin}/p/${postId}`;
|
||||
if (!postId && !post?.guid) return;
|
||||
let shareUrl;
|
||||
if (post?.app_id && post?.guid) {
|
||||
// SEO-friendly URL: /news/slug-shortguid
|
||||
const slug = (post?.title || "post")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
.slice(0, 50);
|
||||
const shortGuid = post.guid.slice(0, 8);
|
||||
shareUrl = `${window.location.origin}/news/${slug}-${shortGuid}`;
|
||||
} else {
|
||||
shareUrl = `${window.location.origin}/p/${postId}`;
|
||||
}
|
||||
if (navigator.share) { try { await navigator.share({ title: post?.title, url: shareUrl }); } catch {} }
|
||||
else { navigator.clipboard?.writeText(shareUrl); }
|
||||
const res = await recordPostShare(postId, post?.guid, post?.app_id);
|
||||
|
|
|
|||
Loading…
Reference in New Issue