mirror of https://github.com/jlelse/GoBlog
Fix draft posts without section not showing in drafts index
This commit is contained in:
parent
c8229ab28d
commit
b6a88e6bed
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/yuin/goldmark/renderer"
|
||||
"github.com/yuin/goldmark/renderer/html"
|
||||
"github.com/yuin/goldmark/util"
|
||||
"go.goblog.app/app/pkgs/builderpool"
|
||||
"go.goblog.app/app/pkgs/bufferpool"
|
||||
|
||||
"github.com/alecthomas/chroma/v2"
|
||||
chromahtml "github.com/alecthomas/chroma/v2/formatters/html"
|
||||
|
@ -60,8 +60,8 @@ func (r *htmlRenderer) renderFencedCodeBlock(w util.BufWriter, source []byte, no
|
|||
n := node.(*ast.FencedCodeBlock)
|
||||
|
||||
// Read code block content.
|
||||
buf := builderpool.Get()
|
||||
defer builderpool.Put(buf)
|
||||
buf := bufferpool.Get()
|
||||
defer bufferpool.Put(buf)
|
||||
for _, line := range n.Lines().Sliced(0, n.Lines().Len()) {
|
||||
buf.Write(line.Value(source))
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (r *htmlRenderer) renderFencedCodeBlock(w util.BufWriter, source []byte, no
|
|||
if highlight(w, buf.String(), string(n.Language(source)), r.formatter) != nil {
|
||||
// Highlight failed, fallback to plain text.
|
||||
_, _ = w.WriteString("<pre><code>")
|
||||
r.Writer.RawWrite(w, []byte(buf.String()))
|
||||
r.Writer.RawWrite(w, buf.Bytes())
|
||||
_, _ = w.WriteString("</code></pre>\n")
|
||||
}
|
||||
|
||||
|
|
13
posts.go
13
posts.go
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/samber/lo"
|
||||
"github.com/vcraescu/go-paginator"
|
||||
"go.goblog.app/app/pkgs/bufferpool"
|
||||
)
|
||||
|
@ -151,13 +152,14 @@ func (p *postPaginationAdapter) Slice(offset, length int, data any) error {
|
|||
}
|
||||
|
||||
func (a *goBlog) serveHome(w http.ResponseWriter, r *http.Request) {
|
||||
blog, _ := a.getBlog(r)
|
||||
blog, bc := a.getBlog(r)
|
||||
if asRequest, ok := r.Context().Value(asRequestKey).(bool); ok && asRequest {
|
||||
a.serveActivityStreams(blog, w, r)
|
||||
return
|
||||
}
|
||||
a.serveIndex(w, r.WithContext(context.WithValue(r.Context(), indexConfigKey, &indexConfig{
|
||||
path: a.getRelativePath(blog, ""),
|
||||
sections: lo.Values(bc.Sections),
|
||||
})))
|
||||
}
|
||||
|
||||
|
@ -261,6 +263,7 @@ func (a *goBlog) serveDate(w http.ResponseWriter, r *http.Request) {
|
|||
type indexConfig struct {
|
||||
path string
|
||||
section *configSection
|
||||
sections []*configSection
|
||||
tax *configTaxonomy
|
||||
taxValue string
|
||||
parameter string
|
||||
|
@ -284,13 +287,9 @@ func (a *goBlog) serveIndex(w http.ResponseWriter, r *http.Request) {
|
|||
// Decode and sanitize search
|
||||
search = cleanHTMLText(searchDecode(search))
|
||||
}
|
||||
var sections []string
|
||||
sections := lo.Map(ic.sections, func(i *configSection, _ int) string { return i.Name })
|
||||
if ic.section != nil {
|
||||
sections = []string{ic.section.Name}
|
||||
} else {
|
||||
for sectionKey := range bc.Sections {
|
||||
sections = append(sections, sectionKey)
|
||||
}
|
||||
sections = append(sections, ic.section.Name)
|
||||
}
|
||||
defaultStatus, defaultVisibility := a.getDefaultPostStates(r)
|
||||
status := ic.status
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"go.goblog.app/app/pkgs/builderpool"
|
||||
"go.goblog.app/app/pkgs/htmlbuilder"
|
||||
)
|
||||
|
||||
|
@ -65,19 +64,18 @@ func (a *goBlog) renderSummary(hb *htmlbuilder.HtmlBuilder, bc *configBlog, p *p
|
|||
}
|
||||
// Show link to full post
|
||||
hb.WriteElementOpen("p")
|
||||
prefix := builderpool.Get()
|
||||
defer builderpool.Put(prefix)
|
||||
prefix := ""
|
||||
if len(photos) > 0 {
|
||||
// Contains photos
|
||||
prefix.WriteString("🖼️")
|
||||
prefix += "🖼️"
|
||||
}
|
||||
if p.hasTrack() {
|
||||
// Has GPX track
|
||||
prefix.WriteString("🗺️")
|
||||
prefix += "🗺️"
|
||||
}
|
||||
if prefix.Len() > 0 {
|
||||
prefix.WriteString(" ")
|
||||
hb.WriteEscaped(prefix.String())
|
||||
if len(prefix) > 0 {
|
||||
hb.WriteEscaped(" ")
|
||||
hb.WriteEscaped(prefix)
|
||||
}
|
||||
hb.WriteElementOpen("a", "class", "u-url", "href", p.Path)
|
||||
hb.WriteEscaped(a.ts.GetTemplateStringVariant(bc.Lang, "view"))
|
||||
|
|
Loading…
Reference in New Issue