|
| 1 | +import DOMPurify from 'dompurify'; |
| 2 | +import { JSDOM } from 'jsdom'; |
| 3 | +import { marked } from 'marked'; |
| 4 | + |
| 5 | +const getMobilePrivacyPolicy = async () => { |
| 6 | + const renderer = { |
| 7 | + heading(text: string, level: number) { |
| 8 | + switch (level) { |
| 9 | + case 1: |
| 10 | + return ` |
| 11 | + <h${level} class="text-2xl pt-2 font-bold items-center justify-center text-center"> |
| 12 | + ${text} |
| 13 | + </h${level}>`; |
| 14 | + case 2: |
| 15 | + return ` |
| 16 | + <h${level} class="text-xl font-bold pt-8 pb-2"> |
| 17 | + ${text} |
| 18 | + </h${level}>`; |
| 19 | + default: |
| 20 | + return `<h${level} class="text-lg"> ${text} </h${level}>`; |
| 21 | + } |
| 22 | + }, |
| 23 | + blockquote(text: string) { |
| 24 | + return `<div class="w-full flex items-center justify-center"><blockquote class="bg-pink-500 rounded-full text-center dark:bg-orange-accent-dark dark:text-navy-blue-900 w-auto inline-block text-white px-4 my-4">${text}</blockquote></div>`; |
| 25 | + }, |
| 26 | + paragraph(text: string) { |
| 27 | + return `<p class="text-justify">${text}</p>`; |
| 28 | + }, |
| 29 | + link(href: string, title: string | null | undefined, text: string) { |
| 30 | + return `<a class="text-pink-500 dark:text-orange-accent-dark" href="${href}" title="${title}">${text}</a>`; |
| 31 | + }, |
| 32 | + }; |
| 33 | + |
| 34 | + marked.use({ renderer }); |
| 35 | + const markdown = await ( |
| 36 | + await fetch( |
| 37 | + 'https://raw.githubusercontent.com/lutralabs/documents/main/mobile-privacy-policy.md', |
| 38 | + { cache: 'no-store' } |
| 39 | + ) |
| 40 | + ).text(); |
| 41 | + const { window } = new JSDOM(''); |
| 42 | + const purify = DOMPurify(window); |
| 43 | + const html = purify.sanitize(await marked.parse(markdown)); |
| 44 | + return html; |
| 45 | +}; |
| 46 | + |
| 47 | +export default async function Page() { |
| 48 | + const pp = await getMobilePrivacyPolicy(); |
| 49 | + return ( |
| 50 | + <div |
| 51 | + className="h-full w-full max-w-4xl flex-1 flex-col p-6 sm:p-16" |
| 52 | + dangerouslySetInnerHTML={{ __html: pp }} |
| 53 | + /> |
| 54 | + ); |
| 55 | +} |
0 commit comments