From d9d55620a6f4f44b2c5069da107b2b3b111390ed Mon Sep 17 00:00:00 2001 From: navewindre Date: Wed, 11 Feb 2026 02:05:39 +0100 Subject: seo renderer --- web/src/blog.tsx | 18 ++++++++++++------ web/src/index-page.tsx | 3 +++ web/src/index.html | 7 +++++-- web/src/jsx.tsx | 20 +++++++++++++++++--- 4 files changed, 37 insertions(+), 11 deletions(-) (limited to 'web/src') 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 () => { diff --git a/web/src/index-page.tsx b/web/src/index-page.tsx index a754ef6..71a2fdc 100644 --- a/web/src/index-page.tsx +++ b/web/src/index-page.tsx @@ -3,6 +3,8 @@ import Home from "./home"; import Blog from "./blog"; import Pkgs from "./pkg"; +JSX.setDefaultTitle( "networkheaven.net" ); + JSX.addRoute( "/", () => ); JSX.addRoute( "/blog", () => ); JSX.addRoute( "/blog/*", () => ); @@ -10,6 +12,7 @@ JSX.addRoute( "/pkg", () => ); JSX.addRoute( "/pkg/*", () => ); window.onpopstate = JSX.onPopState; +document.head.appendChild( ); const url = new URL( window.location.href ); JSX.navigateParams( url.pathname, url.searchParams.entries() ); diff --git a/web/src/index.html b/web/src/index.html index b14f5b5..68eba57 100644 --- a/web/src/index.html +++ b/web/src/index.html @@ -3,11 +3,14 @@ - + networkheaven.net - + +
diff --git a/web/src/jsx.tsx b/web/src/jsx.tsx index a92fc11..749e93f 100644 --- a/web/src/jsx.tsx +++ b/web/src/jsx.tsx @@ -11,8 +11,9 @@ export interface Route { const routes: Route[] = []; let err404page = "/"; let rootId = "moneyjsx-root"; -let onprenavigate: Function = () => {}; -let onpostnavigate: Function = () => {}; +let defaultTitle = ""; +export let onprenavigate: Function = () => {}; +export let onpostnavigate: Function = () => {}; function routeForPath( route: string ) : Function | null { if( !routes[route] ) { @@ -37,6 +38,10 @@ export function setRootId( rootId: string ) { rootId = rootId; } +export function setDefaultTitle( title: string ) { + defaultTitle = title; +} + /** * adds a route component to the routes list * the component function must return either a jquery or a DOM element @@ -87,6 +92,7 @@ export function navigate( route: string ) { window.history.pushState( {}, null, url.href ); onprenavigate(); + setTitle(); const el = $( cb() ); curRoute = cb; @@ -111,6 +117,7 @@ export function navigateParams( route: string, params: any ) { window.history.pushState( {}, null, url.href ); onprenavigate(); + setTitle(); const el = $( cb() ); curRoute = cb; @@ -143,6 +150,7 @@ export function navigateParamsSilent( route: string, params: any ) { return navigateSilent( err404page ); onprenavigate(); + setTitle(); const el = $( cb() ); curRoute = cb; @@ -162,6 +170,7 @@ export function navigateSilent( route: string ) { return navigateSilent( err404page ); onprenavigate(); + setTitle(); const el = $( cb() ); curRoute = cb; @@ -185,6 +194,7 @@ export function onPopState() { return; onprenavigate(); + setTitle(); const el = $( cb() ); curRoute = cb; @@ -251,7 +261,7 @@ export function createElement( tag: any, props: any, ...children: any ) { const lowercaseName = name.toLowerCase(); if( lowercaseName in window ) { - element.addEventListener( lowercaseName.substring(2 ), value ); + element.addEventListener( lowercaseName.substring( 2 ), value ); continue; } } @@ -288,3 +298,7 @@ export function createElement( tag: any, props: any, ...children: any ) { export function createFragment( props: any ) { return props.children; } + +function setTitle() { + document.title = defaultTitle; +} -- cgit v1.2.3