Skip to content

πŸ“š The open-source, offline-first Notion, Obsidian & Confluence alternative. Advanced Markdown, multi-tenant teams, OIDC/SSO, and local S3 backups. Deploy in one command.

feat: public documents hierachy

Smaug673954e5f3430f6b
diff --git a/frontend/app/pages/(public)/doc/[id]/index.vue b/frontend/app/pages/(public)/doc/[id]/index.vue
index c177841a..636e4358 100644
--- a/frontend/app/pages/(public)/doc/[id]/index.vue
+++ b/frontend/app/pages/(public)/doc/[id]/index.vue
@@ -2,31 +2,43 @@
<template>
<div style="width: 100%; padding: 1rem 0">
<div
- v-if="!error"
+ v-if="!error && article"
class="reader"
:style="{
- marginRight: !isTablet && preferencesStore.get('hideTOC').value && isOpened ? '200px' : '0px',
+ marginRight: !isTablet && preferencesStore.get('hideTOC').value && isOpened && hasContent ? '200px' : '0px',
transition: 'margin 0.3s',
}"
>
<div class="doc-container">
+ <!-- Header for all node types -->
<DocumentCardHeader :doc="article" :public="true" style="margin: 20px 0" />
- <!-- eslint-disable-next-line vue/no-v-html -->
+
+ <!-- Document content if available -->
<article
- v-if="article"
+ v-if="hasContent"
ref="element"
:class="`${article.theme || preferencesStore.get('theme').value}-theme`"
style="max-width: 100%"
v-html="article.content_compiled"
/>
- <DocumentSkeleton v-else />
+
+ <!-- Hierarchical children tree -->
+ <HierarchyTree v-if="children.length > 0" :nodes="children" :parent-id="article.id" />
</div>
- <div v-if="!isTablet && !preferencesStore.get('hideTOC').value" class="toc">
+ <!-- Table of contents only for documents with content -->
+ <div v-if="!isTablet && !preferencesStore.get('hideTOC').value && hasContent" class="toc">
<TableOfContent :doc="article" :element="element" />
</div>
</div>
+ <!-- Loading state -->
+ <div v-else-if="!error" class="reader">
+ <div class="doc-container">
+ <DocumentSkeleton />
+ </div>
+ </div>
+
<Error v-else :error="error?.message" />
</div>
</template>
@@ -34,6 +46,7 @@
import TableOfContent from '~/pages/dashboard/docs/_components/table-of-content/TableOfContents.vue';
import DocumentSkeleton from '~/pages/dashboard/docs/_components/DocumentSkeleton.vue';
import DocumentCardHeader from '~/pages/dashboard/docs/_components/DocumentCardHeader.vue';
+import HierarchyTree from '~/pages/(public)/doc/_components/HierarchyTree.vue';
import type { Node } from '~/stores';
const documentsStore = useNodesStore();
@@ -45,6 +58,7 @@ const { isOpened } = useSidebar();
const { isTablet } = useDevice();
const element = ref<HTMLElement>();
+const children = ref<Node[]>([]);
/**
* SSR-aware fetch
@@ -52,9 +66,17 @@ const element = ref<HTMLElement>();
const { data: article, error } = await useAsyncData(`public-doc-${route.params.id}`, async (): Promise<Node | undefined> => {
const documentId = route.params.id;
if (!documentId || typeof documentId !== 'string') return undefined;
- return (await documentsStore.fetchPublic(documentId)) ?? undefined;
+ const result = await documentsStore.fetchPublic(documentId);
+ if (result) {
+ children.value = result.children || [];
+ return result.node;
+ }
+ return undefined;
});
+/** Check if node has displayable content */
+const hasContent = computed(() => article.value?.content_compiled && article.value.content_compiled.trim().length > 0);
+
/**
* SEO (SSR-safe)
*/
diff --git a/frontend/app/pages/(public)/doc/_components/HierarchyNode.vue b/frontend/app/pages/(public)/doc/_components/HierarchyNode.vue
new file mode 100644
index 00000000..bda8f292
--- /dev/null
+++ b/frontend/app/pages/(public)/doc/_components/HierarchyNode.vue
@@ -0,0 +1,261 @@
+<template>
+ <div class="hierarchy-node" :class="{ expanded: isExpanded, 'has-children': hasChildren }">
+ <div class="node-row" :style="{ paddingLeft: `${depth * 1.5 + 1}rem` }" @click="toggleExpand">
+ <!-- Expand/Collapse indicator -->
+ <button v-if="hasChildren" class="expand-btn" :class="{ rotated: isExpanded }">
+ <Icon name="chevron_right" display="sm" />
+ </button>
+ <span v-else class="expand-placeholder" />
+
+ <!-- Node icon -->
+ <span class="node-icon" :class="getAccentClass">
+ <Icon :name="node.icon || getDefaultIcon" display="md" />
+ </span>
+
+ <!-- Node content -->
+ <NuxtLink :to="`/doc/${node.id}`" class="node-link" @click.stop>
+ <span class="node-name">{{ node.name }}</span>
+ <span v-if="node.description" class="node-description">{{ node.description }}</span>
+ </NuxtLink>
+
+ <!-- Node metadata -->
+ <div class="node-meta">
+ <span class="node-type">{{ getRoleLabel }}</span>
+ <span v-if="hasChildren" class="children-count">{{ childrenCount }}</span>
+ </div>
+ </div>
+
+ <!-- Children (collapsible) -->
+ <Transition name="expand">
+ <div v-if="isExpanded && hasChildren" class="node-children">
+ <HierarchyNode v-for="child in children" :key="child.id" :node="child" :all-nodes="allNodes" :depth="depth + 1" />
+ </div>
+ </Transition>
+ </div>
+</template>
+
+<script setup lang="ts">
+import type { Node } from '~/stores';
+
+const props = defineProps<{
+ node: Node;
+ allNodes: Map<string, Node>;
+ depth: number;
+}>();
+
+const { getAppAccent } = useAppColors();
+
+const isExpanded = ref(props.depth < 2); // Auto-expand first 2 levels
+
+const children = computed(() => {
+ const result: Node[] = [];
+ props.allNodes.forEach(n => {
+ if (n.parent_id === props.node.id) {
+ result.push(n);
+ }
+ });
+ return result.sort((a, b) => {
+ if (a.role !== b.role) return a.role - b.role;
+ const orderA = a.order ?? 0;
+ const orderB = b.order ?? 0;
+ if (orderA !== orderB) return orderB - orderA;
+ return a.name.localeCompare(b.name);
+ });
+});
+
+const hasChildren = computed(() => children.value.length > 0);
+const childrenCount = computed(() => children.value.length);
+
+const getDefaultIcon = computed(() => {
+ switch (props.node.role) {
+ case 1:
+ return 'workspace';
+ case 2:
+ return 'files';
+ case 3:
+ return 'file';
+ default:
+ return 'file';
+ }
+});
+
+const getRoleLabel = computed(() => {
+ switch (props.node.role) {
+ case 1:
+ return 'Workspace';
+ case 2:
+ return 'Category';
+ case 3:
+ return 'Document';
+ default:
+ return '';
+ }
+});
+
+const getAccentClass = computed(() => {
+ return getAppAccent(props.node.color as number, true);
+});
+
+function toggleExpand() {
+ if (hasChildren.value) {
+ isExpanded.value = !isExpanded.value;
+ }
+}
+</script>
+
+<style scoped lang="scss">
+.hierarchy-node {
+ &.has-children > .node-row {
+ cursor: pointer;
+
+ &:hover {
+ background: var(--bg-contrast);
+ }
+ }
+}
+
+.node-row {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ padding: 0.625rem 1rem;
+ transition: background-color 0.15s;
+ border-left: 2px solid transparent;
+
+ &:hover {
+ border-left-color: var(--primary);
+ }
+}
+
+.expand-btn {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 20px;
+ height: 20px;
+ padding: 0;
+ border: none;
+ background: none;
+ color: var(--font-color-light);
+ cursor: pointer;
+ transition: transform 0.2s;
+ flex-shrink: 0;
+
+ &.rotated {
+ transform: rotate(90deg);
+ }
+
+ &:hover {
+ color: var(--primary);
+ }
+}
+
+.expand-placeholder {
+ width: 20px;
+ flex-shrink: 0;
+}
+
+.node-icon {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 32px;
+ height: 32px;
+ border-radius: 8px;
+ flex-shrink: 0;
+}
+
+.node-link {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+ min-width: 0;
+ text-decoration: none;
+ gap: 2px;
+
+ &:hover .node-name {
+ color: var(--primary);
+ }
+}
+
+.node-name {
+ font-size: 0.9375rem;
+ font-weight: 500;
+ color: var(--font-color-dark);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ transition: color 0.15s;
+}
+
+.node-description {
+ font-size: 0.8125rem;
+ color: var(--font-color-light);
+ white-space: nowrap;
+ overflow: hidden;
+ text-overflow: ellipsis;
+}
+
+.node-meta {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ flex-shrink: 0;
+}
+
+.node-type {
+ font-size: 0.6875rem;
+ font-weight: 500;
+ text-transform: uppercase;
+ letter-spacing: 0.5px;
+ color: var(--font-color-light);
+ padding: 2px 8px;
+ background: var(--bg-contrast);
+ border-radius: 4px;
+}
+
+.children-count {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ min-width: 20px;
+ height: 20px;
+ font-size: 0.6875rem;
+ font-weight: 600;
+ color: var(--font-color);
+ background: var(--bg-contrast);
+ border-radius: 10px;
+ padding: 0 6px;
+}
+
+.node-children {
+ border-left: 1px dashed var(--border-color);
+ margin-left: 1.75rem;
+}
+
+// Expand transition
+.expand-enter-active,
+.expand-leave-active {
+ transition: all 0.2s ease;
+ overflow: hidden;
+}
+
+.expand-enter-from,
+.expand-leave-to {
+ opacity: 0;
+ max-height: 0;
+}
+
+.expand-enter-to,
+.expand-leave-from {
+ opacity: 1;
+ max-height: 1000px;
+}
+
+@media screen and (max-width: 600px) {
+ .node-description,
+ .node-type {
+ display: none;
+ }
+}
+</style>
diff --git a/frontend/app/pages/(public)/doc/_components/HierarchyTree.vue b/frontend/app/pages/(public)/doc/_components/HierarchyTree.vue
new file mode 100644
index 00000000..c5fc7ec7
--- /dev/null
+++ b/frontend/app/pages/(public)/doc/_components/HierarchyTree.vue
@@ -0,0 +1,108 @@
+<template>
+ <div class="hierarchy-tree">
+ <div class="tree-header">
+ <h2>
+ <Icon name="categories" display="lg" />
+ Contents
+ </h2>
+ <span class="item-count">{{ totalCount }} items</span>
+ </div>
+
+ <div class="tree-content">
+ <HierarchyNode v-for="node in rootNodes" :key="node.id" :node="node" :all-nodes="allNodes" :depth="0" />
+ </div>
+
+ <div v-if="!rootNodes.length" class="empty-state">
+ <Icon name="files" display="xxl" />
+ <p>No content available</p>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import HierarchyNode from './HierarchyNode.vue';
+import type { Node } from '~/stores';
+
+const props = defineProps<{
+ nodes: Node[];
+ parentId: string;
+}>();
+
+// All nodes map for quick lookup
+const allNodes = computed(() => {
+ const map = new Map<string, Node>();
+ props.nodes.forEach(n => map.set(n.id, n));
+ return map;
+});
+
+// Root nodes are direct children of the parent
+const rootNodes = computed(() => {
+ return props.nodes
+ .filter(n => n.parent_id === props.parentId)
+ .sort((a, b) => {
+ if (a.role !== b.role) return a.role - b.role;
+ const orderA = a.order ?? 0;
+ const orderB = b.order ?? 0;
+ if (orderA !== orderB) return orderB - orderA;
+ return a.name.localeCompare(b.name);
+ });
+});
+
+const totalCount = computed(() => props.nodes.length);
+</script>
+
+<style scoped lang="scss">
+.hierarchy-tree {
+ margin-top: 2rem;
+ border: 1px solid var(--border-color);
+ border-radius: 12px;
+ background: var(--bg-color);
+ overflow: hidden;
+}
+
+.tree-header {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 1rem 1.25rem;
+ background: var(--bg-contrast);
+ border-bottom: 1px solid var(--border-color);
+
+ h2 {
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
+ margin: 0;
+ font-size: 1rem;
+ font-weight: 600;
+ color: var(--font-color-dark);
+ border: none;
+ }
+}
+
+.item-count {
+ font-size: 0.75rem;
+ color: var(--font-color-light);
+ background: var(--bg-color);
+ padding: 4px 10px;
+ border-radius: 20px;
+ border: 1px solid var(--border-color);
+}
+
+.tree-content {
+ padding: 0.5rem 0;
+}
+
+.empty-state {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ padding: 3rem;
+ color: var(--font-color-light);
+
+ p {
+ margin: 0.5rem 0 0;
+ }
+}
+</style>
diff --git a/frontend/app/stores/db_strustures.d.ts b/frontend/app/stores/db_strustures.d.ts
index 5b1278bb..1e719e0e 100644
--- a/frontend/app/stores/db_strustures.d.ts
+++ b/frontend/app/stores/db_strustures.d.ts
@@ -79,6 +79,12 @@ export interface NodeSearchResult {
updated_timestamp: number;
}
+// Response from public node endpoint including children
+export interface PublicNodeResponse {
+ node: DB_Node;
+ children: DB_Node[];
+}
+
export interface Session {
id: string;
user_id: string;
diff --git a/frontend/app/stores/nodes.store.ts b/frontend/app/stores/nodes.store.ts
index f0e8b5ad..77d64cbb 100644
--- a/frontend/app/stores/nodes.store.ts
+++ b/frontend/app/stores/nodes.store.ts
@@ -1,6 +1,6 @@
import { makeRequest, type FetchOptions } from './_utils';
import { Collection } from './collection';
-import type { DB_Node, ImportJob, Node, NodeSearchResult, Permission } from './db_strustures';
+import type { DB_Node, ImportJob, Node, NodeSearchResult, Permission, PublicNodeResponse } from './db_strustures';
export interface SearchOptions {
query?: string;
@@ -226,15 +226,25 @@ export const useNodesStore = defineStore('nodes', {
}
} else throw request;
},
- async fetchPublic(id: string): Promise<Node | undefined> {
+ async fetchPublic(id: string): Promise<{ node: Node; children: Node[] } | undefined> {
console.log(`[store/nodes] Fetching public node with id: ${id}`);
const existingDoc = this.public_nodes.get(id);
- if (existingDoc) return existingDoc;
+ if (existingDoc && existingDoc._children !== undefined) {
+ return { node: existingDoc, children: existingDoc._children };
+ }
const request = await makeRequest(`nodes/public/${id}`, 'GET', {});
if (request.status === 'success') {
- const fetchedDoc: Node = { ...(request.result as DB_Node), partial: false, shared: false, permissions: [] };
+ const response = request.result as PublicNodeResponse;
+ const children: Node[] = (response.children || []).map(c => ({ ...c, partial: true, shared: false, permissions: [] }));
+ const fetchedDoc: Node & { _children?: Node[] } = {
+ ...response.node,
+ partial: false,
+ shared: false,
+ permissions: [],
+ _children: children,
+ };
this.public_nodes.set(fetchedDoc.id, fetchedDoc);
- return fetchedDoc;
+ return { node: fetchedDoc, children };
} else return undefined;
},
async fetchShared(): Promise<Collection<string, Node>> {