🎨 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

@ -207,9 +207,9 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) {
plugin.PreferredFunding = getPreferredFunding(plugin.Funding)
plugin.PreferredName = GetPreferredName(plugin.Package)
plugin.PreferredDesc = getPreferredDesc(plugin.Description)
info, statErr := os.Stat(filepath.Join(installPath, "README.md"))
info, statErr := os.Stat(filepath.Join(installPath, "plugin.json"))
if nil != statErr {
logging.LogWarnf("stat install theme README.md failed: %s", statErr)
logging.LogWarnf("stat install plugin.json failed: %s", statErr)
continue
}
plugin.HInstallDate = info.ModTime().Format("2006-01-02")
@ -221,14 +221,7 @@ func InstalledPlugins(frontend string, checkUpdate bool) (ret []*Plugin) {
packageInstallSizeCache.SetDefault(plugin.RepoURL, is)
}
plugin.HInstallSize = humanize.BytesCustomCeil(uint64(plugin.InstallSize), 2)
readmeFilename := getPreferredReadme(plugin.Readme)
readme, readErr := os.ReadFile(filepath.Join(installPath, readmeFilename))
if nil != readErr {
logging.LogWarnf("read installed README.md failed: %s", readErr)
continue
}
plugin.PreferredReadme, _ = renderLocalREADME("/plugins/"+dirName+"/", readme)
plugin.PreferredReadme = loadInstalledReadme(installPath, "/plugins/"+dirName+"/", plugin.Readme)
plugin.Outdated = isOutdatedPlugin(plugin, bazaarPlugins)
plugin.Incompatible = isIncompatiblePlugin(plugin, frontend)
ret = append(ret, plugin)