File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<script >
2- import { marked } from " marked" ;
32 import { formatDistance } from " date-fns" ;
43 import { onMount , onDestroy } from " svelte" ;
5- import { postProcessCitations } from " $lib/blockquoteCitations.js" ;
64
75 export let blip;
86
97 let currentTime = Date .now ();
108 let timeUpdateInterval;
119
12- function renderMarkdown (markdown ) {
13- let html = marked (markdown || " " );
14- html = postProcessCitations (html);
15- return html;
16- }
17-
1810 function getISODate (date ) {
1911 return date .toISOString ();
2012 }
8173 {getAbsoluteDate (createdAtDate )}
8274 </time >
8375 </div >
84- <div class ="blip-content" >{@html renderMarkdown ( blip .content ) }</div >
76+ <div class ="blip-content" >{@html blip .renderedContent }</div >
8577</div >
8678
8779<style >
Original file line number Diff line number Diff line change 11import { error } from "@sveltejs/kit" ;
22import { getBlips } from "../lib/sanity.js" ;
3+ import { marked } from "marked" ;
4+ import { postProcessCitations } from "$lib/blockquoteCitations.js" ;
5+
6+ function renderMarkdown ( markdown ) {
7+ let html = marked ( markdown || "" ) ;
8+ html = postProcessCitations ( html ) ;
9+ return html ;
10+ }
311
412export async function load ( ) {
513 try {
614 const data = await getBlips ( ) ;
715
16+ // Render markdown server-side
17+ const blipsWithRenderedContent = data . blips . map ( ( blip ) => ( {
18+ ...blip ,
19+ renderedContent : renderMarkdown ( blip . content ) ,
20+ } ) ) ;
21+
822 return {
9- blips : data . blips ,
23+ blips : blipsWithRenderedContent ,
24+ allBlipsShown : data . allBlipsShown ,
1025 } ;
1126 } catch ( err ) {
1227 throw error ( 500 , `Failed to load blips: ${ err . message } ` ) ;
You can’t perform that action at this time.
0 commit comments