Small improvements to make the linter happier

This commit is contained in:
Jan-Lukas Else 2023-02-24 22:01:57 +01:00
parent 7052b686fb
commit a6cfa2de86
3 changed files with 51 additions and 35 deletions

View File

@ -36,7 +36,7 @@ func (p *plugin) SetApp(app plugintypes.App) {
p.app = app
}
func (p *plugin) RenderWithDocument(rc plugintypes.RenderContext, doc *goquery.Document) {
func (p *plugin) RenderWithDocument(_ plugintypes.RenderContext, doc *goquery.Document) {
if p.app == nil || p.customCSS == "" {
return
}
@ -47,7 +47,9 @@ func (p *plugin) RenderWithDocument(rc plugintypes.RenderContext, doc *goquery.D
fmt.Println("Failed to open custom css file: ", err.Error())
return
}
defer f.Close()
defer func() {
_ = f.Close()
}()
err = p.app.CompileAsset("plugincustomcss.css", f)
if err != nil {

View File

@ -54,8 +54,8 @@ func (*plugin) Render(_ plugintypes.RenderContext, rendered io.Reader, modified
_ = goquery.Render(modified, doc.Selection)
}
// UI
func (p *plugin) RenderWithDocument(rc plugintypes.RenderContext, doc *goquery.Document) {
// UI2
func (p *plugin) RenderWithDocument(_ plugintypes.RenderContext, doc *goquery.Document) {
buf := bufferpool.Get()
defer bufferpool.Put(buf)
hb := htmlbuilder.NewHtmlBuilder(buf)

View File

@ -219,7 +219,23 @@ func (a *goBlog) serveDeleted(w http.ResponseWriter, r *http.Request) {
}
func (a *goBlog) serveDate(w http.ResponseWriter, r *http.Request) {
var year, month, day int
year, month, day, title, datePath := a.extractDate(r)
if year == 0 && month == 0 && day == 0 {
a.serve404(w, r)
return
}
_, bc := a.getBlog(r)
ic := &indexConfig{
path: bc.getRelativePath(datePath),
title: title,
year: year,
month: month,
day: day,
}
a.serveIndex(w, r.WithContext(context.WithValue(r.Context(), indexConfigKey, ic)))
}
func (a *goBlog) extractDate(r *http.Request) (year, month, day int, title, datePath string) {
if ys := chi.URLParam(r, "year"); ys != "" && ys != "x" {
year = stringToInt(ys)
}
@ -229,38 +245,29 @@ func (a *goBlog) serveDate(w http.ResponseWriter, r *http.Request) {
if ds := chi.URLParam(r, "day"); ds != "" {
day = stringToInt(ds)
}
if year == 0 && month == 0 && day == 0 {
a.serve404(w, r)
return
}
title, dPath := bufferpool.Get(), bufferpool.Get()
titleBuf, pathBuf := bufferpool.Get(), bufferpool.Get()
defer bufferpool.Put(titleBuf, pathBuf)
if year != 0 {
_, _ = fmt.Fprintf(title, "%0004d", year)
_, _ = fmt.Fprintf(dPath, "%0004d", year)
_, _ = fmt.Fprintf(titleBuf, "%0004d", year)
_, _ = fmt.Fprintf(pathBuf, "%0004d", year)
} else {
_, _ = title.WriteString("XXXX")
_, _ = dPath.WriteString("x")
_, _ = titleBuf.WriteString("XXXX")
_, _ = pathBuf.WriteString("x")
}
if month != 0 {
_, _ = fmt.Fprintf(title, "-%02d", month)
_, _ = fmt.Fprintf(dPath, "/%02d", month)
_, _ = fmt.Fprintf(titleBuf, "-%02d", month)
_, _ = fmt.Fprintf(pathBuf, "/%02d", month)
} else if day != 0 {
_, _ = title.WriteString("-XX")
_, _ = dPath.WriteString("/x")
_, _ = titleBuf.WriteString("-XX")
_, _ = pathBuf.WriteString("/x")
}
if day != 0 {
_, _ = fmt.Fprintf(title, "-%02d", day)
_, _ = fmt.Fprintf(dPath, "/%02d", day)
_, _ = fmt.Fprintf(titleBuf, "-%02d", day)
_, _ = fmt.Fprintf(pathBuf, "/%02d", day)
}
_, bc := a.getBlog(r)
a.serveIndex(w, r.WithContext(context.WithValue(r.Context(), indexConfigKey, &indexConfig{
path: bc.getRelativePath(dPath.String()),
year: year,
month: month,
day: day,
title: title.String(),
})))
bufferpool.Put(title, dPath)
title = titleBuf.String()
datePath = pathBuf.String()
return
}
type indexConfig struct {
@ -324,17 +331,24 @@ func (a *goBlog) serveIndex(w http.ResponseWriter, r *http.Request) {
a.serveError(w, r, err.Error(), http.StatusInternalServerError)
return
}
// Meta
title := ic.title
description := ic.description
if ic.tax != nil {
title = fmt.Sprintf("%s: %s", ic.tax.Title, ic.taxValue)
// Title
var title string
if ic.title != "" {
title = ic.title
} else if ic.section != nil {
title = ic.section.Title
description = ic.section.Description
} else if ic.tax != nil {
title = fmt.Sprintf("%s: %s", ic.tax.Title, ic.taxValue)
} else if search != "" {
title = fmt.Sprintf("%s: %s", bc.Search.Title, search)
}
// Description
var description string
if ic.description != "" {
description = ic.description
} else if ic.section != nil {
description = ic.section.Description
}
// Check if feed
if ft := feedType(chi.URLParam(r, "feed")); ft != noFeed {
a.generateFeed(blog, ft, w, r, posts, title, description)