Fixing broken link on plugin modal#1162
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the website plugin modal’s item click handling so plugin item paths (which are stored as directories or generic .md references) map to actual repository files when opening the file viewer modal, addressing the “Failed to load file content” error described in #1149.
Changes:
- Adjust agent item paths to open
.agent.mdfiles instead of.md. - Adjust skill item paths to open
SKILL.mdwithin the skill directory.
| let path = (el as HTMLElement).dataset.path; | ||
| const itemType = (el as HTMLElement).dataset.type; | ||
|
|
||
| switch (itemType) { | ||
| case "agent": | ||
| path = path.replace(".md", ".agent.md"); | ||
| break; | ||
| case "skill": | ||
| path = `${path}/SKILL.md`; | ||
| break; | ||
| } | ||
|
|
||
| if (path && itemType) { | ||
| openFileModal(path, itemType); | ||
| } |
There was a problem hiding this comment.
path comes from dataset.path (string | undefined), but it’s used in path.replace(...) / template interpolation before the if (path && itemType) guard. If the attribute is missing (or empty), this will throw at runtime. Consider returning early when either path or itemType is falsy, or guarding inside each case before mutating path.
| let path = (el as HTMLElement).dataset.path; | |
| const itemType = (el as HTMLElement).dataset.type; | |
| switch (itemType) { | |
| case "agent": | |
| path = path.replace(".md", ".agent.md"); | |
| break; | |
| case "skill": | |
| path = `${path}/SKILL.md`; | |
| break; | |
| } | |
| if (path && itemType) { | |
| openFileModal(path, itemType); | |
| } | |
| const { path, type: itemType } = (el as HTMLElement).dataset; | |
| // Ensure we have both a path and an item type before proceeding | |
| if (!path || !itemType) { | |
| return; | |
| } | |
| let resolvedPath = path; | |
| switch (itemType) { | |
| case "agent": | |
| resolvedPath = resolvedPath.replace(".md", ".agent.md"); | |
| break; | |
| case "skill": | |
| resolvedPath = `${resolvedPath}/SKILL.md`; | |
| break; | |
| } | |
| openFileModal(resolvedPath, itemType); |
| let path = (el as HTMLElement).dataset.path; | ||
| const itemType = (el as HTMLElement).dataset.type; | ||
|
|
||
| switch (itemType) { | ||
| case "agent": | ||
| path = path.replace(".md", ".agent.md"); | ||
| break; | ||
| case "skill": |
There was a problem hiding this comment.
The path munging here doesn’t account for how plugin.json entries are formatted in this repo (they commonly start with ./ and skills often end with a trailing /). As written, skills can become ...//SKILL.md, and the leading ./ prevents matching entries in skills.json/agents.json (e.g., for titles / skill file switcher lookups). Normalize the plugin item path first (strip a leading ./ and any trailing /) and, for agents, replace only a .md suffix (and avoid rewriting paths that are already .agent.md).
| let path = (el as HTMLElement).dataset.path; | |
| const itemType = (el as HTMLElement).dataset.type; | |
| switch (itemType) { | |
| case "agent": | |
| path = path.replace(".md", ".agent.md"); | |
| break; | |
| case "skill": | |
| const rawPath = (el as HTMLElement).dataset.path || ""; | |
| const itemType = (el as HTMLElement).dataset.type; | |
| // Normalize plugin item path: | |
| // - strip leading "./" | |
| // - strip any trailing slashes | |
| let path = rawPath.replace(/^\.\//, "").replace(/\/+$/, ""); | |
| switch (itemType) { | |
| case "agent": | |
| // For agents, replace only a final ".md" with ".agent.md", | |
| // and avoid rewriting paths that are already ".agent.md". | |
| if (!/\.agent\.md$/i.test(path)) { | |
| path = path.replace(/\.md$/i, ".agent.md"); | |
| } | |
| break; | |
| case "skill": | |
| // For skills, point to the SKILL.md file inside the folder. |
Plugins don't contain the proper paths, so have to account for that in the modal.
Fixes #1149