|
|
@ -1,8 +1,8 @@ |
|
|
<script setup lang="ts"> |
|
|
<script setup lang="ts"> |
|
|
import { ref, computed, watch } from 'vue' |
|
|
import { ref, computed, watch } from 'vue' |
|
|
import { useRoute } from 'vue-router' |
|
|
import { useRoute } from 'vue-router' |
|
|
import DOMPurify from 'dompurify' |
|
|
|
|
|
import { articleApi } from '@/api/client' |
|
|
import { articleApi } from '@/api/client' |
|
|
|
|
|
import { renderMarkdown } from '@/utils/markdown' |
|
|
import type { ArticleDetail } from '@/generated/api' |
|
|
import type { ArticleDetail } from '@/generated/api' |
|
|
|
|
|
|
|
|
const route = useRoute() |
|
|
const route = useRoute() |
|
|
@ -12,9 +12,9 @@ const error = ref<string | null>(null) |
|
|
|
|
|
|
|
|
const slug = computed(() => String(route.params.slug ?? '')) |
|
|
const slug = computed(() => String(route.params.slug ?? '')) |
|
|
|
|
|
|
|
|
const sanitizedContent = computed(() => { |
|
|
|
|
|
|
|
|
const renderedContent = computed(() => { |
|
|
if (!article.value?.content) return '' |
|
|
if (!article.value?.content) return '' |
|
|
return DOMPurify.sanitize(article.value.content) |
|
|
|
|
|
|
|
|
return renderMarkdown(article.value.content) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
function formatDate(iso?: string): string { |
|
|
function formatDate(iso?: string): string { |
|
|
@ -53,7 +53,7 @@ watch(slug, load, { immediate: true }) |
|
|
<div class="detail-tags"> |
|
|
<div class="detail-tags"> |
|
|
<span v-for="tag in article.tagNames" :key="tag" class="tag">{{ tag }}</span> |
|
|
<span v-for="tag in article.tagNames" :key="tag" class="tag">{{ tag }}</span> |
|
|
</div> |
|
|
</div> |
|
|
<div class="article-content" v-html="sanitizedContent"></div> |
|
|
|
|
|
|
|
|
<div class="article-content" v-html="renderedContent"></div> |
|
|
</article> |
|
|
</article> |
|
|
|
|
|
|
|
|
<p v-else-if="loading" class="hint-text">加载中...</p> |
|
|
<p v-else-if="loading" class="hint-text">加载中...</p> |
|
|
|