@@ -10,6 +10,7 @@ import (
1010 "sync"
1111 "unicode"
1212 "unicode/utf8"
13+ "unique"
1314
1415 . "github.com/emad-elsaid/xlog"
1516 "github.com/emad-elsaid/xlog/extensions/shortcode"
@@ -63,7 +64,8 @@ func (l link) Attrs() map[template.HTMLAttr]any {
6364
6465type HashTag struct {
6566 ast.BaseInline
66- value []byte
67+ value []byte
68+ unique unique.Handle [string ]
6769}
6870
6971func (h * HashTag ) RegisterFuncs (reg renderer.NodeRendererFuncRegisterer ) {
@@ -100,7 +102,10 @@ func (h *HashTag) Parse(parent ast.Node, block text.Reader, pc parser.Context) a
100102 }
101103 block .Advance (i )
102104 tag := line [1 :i ]
103- return & HashTag {value : []byte (tag )}
105+ return & HashTag {
106+ value : []byte (tag ),
107+ unique : unique .Make (strings .ToLower (tag )),
108+ }
104109}
105110
106111func (h * HashTag ) Dump (source []byte , level int ) {
@@ -171,7 +176,9 @@ func tagHandler(r Request) Output {
171176 })
172177}
173178
174- func tagPages (ctx context.Context , keyword string ) []Page {
179+ func tagPages (ctx context.Context , hashtag string ) []Page {
180+ uniqHandle := unique .Make (strings .ToLower (hashtag ))
181+
175182 return MapPage (ctx , func (p Page ) Page {
176183 if p .Name () == Config .Index {
177184 return nil
@@ -180,7 +187,7 @@ func tagPages(ctx context.Context, keyword string) []Page {
180187 _ , tree := p .AST ()
181188 tags := FindAllInAST [* HashTag ](tree )
182189 for _ , t := range tags {
183- if strings . EqualFold ( string ( t . value ), keyword ) {
190+ if uniqHandle == t . unique {
184191 return p
185192 }
186193 }
@@ -196,9 +203,9 @@ func relatedPages(p Page) template.HTML {
196203
197204 _ , tree := p .AST ()
198205 found_hashtags := FindAllInAST [* HashTag ](tree )
199- hashtags := map [string ]bool {}
206+ hashtags := map [unique. Handle [ string ] ]bool {}
200207 for _ , v := range found_hashtags {
201- hashtags [strings . ToLower ( string ( v . value )) ] = true
208+ hashtags [v . unique ] = true
202209 }
203210
204211 pages := MapPage (context .Background (), func (rp Page ) Page {
@@ -209,7 +216,7 @@ func relatedPages(p Page) template.HTML {
209216 _ , tree := rp .AST ()
210217 page_hashtags := FindAllInAST [* HashTag ](tree )
211218 for _ , h := range page_hashtags {
212- if _ , ok := hashtags [strings . ToLower ( string ( h . value )) ]; ok {
219+ if _ , ok := hashtags [h . unique ]; ok {
213220 return rp
214221 }
215222 }
0 commit comments