This commit is contained in:
Jason Schwarzenberger 2020-12-02 14:10:13 +13:00
parent 33c622216c
commit 888c341296
2 changed files with 16 additions and 2 deletions

View File

@ -7,9 +7,11 @@
let host = new URL(story.url || story.link).hostname.replace(/^www\./, ""); let host = new URL(story.url || story.link).hostname.replace(/^www\./, "");
let html; let html;
let title;
onMount(() => { onMount(() => {
html = DOMPurify.sanitize(story.text); html = DOMPurify.sanitize(story.text);
title = DOMPurify.sanitize(story.title);
}); });
</script> </script>
@ -67,7 +69,9 @@
<article class="article"> <article class="article">
<header class="article-header"> <header class="article-header">
<h1 class="article-title">{story.title}</h1> <h1 class="article-title">
{@html title}
</h1>
{#if story.url} {#if story.url}
<div>source: <a class="article-source" href={story.url}>{host}</a></div> <div>source: <a class="article-source" href={story.url}>{host}</a></div>
{/if} {/if}

View File

@ -1,9 +1,16 @@
<script> <script>
import DOMPurify from "dompurify";
import { onMount } from "svelte";
import { getLogoUrl } from "../utils/logos.js"; import { getLogoUrl } from "../utils/logos.js";
import StoryInfo from "../components/StoryInfo.svelte"; import StoryInfo from "../components/StoryInfo.svelte";
export let stories; export let stories;
const host = (url) => new URL(url).hostname.replace(/^www\./, ""); const host = (url) => new URL(url).hostname.replace(/^www\./, "");
let purify = () => "";
onMount(() => {
purify = (html) => DOMPurify.sanitize(html);
});
</script> </script>
<style> <style>
@ -41,7 +48,10 @@
alt="logo" alt="logo"
class="story-icon" class="story-icon"
style="height: 1rem; width: 1rem;" /> style="height: 1rem; width: 1rem;" />
<a class="story-title" rel="prefetch" href="/{story.id}">{story.title}</a> <a
class="story-title"
rel="prefetch"
href="/{story.id}">{@html purify(story.title)}</a>
<a <a
class="story-source" class="story-source"
href={story.url || story.link}>{host(story.url || story.link)}</a> href={story.url || story.link}>{host(story.url || story.link)}</a>