Skip to content

Commit

Permalink
hide comments for certain pages
Browse files Browse the repository at this point in the history
  • Loading branch information
octo-kumo committed Dec 11, 2024
1 parent 98b6770 commit c1aa08f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pages/c/[...content].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { NavItem, ParsedContent, TocLink } from "@nuxt/content";
import type { Ref } from "@vue/reactivity";
import type { ComputedRef } from "vue";
import type { ElTree } from "element-plus";
import isContentEmpty from "~/utils/is-content-empty";
const route = useRoute();
const path = (route.path.substring(2) || "/")
.replace(/(?!^)\/$/, ''); // strip trailing slash
Expand Down Expand Up @@ -156,7 +157,7 @@ const filterTreeNode: FilterNodeMethodFunction = (values: string[], data: TreeNo
</hover-text>
</el-text>

<ContentRenderer :value="doc" class="content mt-8" tag="section">
<ContentRenderer :value="doc" class="content mt-8" tag="section" v-if="!isContentEmpty(doc)">
<template #empty>
<!-- <el-empty description="No folder note" class="h-32 flex-auto" :image-size="80" /> -->
</template>
Expand All @@ -177,8 +178,9 @@ const filterTreeNode: FilterNodeMethodFunction = (values: string[], data: TreeNo
</kumo-link>
</div>
</article>
<lazy-comments class="print:hidden content-page-sections py-1" v-if="doc" />
<el-divider v-shared="'content-tree-sep'" class="print:hidden mx--3!" style="width: calc(100% + 1.5rem)" />
<lazy-comments class="print:hidden content-page-sections py-1" v-if="!isContentEmpty(doc)" />
<el-divider v-shared="'content-tree-sep'" class="print:hidden mx--3!" style="width: calc(100% + 1.5rem)"
v-if="!isContentEmpty(doc)" />
<lazy-writeup-statistics class="content-page-sections mb-1" v-if="(path === '/ctf') && docs" :docs="docs"
v-model="statsControl" />
</template>
Expand Down
12 changes: 12 additions & 0 deletions utils/is-content-empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { MarkdownNode, ParsedContent } from "@nuxt/content"

export default (content?: ParsedContent) => {
if (!content?.body?.children.length) return true
return empty(content.body);
}

function empty(node: MarkdownNode) {
if (node.value) return false;
if (node.children) return node.children.every(empty);
return true;
}

0 comments on commit c1aa08f

Please sign in to comment.