|↑| Essentials | Essential type filler
// SWITCH: Change this to display only one table
// Options: 'Definition', 'Documentation', 'Explanation', 'Table', 'Pointer', 'Named', 'Incomplete', 'Blank'
const targetHeader = 'TBD';
const labelDict = {
'Definition': 'Definition',
'定義': '定義',
'Documentation': 'Documentation',
'Explanation': 'Explanation',
'Table': 'Table',
'Link': 'Pointer',
'Reference': 'Pointer',
'Repository': 'Pointer',
'Website': 'Pointer',
'SIMBAD': 'Pointer',
'WorldCat': 'Pointer',
'PyPI': 'Named',
'filler': 'filler',
'untitled_placeholder': 'TBD',
};
// Get all files in Concepts/Concepts
const conceptFiles = dv.pages('"Concepts/Concepts"');
// Collect data
let data = [];
let blankFiles = [];
for (let file of conceptFiles) {
// Get incoming links
const incomingLinks = file.file.inlinks || [];
// Filter for links containing "|1st|" and extract labels
const relevantLinks = incomingLinks
.filter(link => link.path.contains("|1st|"))
.map(link => {
const parts = link.path.split("|");
return parts[1];
});
// Total count of all incoming links with "|1st|"
const totalCount = relevantLinks.length;
if (totalCount === 0) {
// No incoming "|1st|" links - add to blank category
blankFiles.push({
file: file.file.link,
fileName: file.file.name,
label: "",
count: 0
});
} else {
// Get unique labels
const uniqueLabels = [...new Set(relevantLinks)];
// Create rows for each unique label found
for (let label of uniqueLabels) {
data.push({
file: file.file.link,
fileName: file.file.name,
label: label,
count: totalCount
});
}
}
}
// Group by label (using dictionary mapping for headers)
const grouped = {};
for (let row of data) {
const header = labelDict[row.label] || "Incomplete";
if (!grouped[header]) {
grouped[header] = [];
}
grouped[header].push(row);
}
// Add blank files as a separate group
if (blankFiles.length > 0) {
grouped["Blank"] = blankFiles;
}
// Display only the selected table
if (grouped[targetHeader]) {
dv.header(3, targetHeader);
// Sort by label first, then by filename
const sortedRows = grouped[targetHeader].sort((a, b) => {
// Primary sort: by label
if (a.label < b.label) return -1;
if (a.label > b.label) return 1;
// Secondary sort: by filename (case-insensitive)
const fileA = a.fileName.toLowerCase();
const fileB = b.fileName.toLowerCase();
return fileA.localeCompare(fileB);
});
dv.table(
["Concept", "Label", "Count"],
sortedRows.map(r => [r.file, r.label, r.count])
);
} else {
dv.paragraph(`No entries found for "${targetHeader}"`);
}