Skip to content

fix(dashboard): resolve relative URLs in rendered plugin README content - #10536

Open
xxynet wants to merge 4 commits into
AstrBotDevs:masterfrom
xxynet:fix/plugin-readme-relative-urls
Open

xxynet wants to merge 4 commits into
AstrBotDevs:masterfrom
xxynet:fix/plugin-readme-relative-urls

Conversation

@xxynet

@xxynet xxynet commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9950.

Replaces #9948 with the same relative-URL fix, updated against upstream master at 48ba71ad7. The original PR was closed due to conflicts and inactivity; its conflict is now resolved, but GitHub rejected reopening it through both the CLI and REST API.

Plugin README and changelog content loaded from the local plugin directory previously resolved relative image and document URLs against the dashboard origin, causing broken images and 404 links. Resolve these references against the plugin repository or the URL from which the document was fetched before rendering.

Modifications / 改动点

  • Add resolveRelativeUrls in dashboard/src/utils/markdownUrls.mjs. For local GitHub plugin documents, images resolve against raw.githubusercontent.com/<owner>/<repo>/HEAD/ and links against github.com/<owner>/<repo>/blob/HEAD/.
  • Apply the resolver after HTML sanitization in ReadmeDialog.vue and PluginDetailPage.vue. Remotely fetched market documents use their source URL; leading-slash references resolve against that URL's origin.
  • Retain the heading IDs and local-anchor click handling added on master when resolving the merge conflict.
  • Keep absolute URLs, protocol-relative URLs, fragments, and relative references without a supported source unchanged. Add 20 resolver tests, including GitHub clone locators with .git, www.github.com, and SCP-style git@github.com:owner/repo forms. The diff against master contains only the original four files.

Affected paths: locally installed plugin README/changelog dialogs, installed plugin details, and remote market README/changelog content. Regression checks cover repository-relative and host-root-relative paths, unchanged external URLs and fragments, and unsupported repository sources. No new dependencies, API changes, or user-facing text are introduced.

Documentation: checked the relevant plugin and WebUI instructions in docs/zh and docs/en. No documentation or screenshot updates are needed because navigation, page structure, labels, and workflows are unchanged. This is a bug fix; the new-feature discussion item below is not applicable.

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

Verification was performed on the merged branch on the host machine:

node --test tests/*.test.mjs
  tests 83; pass 83; fail 0; skipped 0
pnpm typecheck
  passed (vue-tsc --noEmit)
pnpm i18n:check
  passed; zh-CN, en-US, ru-RU, ja-JP each expose 4130 leaf keys
pnpm build
  passed on merged commit 7ee71623b before the locator-only review follow-up; 5669 modules transformed
ruff format .
  516 files left unchanged
ruff check .
  All checks passed!
git diff upstream/master...HEAD --check
  passed

Resolver tests cover GitHub images and links, leading-slash paths, remote document directory and origin resolution, unchanged fragments/absolute/protocol-relative URLs, unsupported repositories, and missing sources. A manual browser smoke test was not performed.


Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。

  • 📚 I checked the affected WebUI instructions and screenshots in docs/zh and docs/en against the changed navigation, page structure, and labels, and updated them in this PR (or explained why no documentation update is needed). For renamed, moved, or merged entry points, I included an old entry → new entry mapping in the documentation and changelog.
    / 我已对照变化后的 WebUI 入口、页面结构和术语,核对并在本 PR 中更新 docs/zh 和 docs/en 的相关操作说明与截图(或说明无需更新文档的原因)。入口改名、移动或合并时,已在文档和 changelog 中补充 旧入口 → 新入口 对照。

  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txt 和 pyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Fix relative URLs in rendered plugin documentation so images and links point to the correct repository or fetched document source.

Bug Fixes:

  • Resolve relative image and document URLs in locally installed and remotely fetched plugin README and changelog content against their actual source locations instead of the dashboard origin.

Enhancements:

  • Preserve absolute URLs, protocol-relative URLs, fragments, and unsupported-source references while retaining existing heading anchors and link handling.

Tests:

  • Add resolver coverage for GitHub repository paths, remote document URLs, host-root-relative references, unchanged URLs, and unsupported sources.

Plugin README files read from the local plugin directory contain
relative references (e.g. docs/demo.png) that previously resolved
against the dashboard origin and broke. Rewrite image src and link
href against the plugin's GitHub repository — images to
raw.githubusercontent.com and links to blob pages under HEAD — mirroring
GitHub's own rendering. When the document is fetched from a remote URL,
that URL is used as the base instead.
…docs

When docUrl points at a document in a nested directory, leading-slash
references (e.g. /images/logo.png) previously resolved against the
document's directory instead of the origin root. Resolve them against
the origin host root while keeping directory-relative references tied
to the document location. GitHub-repo leading-slash handling is
unchanged.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="dashboard/src/utils/markdownUrls.mjs" line_range="1" />
<code_context>
+const GITHUB_REPO_PATTERN = /^https?:\/\/github\.com\/([^/\s]+)\/([^/\s#?]+?)\/?$/i;
+const ABSOLUTE_URL_PATTERN = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
+
</code_context>
<issue_to_address>
**README links point to nonexistent paths**

When a plugin’s GitHub repository URL ends in `.git`, `GITHUB_REPO_PATTERN` captures `.git` as part of the repository name, so `resolveRelativeUrls` builds raw and blob paths under `repo.git/HEAD` and README images and links fail.

Strip an optional `.git` suffix from the captured repository name before building the raw and blob bases.
</issue_to_address>

### Comment 2
<location path="dashboard/src/utils/markdownUrls.mjs" line_range="1" />
<code_context>
+const GITHUB_REPO_PATTERN = /^https?:\/\/github\.com\/([^/\s]+)\/([^/\s#?]+?)\/?$/i;
+const ABSOLUTE_URL_PATTERN = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
+
</code_context>
<issue_to_address>
**Repository links stay dashboard-relative**

When a plugin’s repository URL uses `www.github.com` or an SCP-style GitHub locator, `GITHUB_REPO_PATTERN` does not match these forms, so `resolveRelativeUrls` leaves `rawBase` and `blobBase` empty and README images and links resolve against the dashboard origin.

Extend the repository URL parsing to recognize `www.github.com` and SCP-style GitHub locators.
</issue_to_address>

Sourcery assessment

Approval pending. 2 findings to address first.

Blocking findings: dashboard/src/utils/markdownUrls.mjs:1, dashboard/src/utils/markdownUrls.mjs:1


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread dashboard/src/utils/markdownUrls.mjs Outdated
Comment thread dashboard/src/utils/markdownUrls.mjs Outdated

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] 插件 README 中的相对路径无法正确跳转

1 participant