Skip to content

Commit

Permalink
🎨 集市支持已安装的包单独显示 #5678
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 1, 2022
1 parent 3ad5bb7 commit cde994c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions kernel/bazaar/icon.go
Expand Up @@ -24,7 +24,6 @@ import (
"strings"
"sync"

"github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
Expand Down Expand Up @@ -143,7 +142,8 @@ func InstalledIcons() (ret []*Icon) {
logging.LogWarnf("read install icon README.md failed: %s", readErr)
continue
}
icon.README = gulu.Str.FromBytes(readme)

icon.README, _ = renderREADME(icon.URL, readme)
icon.Outdated = isOutdatedIcon(icon.URL, icon.Version, bazaarIcons)
ret = append(ret, icon)
}
Expand Down
9 changes: 7 additions & 2 deletions kernel/bazaar/package.go
Expand Up @@ -244,16 +244,21 @@ func GetPackageREADME(repoURL, repoHash string, systemID string) (ret string) {
}
}

ret, err = renderREADME(repoURL, data)
return
}

func renderREADME(repoURL string, mdData []byte) (ret string, err error) {
luteEngine := lute.New()
luteEngine.SetSoftBreak2HardBreak(false)
luteEngine.SetCodeSyntaxHighlight(false)
linkBase := repoURL + "/blob/main/"
luteEngine.SetLinkBase(linkBase)
ret = luteEngine.Md2HTML(string(data))
ret = luteEngine.Md2HTML(string(mdData))
doc, err := goquery.NewDocumentFromReader(strings.NewReader(ret))
if nil != err {
logging.LogErrorf("parse HTML failed: %s", err)
return ret
return
}

doc.Find("a").Each(func(i int, selection *goquery.Selection) {
Expand Down
3 changes: 1 addition & 2 deletions kernel/bazaar/template.go
Expand Up @@ -25,7 +25,6 @@ import (
"sync"
"time"

"github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
Expand Down Expand Up @@ -143,7 +142,7 @@ func InstalledTemplates() (ret []*Template) {
logging.LogWarnf("read install template README.md failed: %s", readErr)
continue
}
template.README = gulu.Str.FromBytes(readme)
template.README, _ = renderREADME(template.URL, readme)
template.Outdated = isOutdatedTemplate(template.URL, template.Version, bazaarTemplates)
ret = append(ret, template)
}
Expand Down
3 changes: 1 addition & 2 deletions kernel/bazaar/theme.go
Expand Up @@ -24,7 +24,6 @@ import (
"strings"
"sync"

"github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
Expand Down Expand Up @@ -146,7 +145,7 @@ func InstalledThemes() (ret []*Theme) {
logging.LogWarnf("read install theme README.md failed: %s", readErr)
continue
}
theme.README = gulu.Str.FromBytes(readme)
theme.README, _ = renderREADME(theme.URL, readme)
theme.Outdated = isOutdatedTheme(theme.URL, theme.Version, bazaarThemes)
ret = append(ret, theme)
}
Expand Down
3 changes: 1 addition & 2 deletions kernel/bazaar/widget.go
Expand Up @@ -24,7 +24,6 @@ import (
"strings"
"sync"

"github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
Expand Down Expand Up @@ -141,7 +140,7 @@ func InstalledWidgets() (ret []*Widget) {
logging.LogWarnf("read install widget README.md failed: %s", readErr)
continue
}
widget.README = gulu.Str.FromBytes(readme)
widget.README, _ = renderREADME(widget.URL, readme)
widget.Outdated = isOutdatedWidget(widget.URL, widget.Version, bazaarWidgets)
ret = append(ret, widget)
}
Expand Down

0 comments on commit cde994c

Please sign in to comment.