Skip to content

Commit 6198a71

Browse files
committed
id with release id will now be applied to all elements
1 parent f6ec86e commit 6198a71

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<script setup lang="ts">
2-
const { info } = defineProps<{ info: ChangelogMarkdownInfo }>()
2+
const { info, tpTarget } = defineProps<{
3+
info: ChangelogMarkdownInfo
4+
tpTarget?: HTMLElement | null
5+
}>()
36
47
const { data } = useLazyFetch(() => `/api/changelog/md/${info.provider}/${info.repo}/${info.path}`)
58
</script>
69
<template>
7-
<div v-if="data?.toc && data.toc.length > 1" class="flex justify-end mt-3">
10+
<Teleport
11+
v-if="data?.toc && data.toc.length > 1 && !!tpTarget"
12+
:to="tpTarget"
13+
class="flex justify-end mt-3"
14+
>
815
<ReadmeTocDropdown :toc="data.toc" class="justify-self-end" />
9-
</div>
16+
</Teleport>
1017
<Readme v-if="data?.html" :html="data.html"></Readme>
1118
</template>

app/pages/package-changes/[...path].vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ definePageMeta({
33
name: 'changes',
44
path: '/package-changes/:path+',
55
alias: ['/package/changes/:path+', '/changes/:path+'],
6-
scrollMargin: 130,
6+
scrollMargin: 140,
77
})
88
99
/// routing
@@ -65,12 +65,14 @@ watch(
6565
// getting info
6666
6767
const { data: changelog, pending } = usePackageChangelog(packageName, version)
68+
69+
const header = useTemplateRef('header')
6870
</script>
6971
<template>
7072
<main class="flex-1 flex flex-col">
7173
<header class="border-b border-border bg-bg sticky top-14 z-20">
7274
<div class="container pt-4 pb-3">
73-
<div class="flex items-center gap-2 mb-3 flex-wrap min-w-0">
75+
<div class="flex items-center gap-2 mb-3 flex-wrap min-w-0" ref="header">
7476
<h1
7577
class="font-mono text-lg sm:text-xl font-semibold text-fg hover:text-fg-muted transition-colors truncate"
7678
>
@@ -87,13 +89,18 @@ const { data: changelog, pending } = usePackageChangelog(packageName, version)
8789
:dist-tags="pkg['dist-tags']"
8890
:url-pattern="versionUrlPattern"
8991
/>
92+
<div class="flex-1"></div>
9093
</div>
9194
</div>
9295
</header>
9396

9497
<section class="container w-full" v-if="changelog">
9598
<LazyChangelogReleases v-if="changelog.type == 'release'" :info="changelog" />
96-
<LazyChangelogMarkdown v-else-if="changelog.type == 'md'" :info="changelog" />
99+
<LazyChangelogMarkdown
100+
v-else-if="changelog.type == 'md'"
101+
:info="changelog"
102+
:tpTarget="header"
103+
/>
97104
<p v-else-if="!pending" class="mt-5">{{ $t('changelog.no_logs') }}</p>
98105
</section>
99106
</main>

server/utils/changelog/markdown.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { marked, type Tokens } from 'marked'
1+
import { type Tokens, marked } from 'marked'
22
import {
3+
type prefixId as prefixIdFn,
34
ALLOWED_ATTR,
45
ALLOWED_TAGS,
56
calculateSemanticDepth,
67
isNpmJsUrlThatCanBeRedirected,
7-
prefixId,
88
slugify,
99
stripHtmlTags,
1010
} from '../readme'
@@ -112,6 +112,14 @@ export async function changelogRenderer(mdRepoInfo: MarkdownRepoInfo) {
112112
return `<h${semanticLevel} id="${id}" data-level="${depth}">${text} <a content-none href="#${id}"><span class="i-lucide:link size-[1em]" aria-hidden="true"></span></a></h${semanticLevel}>\n`
113113
}
114114

115+
// Helper to prefix id attributes with 'user-content-'
116+
const prefixId: typeof prefixIdFn = (tagName: string, attribs: sanitizeHtml.Attributes) => {
117+
if (attribs.id && !attribs.id.startsWith('user-content-')) {
118+
attribs.id = `${idPrefix}-${attribs.id}`
119+
}
120+
return { tagName, attribs }
121+
}
122+
115123
return {
116124
html: sanitizeRawHTML(
117125
convertToEmoji(
@@ -120,13 +128,18 @@ export async function changelogRenderer(mdRepoInfo: MarkdownRepoInfo) {
120128
}) as string,
121129
),
122130
mdRepoInfo,
131+
prefixId,
123132
),
124133
toc,
125134
}
126135
}
127136
}
128137

129-
export function sanitizeRawHTML(rawHtml: string, mdRepoInfo: MarkdownRepoInfo) {
138+
export function sanitizeRawHTML(
139+
rawHtml: string,
140+
mdRepoInfo: MarkdownRepoInfo,
141+
prefixId: typeof prefixIdFn,
142+
) {
130143
return sanitizeHtml(rawHtml, {
131144
allowedTags: ALLOWED_TAGS,
132145
allowedAttributes: ALLOWED_ATTR,

0 commit comments

Comments
 (0)