Skip to content

Commit

Permalink
Add linter to check truncate tag in blog posts (#4139)
Browse files Browse the repository at this point in the history
Closes #4048.
  • Loading branch information
sbshah97 committed Mar 8, 2024
1 parent 892780a commit e98d536
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions tools/checkdocs/checkdocs.go
Expand Up @@ -45,12 +45,13 @@ func checkFiles(files []string, logf, fatalf func(string, ...any)) {
var failed bool

for _, file := range files {
b, err := os.ReadFile(file)
fileInBytes, err := os.ReadFile(file)
if err != nil {
fatalf("Couldn't read file %s: %s", file, err)
}

if b, err = extractFrontMatter(b); err != nil {
b, err := extractFrontMatter(fileInBytes)
if err != nil {
fatalf("Couldn't extract front matter from %s: %s", file, err)
}

Expand All @@ -68,13 +69,27 @@ func checkFiles(files []string, logf, fatalf func(string, ...any)) {
logf("%q: %s", file, err)
failed = true
}

if err = verifyTruncateString(fileInBytes); err != nil {
logf("%q: %s", file, err)
failed = true
}
}

if failed {
fatalf("One or more blog posts are not correctly formatted")
}
}

// verifyTruncateString checks that the truncate string is present.
func verifyTruncateString(b []byte) error {
if !bytes.Contains(b, []byte("<!--truncate-->")) {
return fmt.Errorf("<!--truncate--> must be included to have \"Read more\" link on the homepage")
}

return nil
}

// extractFrontMatter returns the front matter of a blog post.
func extractFrontMatter(fm []byte) ([]byte, error) {
var in bool
Expand Down
5 changes: 5 additions & 0 deletions tools/checkdocs/checkdocs_test.go
Expand Up @@ -62,3 +62,8 @@ func TestVerifyTags(t *testing.T) {
err := verifyTags(fm)
assert.EqualError(t, err, `tag "documents databases" is not in the allowed list`)
}

func TestVerifyTruncateString(t *testing.T) {
err := verifyTruncateString(fm)
assert.EqualError(t, err, "<!--truncate--> must be included to have \"Read more\" link on the homepage")
}
Expand Up @@ -13,6 +13,8 @@ tags: [release]
We are starting the new year with a major feature addition!
The latest version of FerretDB v1.18.0 has just been released with support for basic OpLog functionality, along with other exciting features.

<!--truncate-->

OpLog (operations log) functionality has been one of our most requested features, and it would make it possible for developers to build real-time applications using the Meteor framework.
We made this a priority in the last quarter and are super excited that it's now available.
We can't wait to see what you build with FerretDB!
Expand Down

0 comments on commit e98d536

Please sign in to comment.