Skip to content

Commit

Permalink
feat: include mermaidjs
Browse files Browse the repository at this point in the history
  • Loading branch information
batleforc committed Sep 2, 2024
1 parent 38e5a1c commit 144d6e1
Show file tree
Hide file tree
Showing 6 changed files with 793 additions and 7 deletions.
5 changes: 4 additions & 1 deletion apps/front/src/component/Page/PageContent.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { BlockType, TitleBlock } from '../../markdown';
import PageTitle from './PageTitle.vue';
import VueMermaidString from 'vue-mermaid-string';
defineProps<{
Expand All @@ -14,6 +14,9 @@ defineProps<{
<PageTitle :value="content.value" :level="content.level" />
<div v-for="line in content.subBlocks" :key="line.value">
<p class="whitespace-pre" v-if="line.type === BlockType.string">{{ line.value }}</p>
<VueMermaidString class="py-2 pageCodeMermaid"
v-else-if="line.type === BlockType.startEndCodeBlock && line.additionalValue === 'mermaid'"
:value="line.value" />
<highlightjs class="py-2" v-else-if="line.type === BlockType.startEndCodeBlock" autodetect
:code="line.value" />
<div class="flex space-x-2" v-else-if="line.type === BlockType.checkbox">
Expand Down
23 changes: 23 additions & 0 deletions apps/front/src/stores/doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,28 @@ export const useDocStore = defineStore({
this.inited = true;
});
},
searchCategory(path: string): DocCategory | undefined {
if (!this.docContent) return;
return this.searchCategoryRecursive(`content/${path}`, this.docContent);
},
searchCategoryRecursive(
path: string,
category: DocCategory,
): DocCategory | undefined {
const path_split = path.split('/');
if (path_split.length === 1 && category.name === path_split[0]) {
return category;
}
for (const subCategory of category.sub_categories) {
if (subCategory.name === path_split[1]) {
const found = this.searchCategoryRecursive(
path_split.slice(1).join('/'),
subCategory,
);
if (found) return found;
}
}
return;
},
},
});
12 changes: 11 additions & 1 deletion apps/front/src/stores/page.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getPage, Page } from '@portfolio/api-client';
import { defineStore } from 'pinia';
import { useDocStore } from './doc';

export interface PageState {
pageLoading: boolean;
Expand All @@ -17,11 +18,20 @@ export const usePageStore = defineStore({
actions: {
fetchPage(path: string) {
if (this.pageLoading) return new Promise<void>((resolve) => resolve());
this.pageLoading = true;

if (this.pagePath === path) {
this.pageLoading = false;
return new Promise<void>((resolve) => resolve());
}
const doc = useDocStore();
if (!doc.inited) {
return doc.init().then(() => this.fetchPage(path));
}
this.pageLoading = true;
const category = doc.searchCategory(path);
if (category && category.has_index) {
path = `${path}/index`;
}
return getPage({ query: { path } })
.then((body) => {
if (body.status === 200) {
Expand Down
6 changes: 4 additions & 2 deletions apps/front/src/views/DocView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ let pathReactive = computed(() => {
const docStore = useDocStore();
const pageStore = usePageStore();
if (!docStore.inited && !docStore.docLoading) {
docStore.init()
docStore.init().then(() => {
pageStore.fetchPage(pathReactive.value);
});
}
if (pageStore.pageLoading === false && pageStore.pagePath !== pathReactive.value) {
else if (pageStore.pageLoading === false && pageStore.pagePath !== pathReactive.value) {
pageStore.fetchPage(pathReactive.value);
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"primevue": "^4.0.4",
"tslib": "^2.3.0",
"vue": "^3.3.4",
"vue-mermaid-string": "^6.0.0",
"vue-router": "^4.4.3"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 144d6e1

Please sign in to comment.