🎨 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

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