MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / getProjectDisplayName

Function getProjectDisplayName

src/utils/linkUtils.ts:93–135  ·  view source on GitHub ↗
(projectValue: string, app?: App)

Source from the content-addressed store, hash-verified

91 * @param app - Optional Obsidian app for resolving to basename
92 */
93export function getProjectDisplayName(projectValue: string, app?: App): string {
94 if (!projectValue) return "";
95
96 const trimmed = projectValue.trim();
97
98 // Handle markdown links: [text](path)
99 const markdownMatch = trimmed.match(/^\[([^\]]+)\]\(([^)]+)\)$/);
100 if (markdownMatch) {
101 const displayText = markdownMatch[1].trim();
102 const rawPath = markdownMatch[2].trim();
103 const linkPath = parseLinkToPath(rawPath);
104 const resolvedDisplayName = getResolvedProjectDisplayName(linkPath, app, displayText);
105 if (resolvedDisplayName) {
106 return resolvedDisplayName;
107 }
108 if (displayText) {
109 return displayText;
110 }
111 const cleanPath = linkPath.replace(/\.md$/i, "");
112 const parts = cleanPath.split("/");
113 return parts[parts.length - 1] || cleanPath;
114 }
115
116 // Handle wikilinks: [[path]] or [[path|alias]]
117 if (trimmed.startsWith("[[") && trimmed.endsWith("]]")) {
118 const linkContent = trimmed.slice(2, -2).trim();
119 const pipeIndex = linkContent.indexOf("|");
120 if (pipeIndex !== -1) {
121 const alias = linkContent.slice(pipeIndex + 1).trim();
122 if (alias) return alias;
123 }
124 const linkPath =
125 parseLinkPath(linkContent.split("|")[0] || linkContent) || parseLinkToPath(trimmed);
126 const resolvedDisplayName = getResolvedProjectDisplayName(linkPath, app);
127 if (resolvedDisplayName) return resolvedDisplayName;
128 const cleanPath = linkPath.replace(/\.md$/i, "");
129 const parts = cleanPath.split("/");
130 return parts[parts.length - 1] || cleanPath;
131 }
132
133 // Plain text
134 return trimmed;
135}
136
137function getResolvedProjectDisplayName(
138 linkPath: string,

Calls 3

parseLinkToPathFunction · 0.85
parseLinkPathFunction · 0.85

Tested by

no test coverage detected