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));
|
||||
}
|
||||
|
||||
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(
|
||||
app: App,
|
||||
project: string,
|
||||
collection: string,
|
||||
): TFile[] {
|
||||
return listMarkdownFiles(app, collectionPath(project, collection), []);
|
||||
return listAllFiles(app, collectionPath(project, collection), []);
|
||||
}
|
||||
|
||||
export async function readFile(app: App, path: string): Promise<string> {
|
||||
|
||||
@@ -20,12 +20,14 @@ function escapeHtml(s: string): string {
|
||||
.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 badges = data.features
|
||||
.map(
|
||||
(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("");
|
||||
return `
|
||||
@@ -171,7 +173,7 @@ export class GraphView {
|
||||
valign: "center",
|
||||
halignBox: "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);
|
||||
const id = `n_${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);
|
||||
els.push({
|
||||
data: { id, name: child, depth, features, w, h },
|
||||
@@ -374,7 +376,7 @@ export class GraphView {
|
||||
if (featEl?.dataset.feature) {
|
||||
void openMarkdown(
|
||||
this.app,
|
||||
normalizePath(`${collectionPath(this.project, upName)}/${featEl.dataset.feature}.md`),
|
||||
normalizePath(`${collectionPath(this.project, upName)}/${featEl.dataset.feature}`),
|
||||
this.leaf,
|
||||
);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user