diff --git a/collections.go b/collections.go index 6ded4c3..fc225a2 100644 --- a/collections.go +++ b/collections.go @@ -1,5 +1,5 @@ /* - * Copyright © 2018-2021 Musing Studio LLC. + * Copyright © 2018-2022 Musing Studio LLC. * * This file is part of WriteFreely. * @@ -24,12 +24,13 @@ import ( "unicode" "github.com/gorilla/mux" + stripmd "github.com/writeas/go-strip-markdown/v2" "github.com/writeas/impart" "github.com/writeas/web-core/activitystreams" "github.com/writeas/web-core/auth" "github.com/writeas/web-core/bots" "github.com/writeas/web-core/log" - waposts "github.com/writeas/web-core/posts" + "github.com/writeas/web-core/posts" "github.com/writefreely/writefreely/author" "github.com/writefreely/writefreely/config" "github.com/writefreely/writefreely/page" @@ -362,6 +363,26 @@ func (c *Collection) MonetizationURL() string { return strings.Replace(c.Monetization, "$", "https://", 1) } +// DisplayDescription returns the description with rendered Markdown and HTML. +func (c *Collection) DisplayDescription() *template.HTML { + if c.Description == "" { + s := template.HTML("") + return &s + } + t := template.HTML(posts.ApplyBasicAccessibleMarkdown([]byte(c.Description))) + return &t +} + +// PlainDescription returns the description with all Markdown and HTML removed. +func (c *Collection) PlainDescription() string { + if c.Description == "" { + return "" + } + desc := stripHTMLWithoutEscaping(c.Description) + desc = stripmd.Strip(desc) + return desc +} + func (c CollectionPage) DisplayMonetization() string { return displayMonetization(c.Monetization, c.Alias) } @@ -551,11 +572,11 @@ func fetchCollectionPosts(app *App, w http.ResponseWriter, r *http.Request) erro } } - posts, err := app.db.GetPosts(app.cfg, c, page, isCollOwner, false, false) + ps, err := app.db.GetPosts(app.cfg, c, page, isCollOwner, false, false) if err != nil { return err } - coll := &CollectionObj{Collection: *c, Posts: posts} + coll := &CollectionObj{Collection: *c, Posts: ps} app.db.GetPostsCount(coll, isCollOwner) // Strip non-public information coll.Collection.ForPublic() @@ -563,7 +584,7 @@ func fetchCollectionPosts(app *App, w http.ResponseWriter, r *http.Request) erro // Transform post bodies if needed if r.FormValue("body") == "html" { for _, p := range *coll.Posts { - p.Content = waposts.ApplyMarkdown([]byte(p.Content)) + p.Content = posts.ApplyMarkdown([]byte(p.Content)) } } diff --git a/go.mod b/go.mod index 54d38bb..ca65475 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( github.com/writeas/monday v0.0.0-20181024183321-54a7dd579219 github.com/writeas/saturday v1.7.2-0.20200427193424-392b95a03320 github.com/writeas/slug v1.2.0 - github.com/writeas/web-core v1.4.1 + github.com/writeas/web-core v1.4.1-0.20220118212728-0da0bcaf018e github.com/writefreely/go-gopher v0.0.0-20220429181814-40127126f83b github.com/writefreely/go-nodeinfo v1.2.0 golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 diff --git a/go.sum b/go.sum index d9e8885..5736b3e 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ github.com/ikeikeikeike/go-sitemap-generator/v2 v2.0.2 h1:wIdDEle9HEy7vBPjC6oKz6 github.com/ikeikeikeike/go-sitemap-generator/v2 v2.0.2/go.mod h1:WtaVKD9TeruTED9ydiaOJU08qGoEPP/LyzTKiD3jEsw= github.com/jtolds/gls v4.2.1+incompatible h1:fSuqC+Gmlu6l/ZYAoZzx2pyucC8Xza35fpRVWLVmUEE= github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a h1:FaWFmfWdAUKbSCtOU2QjDaorUexogfaMgbipgYATUMU= +github.com/juju/ansiterm v0.0.0-20180109212912-720a0952cc2a/go.mod h1:UJSiEoRfvx3hP73CvoARgeLjaIOjybY9vj8PUPPFGeU= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -150,8 +152,8 @@ github.com/writeas/saturday v1.7.2-0.20200427193424-392b95a03320 h1:PozPZ29CQ/xt github.com/writeas/saturday v1.7.2-0.20200427193424-392b95a03320/go.mod h1:ETE1EK6ogxptJpAgUbcJD0prAtX48bSloie80+tvnzQ= github.com/writeas/slug v1.2.0 h1:EMQ+cwLiOcA6EtFwUgyw3Ge18x9uflUnOnR6bp/J+/g= github.com/writeas/slug v1.2.0/go.mod h1:RE8shOqQP3YhsfsQe0L3RnuejfQ4Mk+JjY5YJQFubfQ= -github.com/writeas/web-core v1.4.1 h1:mdDwZepEyQb76j8gNUIPblV7SUIXi4WQ0h3Xl0ZwKT4= -github.com/writeas/web-core v1.4.1/go.mod h1:MTWDZWikeG063S9IrI6ekvu3N2tJEVRpZuU4kAWg1DY= +github.com/writeas/web-core v1.4.1-0.20220118212728-0da0bcaf018e h1:/SiS+iQb5YbE/QtKlfJKHSO2c8KwamtTkg0Ojg1uFEI= +github.com/writeas/web-core v1.4.1-0.20220118212728-0da0bcaf018e/go.mod h1:MTWDZWikeG063S9IrI6ekvu3N2tJEVRpZuU4kAWg1DY= github.com/writefreely/go-gopher v0.0.0-20220429181814-40127126f83b h1:h3NzB8OZ50NNi5k9yrFeyFszt3LyqyVK4+xUHFYY8B0= github.com/writefreely/go-gopher v0.0.0-20220429181814-40127126f83b/go.mod h1:T2UVVzt+R5KSSZe2xRSytnwc2M9AoDegi7foeIsik+M= github.com/writefreely/go-nodeinfo v1.2.0 h1:La+YbTCvmpTwFhBSlebWDDL81N88Qf/SCAvRLR7F8ss= diff --git a/templates/collection.tmpl b/templates/collection.tmpl index db0591d..6e3d2dc 100644 --- a/templates/collection.tmpl +++ b/templates/collection.tmpl @@ -15,18 +15,18 @@ - + - + - + - + {{template "collection-meta" .}} {{if .StyleSheet}}{{end}} @@ -83,7 +83,7 @@ {{template "user-silenced"}} {{end}}

{{if .Posts}}{{else}}write.as {{end}}{{.DisplayTitle}}

- {{if .Description}}

{{.Description}}

{{end}} + {{if .Description}}

{{.DisplayDescription}}

{{end}} {{/*if not .Public/*}} {{/*end*/}} diff --git a/templates/user/collection.tmpl b/templates/user/collection.tmpl index 9f16faa..40e9624 100644 --- a/templates/user/collection.tmpl +++ b/templates/user/collection.tmpl @@ -37,7 +37,7 @@ textarea.section.norm {

-

+