Skip to content

Commit

Permalink
remove Emoji method from page
Browse files Browse the repository at this point in the history
  • Loading branch information
emad-elsaid committed Jan 11, 2025
1 parent 1d17119 commit 2aac3cc
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 34 deletions.
9 changes: 0 additions & 9 deletions extensions/gpg/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"time"

"github.com/emad-elsaid/xlog"
emojiAst "github.com/yuin/goldmark-emoji/ast"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
)
Expand Down Expand Up @@ -100,11 +99,3 @@ func (p *page) AST() ([]byte, ast.Node) {

return []byte(src), p.ast
}
func (p *page) Emoji() string {
_, tree := p.AST()
if e, ok := xlog.FindInAST[*emojiAst.Emoji](tree); ok && e != nil {
return string(e.Value.Unicode)
}

return ""
}
1 change: 0 additions & 1 deletion extensions/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,3 @@ func (p *page) Write(content xlog.Markdown) bool {
}

func (p *page) AST() ([]byte, ast.Node) { return []byte{}, ast.NewDocument() }
func (p *page) Emoji() string { return "" }
1 change: 0 additions & 1 deletion extensions/pandoc/pandoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,3 @@ func (p *page) Write(content xlog.Markdown) bool {
}

func (p *page) AST() ([]byte, ast.Node) { return []byte{}, ast.NewDocument() }
func (p *page) Emoji() string { return "" }
1 change: 0 additions & 1 deletion extensions/photos/photos.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func (p *Photo) Name() string {
return base[:len(base)-len(ext)]
}

func (*Photo) Emoji() string { return "" }
func (*Photo) FileName() string { return "" }
func (*Photo) Exists() bool { return false }
func (*Photo) Content() xlog.Markdown { return "" }
Expand Down
2 changes: 1 addition & 1 deletion extensions/search/templates/search-result.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<a href="/{{.Page.Name}}">
<strong class="is-block mb-1">
{{ with .Page }}
{{.Emoji}}
{{ emoji . }}
{{ $props := properties . }}
{{ with $props.title }} {{ .Value }} {{ else }} {{ .Name }} {{ end }}
{{ end }}
Expand Down
4 changes: 2 additions & 2 deletions extensions/star/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ type starredPage struct {
}

func (s starredPage) Icon() string {
if s.Emoji() == "" {
if e := Emoji(s); e == "" {
return "fa-solid fa-star"
} else {
return s.Emoji()
return e
}
}

Expand Down
3 changes: 1 addition & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ func getPageHandler(r Request) Output {
Trigger(PageNotFound, page)

page = DynamicPage{
NameVal: page.Name(),
EmojiVal: "",
NameVal: page.Name(),
RenderFn: func() template.HTML {
str := "Page doesn't exist"

Expand Down
11 changes: 11 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

emojiAst "github.com/yuin/goldmark-emoji/ast"
"github.com/yuin/goldmark/ast"
gast "github.com/yuin/goldmark/ast"
)
Expand All @@ -23,6 +24,7 @@ var helpers = template.FuncMap{
"includeJS": includeJS,
"scripts": scripts,
"banner": Banner,
"emoji": Emoji,
}

var ErrHelperRegistered = errors.New("Helper already registered")
Expand Down Expand Up @@ -160,3 +162,12 @@ func Banner(p Page) string {

return string(image.Destination)
}

func Emoji(p Page) string {
_, tree := p.AST()
if e, ok := FindInAST[*emojiAst.Emoji](tree); ok && e != nil {
return string(e.Value.Unicode)
}

return ""
}
14 changes: 0 additions & 14 deletions page.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"time"

emojiAst "github.com/yuin/goldmark-emoji/ast"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
)
Expand Down Expand Up @@ -44,8 +43,6 @@ type Page interface {
// parts of the page. for example the following "Emoji" function uses it to
// extract the first emoji.
AST() ([]byte, ast.Node)
// Returns the first emoji of the page.
Emoji() string
}

type page struct {
Expand Down Expand Up @@ -155,15 +152,6 @@ func (p *page) AST() (source []byte, tree ast.Node) {
return []byte(content), p.ast
}

func (p *page) Emoji() string {
_, tree := p.AST()
if e, ok := FindInAST[*emojiAst.Emoji](tree); ok && e != nil {
return string(e.Value.Unicode)
}

return ""
}

func (p *page) clearCache() {
p.content = nil
p.ast = nil
Expand All @@ -174,7 +162,6 @@ func (p *page) clearCache() {
// be passed to templates without having underlying file on desk
type DynamicPage struct {
NameVal string
EmojiVal string
RenderFn func() template.HTML
}

Expand All @@ -186,7 +173,6 @@ func (DynamicPage) Write(Markdown) bool { return false }
func (DynamicPage) ModTime() time.Time { return time.Time{} }
func (DynamicPage) AST() ([]byte, ast.Node) { return nil, nil }
func (d DynamicPage) Name() string { return d.NameVal }
func (d DynamicPage) Emoji() string { return d.EmojiVal }
func (d DynamicPage) Render() template.HTML {
if d.RenderFn != nil {
return d.RenderFn()
Expand Down
4 changes: 2 additions & 2 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{ $props := properties .page }}
{{- with .page -}}
{{- if ne .Name $.config.Index -}}
{{ .Emoji }}
{{ emoji . }}
{{ with $props.title }} {{ .Value }} {{ else }} {{ .Name }} {{ end }}
|
{{ end -}}
Expand All @@ -28,7 +28,7 @@
{{- if ne .config.Index .page.Name -}}
<div dir="auto" class="title is-1 has-text-weight-bold" style="view-transition-name: page-title;">
{{- with .page -}}
{{- .Emoji }}
{{- emoji . }}
{{ with $props.title }} {{ .Value }} {{ else }} {{ .Name }} {{ end }}
{{- end -}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/pages.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{ end }}

<span class="is-block">
{{ .Emoji }}
{{ emoji . }}
{{ $props := properties . }}
{{ with $props.title }} {{ .Value }} {{ else }} {{ .Name }} {{ end }}
</span>
Expand Down

0 comments on commit 2aac3cc

Please sign in to comment.