🎨 Improve the fallback logic for fetching README in the marketplace (#16551)

* 加载已下载插件列表时,如果插件指定 README 文件不存在,则回退到 README.md https://github.com/siyuan-note/siyuan/issues/14636#issuecomment-3035905944

* 加载已下载插件列表时,如果插件指定 README 文件不存在,则回退到 README.md https://github.com/siyuan-note/siyuan/issues/14636#issuecomment-3035905944

* 提取公共函数

* 获取首选 Readme Name Desc 时优先回退到指定的默认值

* 兼容赞助链接

* 在线获取 README 时最后回退到 README.md
This commit is contained in:
Jeffrey Chen 2025-12-10 11:26:54 +08:00 committed by GitHub
parent d11ed21f06
commit 058ade01c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 108 additions and 78 deletions

View file

@ -167,9 +167,9 @@ func InstalledWidgets() (ret []*Widget) {
widget.PreferredFunding = getPreferredFunding(widget.Funding)
widget.PreferredName = GetPreferredName(widget.Package)
widget.PreferredDesc = getPreferredDesc(widget.Description)
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
info, statErr := os.Stat(filepath.Join(installPath, "widget.json"))
if nil != statErr {
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
logging.LogWarnf("stat install widget.json failed: %s", statErr)
continue
}
widget.HInstallDate = info.ModTime().Format("2006-01-02")
@ -181,14 +181,7 @@ func InstalledWidgets() (ret []*Widget) {
packageInstallSizeCache.SetDefault(widget.RepoURL, is)
}
widget.HInstallSize = humanize.BytesCustomCeil(uint64(widget.InstallSize), 2)
readmeFilename := getPreferredReadme(widget.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
logging.LogWarnf("read installed README.md failed: %s", readErr)
continue
}
widget.PreferredReadme, _ = renderLocalREADME("/widgets/"+dirName+"/", readme)
widget.PreferredReadme = loadInstalledReadme(installPath, "/widgets/"+dirName+"/", widget.Readme)
widget.Outdated = isOutdatedWidget(widget, bazaarWidgets)
ret = append(ret, widget)
}