Skip to content

Commit

Permalink
fix(headings): don't generate link if id is missing (#1893)
Browse files Browse the repository at this point in the history
  • Loading branch information
nobkd committed Feb 7, 2023
1 parent 8d06196 commit ee83de8
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH1.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h1 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 1
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH2.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h2 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 2
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH3.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h3 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 3
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH4.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h4 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 4
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH5.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h5 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 5
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components/Prose/ProseH6.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<h6 :id="id">
<a v-if="generate" :href="`#${id}`">
<a v-if="id && generate" :href="`#${id}`">
<slot />
</a>
<slot v-else />
Expand All @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useRuntimeConfig } from '#imports'
defineProps<{ id: string }>()
defineProps<{ id?: string }>()
const heading = 6
const { anchorLinks } = useRuntimeConfig().public.content
const generate = anchorLinks?.depth >= heading && !anchorLinks?.exclude.includes(heading)
Expand Down

0 comments on commit ee83de8

Please sign in to comment.