Skip to content

Commit

Permalink
Fixed issue #3: Preview strips images and code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zlowram committed Jan 19, 2015
1 parent 9a7a4dc commit 682a805
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ func loadPost(filename string) Post {
// Convert the markdown to HTML
post.Content = string(blackfriday.MarkdownCommon([]byte(strings.Trim(strings.Join(x[1:], "\n\n"), "\n"))))

// Get the excerpt
words := strings.Split(post.Content, " ")
// Get the preview
rtags := regexp.MustCompile(`<(pre|code|img).*>(.|\s)*?(</(pre|code|img)>)+`)
stripped := rtags.ReplaceAllString(post.Content, "[...]")

words := strings.Split(stripped, " ")
if len(words) <= site.Config.PreviewLength {
post.Preview = post.Content
post.Preview = stripped
} else {
post.Preview = strings.Join(words[:site.Config.PreviewLength], " ") + "..."
}
Expand Down

0 comments on commit 682a805

Please sign in to comment.