Skip to content

Commit

Permalink
only process the .md files
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Jan 15, 2024
1 parent 4cc2724 commit 692e9e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
17 changes: 14 additions & 3 deletions http/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ func getChangedPosts(config *blog.Config, payload webhookPayload) ([]*blog.Post,
modifiedFiles []string
)
for _, commit := range payload.Commits {
addedFiles = append(addedFiles, commit.Added...)
removedFiles = append(removedFiles, commit.Removed...)
modifiedFiles = append(modifiedFiles, commit.Modified...)
addedFiles = append(addedFiles, getMDFiles(commit.Added)...)
removedFiles = append(removedFiles, getMDFiles(commit.Removed)...)
modifiedFiles = append(modifiedFiles, getMDFiles(commit.Modified)...)
}

var (
Expand Down Expand Up @@ -162,6 +162,17 @@ func getChangedPosts(config *blog.Config, payload webhookPayload) ([]*blog.Post,
return addedPosts, removedFiles, modifiedPosts, nil
}

func getMDFiles(files []string) []string {
var mdFiles []string
for _, file := range files {
if strings.HasSuffix(file, markdown.Extension) {
mdFiles = append(mdFiles, file)
}
}

return mdFiles
}

func (s *Server) reload(config *blog.Config, addedPosts []*blog.Post, removedFiles []string, modifiedPosts []*blog.Post) error {
if s.PostService != nil {
posts := s.PostService.GetAllPosts()
Expand Down
6 changes: 3 additions & 3 deletions markdown/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
summaryLength = 70
threeBackticks = "```"
numberOfRelatedPosts = 5
mdExtension = ".md"
Extension = ".md"
)

// GetAllPosts gets all posts in root directory
Expand All @@ -47,7 +47,7 @@ func GetAllPosts(root string) ([]*blog.Post, error) {
if err != nil {
return err
}
if filepath.Ext(path) != mdExtension {
if filepath.Ext(path) != Extension {
return nil
}
select {
Expand Down Expand Up @@ -178,7 +178,7 @@ func Parse(ctx context.Context, root string, r io.Reader) (*blog.Post, error) {
basename := filepath.Base(name)
p.URI = path.Join(strings.TrimPrefix(filepath.Dir(name), root), basename)
default:
p.URI = path.Join(p.Date.GetYear(), p.Date.GetMonth(), p.Date.GetDay(), fmt.Sprintf("%s%s", url.QueryEscape(strings.ToLower(p.Title)), mdExtension))
p.URI = path.Join(p.Date.GetYear(), p.Date.GetMonth(), p.Date.GetDay(), fmt.Sprintf("%s%s", url.QueryEscape(strings.ToLower(p.Title)), Extension))
}
if !strings.HasPrefix(p.URI, "/") {
p.URI = "/" + p.URI
Expand Down

0 comments on commit 692e9e2

Please sign in to comment.