update
This commit is contained in:
12
src/fs.ts
12
src/fs.ts
@@ -57,12 +57,22 @@ export function listMarkdownFiles(app: App, path: string, exclude: string[] = []
|
|||||||
.sort((a, b) => a.basename.localeCompare(b.basename));
|
.sort((a, b) => a.basename.localeCompare(b.basename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function listAllFiles(app: App, path: string, exclude: string[] = []): TFile[] {
|
||||||
|
const folder = path ? app.vault.getAbstractFileByPath(normalizePath(path)) : app.vault.getRoot();
|
||||||
|
if (!(folder instanceof TFolder)) return [];
|
||||||
|
return folder.children
|
||||||
|
.filter((c): c is TFile => c instanceof TFile)
|
||||||
|
.filter((f) => !exclude.includes(f.name))
|
||||||
|
.filter((f) => !f.basename.startsWith("_") || f.basename.startsWith("__"))
|
||||||
|
.sort((a, b) => a.basename.localeCompare(b.basename));
|
||||||
|
}
|
||||||
|
|
||||||
export function listCollectionFeatures(
|
export function listCollectionFeatures(
|
||||||
app: App,
|
app: App,
|
||||||
project: string,
|
project: string,
|
||||||
collection: string,
|
collection: string,
|
||||||
): TFile[] {
|
): TFile[] {
|
||||||
return listMarkdownFiles(app, collectionPath(project, collection), []);
|
return listAllFiles(app, collectionPath(project, collection), []);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function readFile(app: App, path: string): Promise<string> {
|
export async function readFile(app: App, path: string): Promise<string> {
|
||||||
|
|||||||
@@ -20,12 +20,14 @@ function escapeHtml(s: string): string {
|
|||||||
.replace(/'/g, "'");
|
.replace(/'/g, "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
function nodeTemplate(data: { name: string; features: string[] }): string {
|
interface FeatureEntry { file: string; label: string }
|
||||||
|
|
||||||
|
function nodeTemplate(data: { name: string; features: FeatureEntry[] }): string {
|
||||||
const name = escapeHtml(data.name);
|
const name = escapeHtml(data.name);
|
||||||
const badges = data.features
|
const badges = data.features
|
||||||
.map(
|
.map(
|
||||||
(f) =>
|
(f) =>
|
||||||
`<span class="pk-badge" data-action="open-feature" data-feature="${escapeHtml(f)}">${escapeHtml(f)}</span>`,
|
`<span class="pk-badge" data-action="open-feature" data-feature="${escapeHtml(f.file)}">${escapeHtml(f.label)}</span>`,
|
||||||
)
|
)
|
||||||
.join("");
|
.join("");
|
||||||
return `
|
return `
|
||||||
@@ -171,7 +173,7 @@ export class GraphView {
|
|||||||
valign: "center",
|
valign: "center",
|
||||||
halignBox: "center",
|
halignBox: "center",
|
||||||
valignBox: "center",
|
valignBox: "center",
|
||||||
tpl: (d: { name: string; features: string[] }) => nodeTemplate(d),
|
tpl: (d: { name: string; features: FeatureEntry[] }) => nodeTemplate(d),
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -204,7 +206,7 @@ export class GraphView {
|
|||||||
visited.add(child);
|
visited.add(child);
|
||||||
const id = `n_${child}`;
|
const id = `n_${child}`;
|
||||||
const features = listCollectionFeatures(this.app, this.project, child)
|
const features = listCollectionFeatures(this.app, this.project, child)
|
||||||
.map((f) => f.basename);
|
.map((f) => ({ file: f.name, label: f.basename }));
|
||||||
const { w, h } = this.nodeSize(features.length);
|
const { w, h } = this.nodeSize(features.length);
|
||||||
els.push({
|
els.push({
|
||||||
data: { id, name: child, depth, features, w, h },
|
data: { id, name: child, depth, features, w, h },
|
||||||
@@ -374,7 +376,7 @@ export class GraphView {
|
|||||||
if (featEl?.dataset.feature) {
|
if (featEl?.dataset.feature) {
|
||||||
void openMarkdown(
|
void openMarkdown(
|
||||||
this.app,
|
this.app,
|
||||||
normalizePath(`${collectionPath(this.project, upName)}/${featEl.dataset.feature}.md`),
|
normalizePath(`${collectionPath(this.project, upName)}/${featEl.dataset.feature}`),
|
||||||
this.leaf,
|
this.leaf,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user