Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linter to check truncate tag in blog posts #4139

Merged
merged 7 commits into from Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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