From d9d55620a6f4f44b2c5069da107b2b3b111390ed Mon Sep 17 00:00:00 2001
From: navewindre <boneyaard@gmail.com>
Date: Wed, 11 Feb 2026 02:05:39 +0100
Subject: seo renderer

---
 web/src/blog.tsx | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

(limited to 'web/src/blog.tsx')

diff --git a/web/src/blog.tsx b/web/src/blog.tsx
index bfef434..1fcfec2 100644
--- a/web/src/blog.tsx
+++ b/web/src/blog.tsx
@@ -8,12 +8,9 @@ let reqErr = 0;
 
 let hljs = null;
 let hljs_imported = 0;
-async function importHlJs() {
-  if( hljs ) return;
-  if( hljs_imported ) return;
 
-  hljs_imported = 1;
-  hljs = ( await import( 'highlight.js' ) ).default;
+async function highlightCode() {
+  if( !hljs || !hljs_imported ) return setTimeout( highlightCode, 500 );
 
   const elements = $( "code" );
   elements.each( ( _, e ) => {
@@ -21,6 +18,14 @@ async function importHlJs() {
   } );
 }
 
+async function importHlJs() {
+  if( hljs ) return;
+  if( hljs_imported ) return;
+
+  hljs_imported = 1;
+  hljs = ( await import( 'highlight.js' ) ).default;
+}
+
 function urlForHref( href: string, isdir: boolean ) {
   const url = new URL( window.location.href );
   let path = url.pathname;
@@ -105,19 +110,20 @@ async function populatePost() {
       $( "title" ).html( title );
     }
 
-    importHlJs();
 
     $( "#package-entries" ).find( ".spinner" ).remove();
     $( "#package-entries" ).css( "display", "none" );
     $( "#blog-entry" ).html( text );
     $( "#blog-entry" ).css( "display", "flex" );
     $( "#back-btn" ).css( "display", "block" );
+    setTimeout( highlightCode );
   } catch( e ) {
     return populateEntries();
   }
 }
 
 export default function Blog() {
+  importHlJs();
   entries = [];
   reqErr = 0;
   setTimeout( async () => {
-- 
cgit v1.2.3

