Skip to content

Commit

Permalink
blog: improve extractTitleAndContents logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 30, 2024
1 parent 4ecb21a commit 09274ce
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions blog.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@ func extractTitleAndContents(raw []byte) (title string, contents []byte, err err
for i, c := range raw {
// We are assuming that each file has one title as a H1 header
if c == '\n' {
original := string(raw[:i])
clean := strings.Replace(string(raw[:i]), "# ", "", 1)
if clean == original {
return "", nil, fmt.Errorf("could not find title")
if raw[0] != '#' {
return "", nil, fmt.Errorf("could not find '#', file seems to be missing a H1 header")
}
title = clean
title = string(bytes.TrimSpace(raw[1:i]))
contents = bytes.TrimSpace(raw[i:])
break
}
Expand Down

0 comments on commit 09274ce

Please sign in to comment.