🎨 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

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