diff options
| author | navewindre <boneyaard@gmail.com> | 2026-02-16 18:50:27 +0100 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2026-02-16 18:50:27 +0100 |
| commit | 5d8ff6e73b2734c33badf09321fa346a6d144a49 (patch) | |
| tree | 9b71774722b5c386873d716707c1992574204642 /web/src/blog.tsx | |
| parent | e66257a6f66bf905d82c8df6e4e4d1a1509e0810 (diff) | |
cleanup
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(); |
