Skip to content

Commit

Permalink
only statistics on blog posts starting with /year/month/day/...
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Jul 13, 2024
1 parent 75f1219 commit f5f2a64
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net"
"net/http"
"path"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -87,8 +88,10 @@ func NewServer(logger zerolog.Logger, config *blog.Config, posts []*blog.Post) (

if config.Env != "local" {
go func() {
pattern := `^/\d{4}/\d{2}/\d{2}/[a-z-]+(\.md)?$`
regex := regexp.MustCompile(pattern)
ua := r.Header.Get("User-Agent")
if !strings.Contains(strings.ToLower(ua), "bot") {
if regex.MatchString(r.URL.Path) && !strings.Contains(strings.ToLower(ua), "bot") {
ip, err := httperror.GetIP(r)
if err != nil {
s.logger.Error().Err(err).Msg("failed to get IP address")
Expand Down

0 comments on commit f5f2a64

Please sign in to comment.