diff options
Diffstat (limited to 'web/src/blog.tsx')
| -rw-r--r-- | web/src/blog.tsx | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/web/src/blog.tsx b/web/src/blog.tsx index 738dd7c..745afde 100644 --- a/web/src/blog.tsx +++ b/web/src/blog.tsx @@ -9,6 +9,8 @@ let reqErr = 0; let hljs = null; let hljs_imported = 0; +const page_meta = $( "meta[name=description]" ).attr( "content" ); + async function highlightCode() { if( !hljs || !hljs_imported ) return setTimeout( highlightCode, 500 ); @@ -92,6 +94,22 @@ function populateEntries() { } } +function updateMeta( is_post: boolean ) { + if( is_post ) { + const entry = $( "#blog-entry" ); + if( !entry.length ) + return; + + let text = entry[0].innerText; + if( text.length > 300 ) + text = text.slice( 0, 300 ) + "..."; + + $( "meta[name='description']" ).attr( "content", text ); + } else { + $( "meta[name='description']" ).attr( "content", page_meta ); + } +} + async function populatePost() { try { const res = await fetch( "https://networkheaven.net/" + getEndpoint() + ".html" ); @@ -107,17 +125,18 @@ async function populatePost() { let title = text.substring( titles + 7, titlee - 1 ); title = title.replace( /\n/g, "" ); $( ".page-title h3" )[0].innerText = title; - $( "title" ).html( title ); + $( "title" ).html( title + " - networkheaven.net" ); } - $( "#package-entries" ).find( ".spinner" ).remove(); $( "#package-entries" ).css( "display", "none" ); $( "#blog-entry" ).html( text ); $( "#blog-entry" ).css( "display", "flex" ); $( "#back-btn" ).css( "display", "block" ); + updateMeta( true ); setTimeout( highlightCode ); } catch( e ) { + updateMeta( false ); return populateEntries(); } } @@ -134,6 +153,11 @@ export default function Blog() { } } ); + JSX.onPreNavigate( () => { + updateMeta( false ); + JSX.onPreNavigate( () => {} ); + } ); + setTimeout( () => { if( getEndpoint() == 'posts/' ) return populateEntries(); |
