diff --git a/src/components/Library.astro b/src/components/Library.astro index dc9c7ef..d490aa5 100644 --- a/src/components/Library.astro +++ b/src/components/Library.astro @@ -16,6 +16,7 @@ export interface Props { import type { Props } from './Library.astro'; import type { AppConfig } from '../pages/index.astro'; import { getPostCard, renderPost } from '../utils/library' +import { cozify } from '../utils/sanitizer'; const cache = await caches.open('cozy-reader'); let url= new URL(window.location.href); // only cached unencoded url param @@ -57,10 +58,12 @@ export interface Props { let responseText; const fullResponse = await cache.match(url) - fullResponse?.text().then(data => { + fullResponse?.text().then(async data => { responseText = data; + const { baseUrl } = deserialize('app-config'); + const cleanedResponse = await cozify(responseText, baseUrl) const html = document.createElement('html'); - html.innerHTML = responseText; + html.innerHTML = cleanedResponse; const title = html.querySelector('meta[property="cozy:title"]')?.getAttribute('content'); if (title === 'Something is not right') { cache.delete(url); @@ -74,7 +77,7 @@ export interface Props { e.preventDefault(); localStorage.setItem('scrollPosition', window.scrollY.toString()); scrollTo(0,0); - renderPost(responseText, url, routerOutlet) + renderPost(cleanedResponse, url, routerOutlet) } const item = document.createElement('li'); item.appendChild(link); @@ -95,9 +98,11 @@ export interface Props { } const fullResponse = await cache.match(url) - fullResponse?.text().then(data => { + fullResponse?.text().then(async (data) => { const responseText = data; - renderPost(responseText, url, routerOutlet, true); + const { baseUrl } = deserialize('app-config'); + const cleanedResponse = await cozify(responseText, baseUrl); + renderPost(cleanedResponse, url, routerOutlet, true); if (isHome) { const scrollPosition = localStorage.getItem('scrollPosition'); scrollTo(0, scrollPosition ? parseInt(scrollPosition) : 0); diff --git a/src/pages/index.astro b/src/pages/index.astro index 3fe09d4..8207b00 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -9,6 +9,7 @@ import Footer from "../components/Footer.astro"; const appConfig = { routerOutlet: 'router-outlet', + baseUrl: Astro.url.origin }; export type AppConfig = typeof appConfig;