Skip to content

Commit

Permalink
perf(youtube): Add fast case for hashtag and timestamp formatters
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 3, 2025
1 parent b13729d commit c348065
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/youtube/html/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ import (
var hashtagRe = regexp.MustCompile(`(^|\s)#([A-Za-z0-9_]+)`)

func FormatHashtags(s string) string {
if !strings.Contains(s, "#") {
return s
}
return hashtagRe.ReplaceAllString(s, `$1<a href="https://youtube.com/hashtag/$2">#$2</a>`)
}

var timestampRe = regexp.MustCompile("([0-9]:)?[0-9]+:[0-9]+")

func FormatTimestamps(id, s string) string {
if !strings.Contains(s, ":") {
return s
}
return timestampRe.ReplaceAllStringFunc(s, func(s string) string {
cleaned := s
if strings.Count(s, ":") == 2 {
Expand Down

0 comments on commit c348065

Please sign in to comment.