From 5dafac827c05de5065214509a3bd76391b657c7f Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sat, 31 Jul 2021 13:20:51 +0200 Subject: [PATCH] Section option to show full post content on index & fixes --- config.go | 6 +- example-config.yml | 5 +- geo.go | 2 - geoMap.go | 6 +- httpRouters.go | 2 +- micropub.go | 123 ++++++++++++++-------------- postsFuncs.go | 54 ++++++++---- render.go | 9 +- templates/photosummary.gohtml | 8 +- templates/postheadmeta.gohtml | 2 +- templates/postmeta.gohtml | 9 -- templates/summary.gohtml | 12 ++- templates/summaryandpostmeta.gohtml | 16 +++- webmentionSending.go | 1 - 14 files changed, 145 insertions(+), 110 deletions(-) diff --git a/config.go b/config.go index 0f73cfa..821e2b1 100644 --- a/config.go +++ b/config.go @@ -80,6 +80,7 @@ type configSection struct { Title string `mapstructure:"title"` Description string `mapstructure:"description"` PathTemplate string `mapstructure:"pathtemplate"` + ShowFull bool `mapstructure:"showFull"` } type configTaxonomy struct { @@ -99,7 +100,6 @@ type configMenuItem struct { type configPhotos struct { Enabled bool `mapstructure:"enabled"` - Parameter string `mapstructure:"parameter"` Path string `mapstructure:"path"` Title string `mapstructure:"title"` Description string `mapstructure:"description"` @@ -197,7 +197,9 @@ type configHooks struct { type configMicropub struct { CategoryParam string `mapstructure:"categoryParam"` ReplyParam string `mapstructure:"replyParam"` + ReplyTitleParam string `mapstructure:"replyTitleParam"` LikeParam string `mapstructure:"likeParam"` + LikeTitleParam string `mapstructure:"likeTitleParam"` BookmarkParam string `mapstructure:"bookmarkParam"` AudioParam string `mapstructure:"audioParam"` PhotoParam string `mapstructure:"photoParam"` @@ -281,7 +283,9 @@ func (a *goBlog) initConfig() error { viper.SetDefault("hooks.shell", "/bin/bash") viper.SetDefault("micropub.categoryParam", "tags") viper.SetDefault("micropub.replyParam", "replylink") + viper.SetDefault("micropub.replyTitleParam", "replytitle") viper.SetDefault("micropub.likeParam", "likelink") + viper.SetDefault("micropub.likeTitleParam", "liketitle") viper.SetDefault("micropub.bookmarkParam", "link") viper.SetDefault("micropub.audioParam", "audio") viper.SetDefault("micropub.photoParam", "images") diff --git a/example-config.yml b/example-config.yml index 02d6451..92e1afd 100644 --- a/example-config.yml +++ b/example-config.yml @@ -98,11 +98,14 @@ micropub: # You can set parameters via the UI of your MicroPub editor or via front matter in the content categoryParam: tags replyParam: replylink + replyTitleParam: replytitle likeParam: likelink + likeTitleParam: liketitle bookmarkParam: link audioParam: audio photoParam: images photoDescriptionParam: imagealts + locationParam: location # Notifications notifications: @@ -142,6 +145,7 @@ blogs: title: Micro description: "You can also use **Markdown** here." # Section description, can also use Markdown pathtemplate: "{{printf \"/%v/%02d/%02d/%v\" .Section .Year .Month .Slug}}" + showFull: true # Show full post content instead of just the summary on index pages # Taxonomies taxonomies: - name: tags # Code of taxonomy (used via post parameters) @@ -166,7 +170,6 @@ blogs: # Index page which shows all posts with photos photos: enabled: true # Enable - parameter: images # Parameter which includes photo links path: /photos # (Optional) Set a custom path (relative to blog path) title: Photos # Title description: Instead of using Instagram, I prefer uploading pictures to my blog. # Description diff --git a/geo.go b/geo.go index a8de5c9..9664975 100644 --- a/geo.go +++ b/geo.go @@ -12,8 +12,6 @@ import ( "github.com/thoas/go-funk" ) -const geoParam = "location" - func (a *goBlog) geoTitle(g *gogeouri.Geo, lang string) string { if name, ok := g.Parameters["name"]; ok && len(name) > 0 && name[0] != "" { return name[0] diff --git a/geoMap.go b/geoMap.go index c52e0d0..fd584d5 100644 --- a/geoMap.go +++ b/geoMap.go @@ -23,8 +23,8 @@ func (a *goBlog) serveGeoMap(w http.ResponseWriter, r *http.Request) { allPostsWithLocation, err := a.db.getPosts(&postsRequestConfig{ blog: blog, status: statusPublished, - parameter: geoParam, - withOnlyParameters: []string{geoParam}, + parameter: a.cfg.Micropub.LocationParam, + withOnlyParameters: []string{a.cfg.Micropub.LocationParam}, }) if err != nil { a.serveError(w, r, err.Error(), http.StatusInternalServerError) @@ -49,7 +49,7 @@ func (a *goBlog) serveGeoMap(w http.ResponseWriter, r *http.Request) { var locations []*templateLocation for _, p := range allPostsWithLocation { - if g := p.GeoURI(); g != nil { + if g := a.geoURI(p); g != nil { locations = append(locations, &templateLocation{ Lat: g.Latitude, Lon: g.Longitude, diff --git a/httpRouters.go b/httpRouters.go index 9571968..33d8a7e 100644 --- a/httpRouters.go +++ b/httpRouters.go @@ -237,7 +237,7 @@ func (a *goBlog) blogPhotosRouter(conf *configBlog) func(r chi.Router) { a.cacheMiddleware, middleware.WithValue(indexConfigKey, &indexConfig{ path: photoPath, - parameter: pc.Parameter, + parameter: a.cfg.Micropub.PhotoParam, title: pc.Title, description: pc.Description, summaryTemplate: templatePhotosSummary, diff --git a/micropub.go b/micropub.go index edfbd33..f6a7719 100644 --- a/micropub.go +++ b/micropub.go @@ -7,12 +7,12 @@ import ( "mime" "net/http" "net/url" - "reflect" "regexp" "strconv" "strings" "github.com/spf13/cast" + "github.com/thoas/go-funk" "go.goblog.app/app/pkgs/contenttype" "gopkg.in/yaml.v3" ) @@ -547,11 +547,7 @@ func (a *goBlog) micropubUpdateAdd(p *post, add map[string][]interface{}) { case "updated": p.Updated = strings.TrimSpace(strings.Join(cast.ToStringSlice(value), " ")) case "category": - category := p.Parameters[a.cfg.Micropub.CategoryParam] - if category == nil { - category = []string{} - } - p.Parameters[a.cfg.Micropub.CategoryParam] = append(category, cast.ToStringSlice(value)...) + p.Parameters[a.cfg.Micropub.CategoryParam] = append(p.Parameters[a.cfg.Micropub.CategoryParam], cast.ToStringSlice(value)...) case "in-reply-to": p.Parameters[a.cfg.Micropub.ReplyParam] = cast.ToStringSlice(value) case "like-of": @@ -559,67 +555,74 @@ func (a *goBlog) micropubUpdateAdd(p *post, add map[string][]interface{}) { case "bookmark-of": p.Parameters[a.cfg.Micropub.BookmarkParam] = cast.ToStringSlice(value) case "audio": - audio := p.Parameters[a.cfg.Micropub.CategoryParam] - if audio == nil { - audio = []string{} - } - p.Parameters[a.cfg.Micropub.AudioParam] = append(audio, cast.ToStringSlice(value)...) + p.Parameters[a.cfg.Micropub.AudioParam] = append(p.Parameters[a.cfg.Micropub.AudioParam], cast.ToStringSlice(value)...) // TODO: photo } } } func (a *goBlog) micropubUpdateDelete(p *post, del interface{}) { - if del != nil { - if reflect.TypeOf(del).Kind() == reflect.Slice { - toDelete, ok := del.([]interface{}) - if ok { - for _, key := range toDelete { - switch key { - case "content": - p.Content = "" - case "published": - p.Published = "" - case "updated": - p.Updated = "" - case "category": - delete(p.Parameters, a.cfg.Micropub.CategoryParam) - case "in-reply-to": - delete(p.Parameters, a.cfg.Micropub.ReplyParam) - case "like-of": - delete(p.Parameters, a.cfg.Micropub.LikeParam) - case "bookmark-of": - delete(p.Parameters, a.cfg.Micropub.BookmarkParam) - case "audio": - delete(p.Parameters, a.cfg.Micropub.AudioParam) - case "photo": - delete(p.Parameters, a.cfg.Micropub.PhotoParam) - delete(p.Parameters, a.cfg.Micropub.PhotoDescriptionParam) - } - } + if del == nil { + return + } + deleteProperties, ok := del.([]interface{}) + if ok { + // Completely remove properties + for _, prop := range deleteProperties { + switch prop { + case "content": + p.Content = "" + case "published": + p.Published = "" + case "updated": + p.Updated = "" + case "category": + delete(p.Parameters, a.cfg.Micropub.CategoryParam) + case "in-reply-to": + delete(p.Parameters, a.cfg.Micropub.ReplyParam) + delete(p.Parameters, a.cfg.Micropub.ReplyTitleParam) + case "like-of": + delete(p.Parameters, a.cfg.Micropub.LikeParam) + delete(p.Parameters, a.cfg.Micropub.LikeTitleParam) + case "bookmark-of": + delete(p.Parameters, a.cfg.Micropub.BookmarkParam) + case "audio": + delete(p.Parameters, a.cfg.Micropub.AudioParam) + case "photo": + delete(p.Parameters, a.cfg.Micropub.PhotoParam) + delete(p.Parameters, a.cfg.Micropub.PhotoDescriptionParam) } - } else { - toDelete, ok := del.(map[string]interface{}) - if ok { - for key := range toDelete { - if ok { - switch key { - case "content": - p.Content = "" - case "published": - p.Published = "" - case "updated": - p.Updated = "" - case "in-reply-to": - delete(p.Parameters, a.cfg.Micropub.ReplyParam) - case "like-of": - delete(p.Parameters, a.cfg.Micropub.LikeParam) - case "bookmark-of": - delete(p.Parameters, a.cfg.Micropub.BookmarkParam) - // Use content to edit other parameters - } - } - } + } + // Return + return + } + toDelete, ok := del.(map[string]interface{}) + if ok { + // Only delete parts of properties + for key, values := range toDelete { + switch key { + // Properties to completely delete + case "content": + p.Content = "" + case "published": + p.Published = "" + case "updated": + p.Updated = "" + case "in-reply-to": + delete(p.Parameters, a.cfg.Micropub.ReplyParam) + delete(p.Parameters, a.cfg.Micropub.ReplyTitleParam) + case "like-of": + delete(p.Parameters, a.cfg.Micropub.LikeParam) + delete(p.Parameters, a.cfg.Micropub.LikeTitleParam) + case "bookmark-of": + delete(p.Parameters, a.cfg.Micropub.BookmarkParam) + // Properties to delete part of + // TODO: Support partial deletes of more properties + case "category": + delValues := cast.ToStringSlice(values) + p.Parameters[a.cfg.Micropub.CategoryParam] = funk.FilterString(p.Parameters[a.cfg.Micropub.CategoryParam], func(s string) bool { + return !funk.ContainsString(delValues, s) + }) } } } diff --git a/postsFuncs.go b/postsFuncs.go index 88f251b..75c69e1 100644 --- a/postsFuncs.go +++ b/postsFuncs.go @@ -32,10 +32,6 @@ func postParameter(p *post, parameter string) []string { return p.Parameters[parameter] } -func postHasParameter(p *post, parameter string) bool { - return len(p.Parameters[parameter]) > 0 -} - func (p *post) firstParameter(parameter string) (result string) { if pp := p.Parameters[parameter]; len(pp) > 0 { result = pp[0] @@ -43,10 +39,6 @@ func (p *post) firstParameter(parameter string) (result string) { return } -func firstPostParameter(p *post, parameter string) string { - return p.firstParameter(parameter) -} - func (a *goBlog) postHtml(p *post, absolute bool) template.HTML { p.renderMutex.RLock() // Check cache @@ -61,7 +53,7 @@ func (a *goBlog) postHtml(p *post, absolute bool) template.HTML { // Build HTML var htmlBuilder strings.Builder // Add audio to the top - if audio, ok := p.Parameters["audio"]; ok && len(audio) > 0 { + if audio, ok := p.Parameters[a.cfg.Micropub.AudioParam]; ok && len(audio) > 0 { for _, a := range audio { htmlBuilder.WriteString(`