feat(spaces): docs-kind spaces render as pure documentation repos
Adds a `kind` column to spaces ('project' default, 'docs' for Wiki).
Docs spaces skip projects/tasks fetches and render only the page tree.
Sidebar caret for docs spaces expands to top-level pages (#/page/:id).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,13 @@ async function loadProjects(space_id) {
|
||||
} catch { return []; }
|
||||
}
|
||||
|
||||
async function loadTopPages(space_id) {
|
||||
try {
|
||||
const pages = await api.get(`/api/spaces/${space_id}/pages`);
|
||||
return pages.filter(p => p.parent_id == null);
|
||||
} catch { return []; }
|
||||
}
|
||||
|
||||
async function renderSpaceTree(container) {
|
||||
let spaces;
|
||||
try { spaces = await api.get('/api/spaces'); }
|
||||
@@ -52,11 +59,20 @@ async function renderSpaceTree(container) {
|
||||
if (expanded.has(s.id)) { expanded.delete(s.id); clear(childWrap); }
|
||||
else {
|
||||
expanded.add(s.id);
|
||||
const projects = await loadProjects(s.id);
|
||||
clear(childWrap);
|
||||
if (!projects.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no projects)'));
|
||||
for (const p of projects) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/project/' + p.id }, p.name));
|
||||
if (s.kind === 'docs') {
|
||||
const pages = await loadTopPages(s.id);
|
||||
clear(childWrap);
|
||||
if (!pages.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no pages)'));
|
||||
for (const p of pages) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/page/' + p.id }, p.title || '(untitled)'));
|
||||
}
|
||||
} else {
|
||||
const projects = await loadProjects(s.id);
|
||||
clear(childWrap);
|
||||
if (!projects.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no projects)'));
|
||||
for (const p of projects) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/project/' + p.id }, p.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,13 +83,23 @@ async function renderSpaceTree(container) {
|
||||
);
|
||||
container.appendChild(header);
|
||||
if (isOpen) {
|
||||
loadProjects(s.id).then(projects => {
|
||||
clear(childWrap);
|
||||
if (!projects.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no projects)'));
|
||||
for (const p of projects) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/project/' + p.id }, p.name));
|
||||
}
|
||||
});
|
||||
if (s.kind === 'docs') {
|
||||
loadTopPages(s.id).then(pages => {
|
||||
clear(childWrap);
|
||||
if (!pages.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no pages)'));
|
||||
for (const p of pages) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/page/' + p.id }, p.title || '(untitled)'));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
loadProjects(s.id).then(projects => {
|
||||
clear(childWrap);
|
||||
if (!projects.length) childWrap.appendChild(el('div', { class: 'sb-item muted' }, '(no projects)'));
|
||||
for (const p of projects) {
|
||||
childWrap.appendChild(el('a', { class: 'sb-item', href: '#/project/' + p.id }, p.name));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
container.appendChild(childWrap);
|
||||
}
|
||||
|
||||
@@ -56,6 +56,39 @@ export async function render(main, ctx) {
|
||||
try { space = await api.get('/api/spaces/' + id); }
|
||||
catch (e) { mount(main, el('h1', { class: 'view-h1' }, 'Space not found'), el('p', { class: 'view-sub muted' }, e.message)); return; }
|
||||
|
||||
const docHead = el('div', { class: 'doc-head' },
|
||||
el('h1', { class: 'view-h1', style: { margin: '0' } }, space.name),
|
||||
exportMenu({
|
||||
filenameBase: 'space-' + (space.slug || space.name),
|
||||
getContent: async () => {
|
||||
const allPages = await api.get(`/api/spaces/${id}/pages`).catch(() => []);
|
||||
const full = await Promise.all(allPages.map(p => api.get('/api/pages/' + p.id).catch(() => null)));
|
||||
const md = full.filter(Boolean).map(p => `# ${p.title}\n\n${p.body_md || ''}`).join('\n\n---\n\n');
|
||||
return { title: space.name, md };
|
||||
}
|
||||
})
|
||||
);
|
||||
const descEl = el('p', { class: 'view-sub' }, space.description || el('span', { class: 'muted' }, 'No description.'));
|
||||
|
||||
if (space.kind === 'docs') {
|
||||
// Docs-mode: pure documentation repo — no projects or tasks
|
||||
const [pages, refs] = await Promise.all([
|
||||
api.get(`/api/spaces/${id}/pages`).catch(() => []),
|
||||
api.get(`/api/refs?space_id=${id}&limit=200`).catch(() => [])
|
||||
]);
|
||||
mount(main,
|
||||
docHead,
|
||||
descEl,
|
||||
el('div', { class: 'card' },
|
||||
el('h3', {}, space.name),
|
||||
(pages.length + refs.length) > 0
|
||||
? el('div', {}, renderPageTree(pages, refs))
|
||||
: el('p', { class: 'muted' }, 'Nothing here yet.'))
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Project-mode: full workspace with projects, tasks, and pages
|
||||
let projects = [];
|
||||
const [tasks, pages, refs] = await Promise.all([
|
||||
api.get(`/api/spaces/${id}/tasks?status=todo`).catch(() => []),
|
||||
|
||||
Reference in New Issue
Block a user