Skip to content

Commit 632c4a3

Browse files
SkyBird233MingcongBai
authored andcommitted
feat(makrdown detail): add an option to show title
1 parent 8d9e65d commit 632c4a3

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/components/MarkdownDetail.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
<script setup>
22
import PageNotFound from './PageNotFound.vue';
33
import { useRoute } from 'vue-router';
4-
import { shallowRef, defineAsyncComponent, watch } from 'vue';
4+
import {
5+
shallowRef,
6+
defineAsyncComponent,
7+
watch,
8+
useTemplateRef,
9+
computed
10+
} from 'vue';
11+
import CategorySecond from './CategorySecond.vue';
512
613
const props = defineProps({
714
articles: {
815
type: Object,
916
required: true
1017
},
11-
title: String,
18+
showTitle: {
19+
type: Boolean,
20+
default: false
21+
},
22+
defaultTitle: String,
1223
pathPrefix: String,
1324
pathSuffix: String
1425
});
@@ -17,6 +28,10 @@ const props = defineProps({
1728
const route = useRoute();
1829
const loadError = shallowRef(false);
1930
const articleComponent = shallowRef();
31+
const articleComponentRef = useTemplateRef('articleComponentRef');
32+
const articleTitle = computed(
33+
() => articleComponentRef.value?.frontmatter.title
34+
);
2035
2136
function loadArticle(slug) {
2237
const path = `${props.pathPrefix ?? './articles/'}${slug.split('#')[0]}${props.pathSuffix ?? '.md'}`;
@@ -44,7 +59,13 @@ watch(
4459
<PageNotFound />
4560
</template>
4661
<template v-else>
47-
<component class="vuepress-markdown-body" :is="articleComponent" />
62+
<CategorySecond
63+
v-if="showTitle"
64+
:title="articleTitle ?? defaultTitle" />
65+
<component
66+
ref="articleComponentRef"
67+
class="vuepress-markdown-body"
68+
:is="articleComponent" />
4869
</template>
4970
</div>
5071
</template>

src/pages/crowdsourcing/CrowdsourcingDetail.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const articles = import.meta.glob('./articles/*.zh.md');
77
<template>
88
<MarkdownDetail
99
:articles="articles"
10+
:show-title="true"
1011
default-title="众筹详情"
1112
path-suffix=".zh.md" />
1213
</template>

0 commit comments

Comments
 (0)