feat: photonify user and comment links

This commit is contained in:
Xyphyn committed 2023-08-27 12:18:18 -07:00
1 parent 5d68d02d3e
commit 22d0f63295
2 files changed
+31 -9

No files matched your search

+3 -9
View File
@@ -1,21 +1,15 @@
<script lang="ts">
import { md, mdInline } from '$lib/components/markdown/markdown'
import { md, mdInline, photonify } from '$lib/components/markdown/markdown'
export let source: string = ''
export let inline: boolean = false
function replaceURLs(node: HTMLElement) {
const postRegex = /^https:\/\/([a-zA-Z0-9.-]+)\/post\/(\d+)$/
const links = node.querySelectorAll('a')
links.forEach((l) => {
if (!postRegex.test(l.href)) return
const match = l.href.match(postRegex)
if (!match) return
l.href = `/post/${match?.[1]}/${match?.[2]}`
const photonified = photonify(l.href)
if (photonified) l.href = photonified
})
}