From e8189acb402acbad337148bf2c4e7ba817d861be Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 31 Jul 2022 19:49:58 +0200 Subject: [PATCH] Reply / like context in feeds (#22) --- config.go | 4 ++++ postsFuncs.go | 5 ++++- uiComponents.go | 56 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index 4f719ac..31ca80d 100644 --- a/config.go +++ b/config.go @@ -546,3 +546,7 @@ func (a *goBlog) getBlog(r *http.Request) (string, *configBlog) { } return blog, a.cfg.Blogs[blog] } + +func (a *goBlog) getBlogFromPost(p *post) *configBlog { + return a.cfg.Blogs[defaultIfEmpty(p.Blog, a.cfg.DefaultBlog)] +} diff --git a/postsFuncs.go b/postsFuncs.go index b2269cb..a964046 100644 --- a/postsFuncs.go +++ b/postsFuncs.go @@ -73,10 +73,13 @@ func (a *goBlog) feedHtml(w io.Writer, p *post) { hb.writeElementClose("source") hb.writeElementClose("audio") } + // Add IndieWeb context + a.renderPostReplyContext(hb, p, "p") + a.renderPostLikeContext(hb, p, "p") // Add post HTML a.postHtmlToWriter(hb, p, true) // Add link to interactions and comments - blogConfig := a.cfg.Blogs[defaultIfEmpty(p.Blog, a.cfg.DefaultBlog)] + blogConfig := a.getBlogFromPost(p) if cc := blogConfig.Comments; cc != nil && cc.Enabled { hb.writeElementOpen("p") hb.writeElementOpen("a", "href", a.getFullAddress(p.Path)+"#interactions") diff --git a/uiComponents.go b/uiComponents.go index 3443b94..bf4f480 100644 --- a/uiComponents.go +++ b/uiComponents.go @@ -160,20 +160,8 @@ func (a *goBlog) renderPostMeta(hb *htmlBuilder, p *post, b *configBlog, typ str hb.writeElementClose("div") } // IndieWeb Meta - // Reply ("u-in-reply-to") - if replyLink := a.replyLink(p); replyLink != "" { - hb.writeElementOpen("div") - hb.writeEscaped(a.ts.GetTemplateStringVariant(b.Lang, "replyto")) - hb.writeEscaped(": ") - hb.writeElementOpen("a", "class", "u-in-reply-to", "rel", "noopener", "target", "_blank", "href", replyLink) - if replyTitle := a.replyTitle(p); replyTitle != "" { - hb.writeEscaped(replyTitle) - } else { - hb.writeEscaped(replyLink) - } - hb.writeElementClose("a") - hb.writeElementClose("div") - } + a.renderPostReplyContext(hb, p, "") + a.renderPostLikeContext(hb, p, "") // Like ("u-like-of") if likeLink := a.likeLink(p); likeLink != "" { hb.writeElementOpen("div") @@ -249,6 +237,46 @@ func (a *goBlog) renderPostMeta(hb *htmlBuilder, p *post, b *configBlog, typ str } } +// Reply ("u-in-reply-to") +func (a *goBlog) renderPostReplyContext(hb *htmlBuilder, p *post, htmlWrapperElement string) { + if htmlWrapperElement == "" { + htmlWrapperElement = "div" + } + if replyLink := a.replyLink(p); replyLink != "" { + hb.writeElementOpen(htmlWrapperElement) + hb.writeEscaped(a.ts.GetTemplateStringVariant(a.getBlogFromPost(p).Lang, "replyto")) + hb.writeEscaped(": ") + hb.writeElementOpen("a", "class", "u-in-reply-to", "rel", "noopener", "target", "_blank", "href", replyLink) + if replyTitle := a.replyTitle(p); replyTitle != "" { + hb.writeEscaped(replyTitle) + } else { + hb.writeEscaped(replyLink) + } + hb.writeElementClose("a") + hb.writeElementClose(htmlWrapperElement) + } +} + +// Like ("u-like-of") +func (a *goBlog) renderPostLikeContext(hb *htmlBuilder, p *post, htmlWrapperElement string) { + if htmlWrapperElement == "" { + htmlWrapperElement = "div" + } + if likeLink := a.likeLink(p); likeLink != "" { + hb.writeElementOpen(htmlWrapperElement) + hb.writeEscaped(a.ts.GetTemplateStringVariant(a.getBlogFromPost(p).Lang, "likeof")) + hb.writeEscaped(": ") + hb.writeElementOpen("a", "class", "u-like-of", "rel", "noopener", "target", "_blank", "href", likeLink) + if likeTitle := a.likeTitle(p); likeTitle != "" { + hb.writeEscaped(likeTitle) + } else { + hb.writeEscaped(likeLink) + } + hb.writeElementClose("a") + hb.writeElementClose(htmlWrapperElement) + } +} + // warning for old posts func (a *goBlog) renderOldContentWarning(hb *htmlBuilder, p *post, b *configBlog) { if b == nil || b.hideOldContentWarning || p == nil || !p.Old() {