bep40 commited on
Commit
7e31322
·
verified ·
1 Parent(s): 4839c2c

Fix doShare to prefer post_id in /s?post_id= for reliable sharing

Browse files
Files changed (1) hide show
  1. static/index_v2.html +7 -3
static/index_v2.html CHANGED
@@ -35,12 +35,16 @@ function showView(id){document.querySelectorAll('.view').forEach(v=>v.classList.
35
  function switchCat(id){document.querySelectorAll('.cat').forEach(c=>c.classList.remove('active'));document.querySelector('[data-cat="'+id+'"]')?.classList.add('active');document.querySelectorAll('.view').forEach(v=>v.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home')document.getElementById('view-home').classList.add('active');else if(id==='news-all'){document.getElementById('view-cat').classList.add('active');loadNewsTab()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
36
  function toast(msg){let t=document.getElementById('progress-toast');if(t){t.textContent=msg;t.style.display='block';setTimeout(()=>{t.style.display='none'},3500)}}
37
  function doShare(title,url,img,postId){
38
- // Create SEO-friendly URL with slug
39
- const slug = title.toLowerCase()
 
 
 
40
  .normalize('NFKD').replace(/[\u0300-\u036f]/g,'')
41
  .replace(/[^a-z0-9]+/g,'-').replace(/^-+|-+$/g,'')
42
  .substring(0,60) || 'article';
43
- const shareUrl = SPACE + '/s/' + slug + '?url=' + encodeURIComponent(url) + '&img=' + encodeURIComponent(img||'');
 
44
  if(navigator.share) navigator.share({title,url:shareUrl}).catch(()=>{});
45
  else{ navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!\n'+shareUrl)).catch(()=>{}) }
46
  }
 
35
  function switchCat(id){document.querySelectorAll('.cat').forEach(c=>c.classList.remove('active'));document.querySelector('[data-cat="'+id+'"]')?.classList.add('active');document.querySelectorAll('.view').forEach(v=>v.classList.remove('active'));document.querySelectorAll('video').forEach(v=>{v.pause();if(v._hls){v._hls.destroy();v._hls=null}});document.querySelectorAll('iframe[data-yt-src]').forEach(f=>{f.src=''});if(id==='home')document.getElementById('view-home').classList.add('active');else if(id==='news-all'){document.getElementById('view-cat').classList.add('active');loadNewsTab()}else{document.getElementById('view-cat').classList.add('active');loadCat(id)}}
36
  function toast(msg){let t=document.getElementById('progress-toast');if(t){t.textContent=msg;t.style.display='block';setTimeout(()=>{t.style.display='none'},3500)}}
37
  function doShare(title,url,img,postId){
38
+ var shareUrl;
39
+ if(postId){
40
+ shareUrl = SPACE+'/s?post_id='+encodeURIComponent(postId)+'&title='+encodeURIComponent(title);
41
+ } else {
42
+ const slug = title.toLowerCase()
43
  .normalize('NFKD').replace(/[\u0300-\u036f]/g,'')
44
  .replace(/[^a-z0-9]+/g,'-').replace(/^-+|-+$/g,'')
45
  .substring(0,60) || 'article';
46
+ shareUrl = SPACE + '/s/' + slug + '?url=' + encodeURIComponent(url) + '&img=' + encodeURIComponent(img||'');
47
+ }
48
  if(navigator.share) navigator.share({title,url:shareUrl}).catch(()=>{});
49
  else{ navigator.clipboard.writeText(shareUrl).then(()=>alert('Đã sao chép!\n'+shareUrl)).catch(()=>{}) }
50
  }