@handsupmin/gc-tree 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/markdown.js +36 -16
- package/dist/src/paths.js +0 -1
- package/dist/src/store.js +1 -4
- package/package.json +1 -1
package/dist/src/markdown.js
CHANGED
|
@@ -70,7 +70,8 @@ export function renderIndexMarkdown(input) {
|
|
|
70
70
|
for (const category of categories) {
|
|
71
71
|
lines.push(`## ${displayCategory(category)}`, '');
|
|
72
72
|
for (const doc of grouped.get(category).sort((a, b) => (a.label || a.title).localeCompare(b.label || b.title))) {
|
|
73
|
-
lines.push(`- ${doc.label || doc.title}
|
|
73
|
+
lines.push(`- ${doc.label || doc.title}`);
|
|
74
|
+
lines.push(` - ${doc.path}`);
|
|
74
75
|
}
|
|
75
76
|
lines.push('');
|
|
76
77
|
}
|
|
@@ -107,25 +108,44 @@ export function displayCategory(category) {
|
|
|
107
108
|
}
|
|
108
109
|
export function parseIndexEntries(indexContent) {
|
|
109
110
|
let currentCategory = 'general';
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
let pendingLabel = null;
|
|
112
|
+
const entries = [];
|
|
113
|
+
for (const rawLine of String(indexContent || '').split(/\r?\n/)) {
|
|
114
|
+
const line = rawLine.trimEnd();
|
|
115
|
+
const trimmed = line.trim();
|
|
116
|
+
if (!trimmed) {
|
|
117
|
+
pendingLabel = null;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const heading = trimmed.match(/^##\s+(.+)$/);
|
|
117
121
|
if (heading) {
|
|
118
122
|
currentCategory = normalizeCategory(heading[1] || 'general');
|
|
119
|
-
|
|
123
|
+
pendingLabel = null;
|
|
124
|
+
continue;
|
|
120
125
|
}
|
|
121
|
-
if (
|
|
122
|
-
|
|
126
|
+
if (trimmed.startsWith('- gc-branch:') || trimmed.startsWith('- summary:') || trimmed === '- No source docs yet.') {
|
|
127
|
+
pendingLabel = null;
|
|
128
|
+
continue;
|
|
123
129
|
}
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
const pathMatch = rawLine.match(/^\s{2,}-\s+(docs\/.+)$/);
|
|
131
|
+
if (pathMatch && pendingLabel) {
|
|
132
|
+
const path = pathMatch[1].trim();
|
|
133
|
+
const category = deriveCategoryFromPath(path) || currentCategory;
|
|
134
|
+
entries.push({
|
|
135
|
+
id: docIdFromPath(path),
|
|
136
|
+
title: pendingLabel,
|
|
137
|
+
label: pendingLabel,
|
|
138
|
+
category,
|
|
139
|
+
path,
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const labelMatch = trimmed.match(/^-\s+(.+)$/);
|
|
144
|
+
if (labelMatch) {
|
|
145
|
+
pendingLabel = labelMatch[1].trim();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return entries;
|
|
129
149
|
}
|
|
130
150
|
export function extractIndexEntries(markdown) {
|
|
131
151
|
const match = String(markdown || '').match(/## Index Entries\s+([\s\S]*?)(?:\n## |$)/);
|
package/dist/src/paths.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { homedir } from 'node:os';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
export const DEFAULT_BRANCH = 'main';
|
|
4
|
-
export const INDEX_WARNING_CHARS = 2000;
|
|
5
4
|
export function resolveHome(explicitHome) {
|
|
6
5
|
return explicitHome || process.env.GCTREE_HOME || join(homedir(), '.gctree');
|
|
7
6
|
}
|
package/dist/src/store.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { cp, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { branchDir, branchDocsDir, branchIndexPath, branchMetaPath, branchesRoot, DEFAULT_BRANCH, headPath,
|
|
4
|
+
import { branchDir, branchDocsDir, branchIndexPath, branchMetaPath, branchesRoot, DEFAULT_BRANCH, headPath, } from './paths.js';
|
|
5
5
|
import { extractIndexEntries, renderIndexMarkdown } from './markdown.js';
|
|
6
6
|
async function listDocRelativePaths(dir, prefix = '') {
|
|
7
7
|
const entries = await readdir(dir, { withFileTypes: true }).catch(() => []);
|
|
@@ -150,9 +150,6 @@ export async function statusForBranch(home, branch) {
|
|
|
150
150
|
const indexRaw = await readFile(branchIndexPath(home, branch), 'utf8');
|
|
151
151
|
const docs = await listDocRelativePaths(branchDocsDir(home, branch));
|
|
152
152
|
const warnings = [];
|
|
153
|
-
if (indexRaw.length > INDEX_WARNING_CHARS) {
|
|
154
|
-
warnings.push(`index.md is ${indexRaw.length} chars; keep it closer to an index than a knowledge dump.`);
|
|
155
|
-
}
|
|
156
153
|
for (const doc of docs) {
|
|
157
154
|
const raw = await readFile(join(branchDocsDir(home, branch), doc), 'utf8');
|
|
158
155
|
if (!/^## Summary$/m.test(raw)) {
|