Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: 'Generate Docs'
on:
workflow_dispatch:
push:
tags:
- 'v*'
Comment on lines +4 to +6
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will now trigger every time a new release is created.

env:
DOCS_TOKEN: ${{ secrets.DOCS_TOKEN }}
jobs:
Expand Down
37 changes: 30 additions & 7 deletions cmd/gen-docs/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"bytes"
"fmt"
"io"
"os"
"os/user"
"path/filepath"
"regexp"
"sort"
"strings"
"text/template"
Expand Down Expand Up @@ -176,18 +178,39 @@ func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, relativeBasePath stri
}

info := NewTemplateInformation(cmd, dir, relativeBasePath, myPosition)
f, err := os.Create(info.OutputFile)
if err != nil {
return err
}
defer f.Close()

*pageCollection.Pages = append(*pageCollection.Pages, info)

if err := GenMarkdownCustom(cmd, f, info); err != nil {
// Generate new content to buffer
var buf bytes.Buffer
if err := GenMarkdownCustom(cmd, &buf, info); err != nil {
return err
}
return nil
updatedContent := buf.Bytes()

// Only write if content actually changed (ignoring modDate line)
if existingContent, err := os.ReadFile(info.OutputFile); err == nil {
if contentEqualIgnoringModDate(existingContent, updatedContent) {
return nil
}
}

return os.WriteFile(info.OutputFile, updatedContent, 0644)
}

var modDatePattern = regexp.MustCompile(`(?m)^modDate: .+$`)

// contentEqualIgnoringModDate compares two file contents, treating the modDate
// frontmatter line as identical regardless of actual date value.
// Normalizes CRLF to LF before comparing so existing files with different
// line endings don't cause false mismatches.
func contentEqualIgnoringModDate(a, b []byte) bool {
placeholder := []byte("modDate: PLACEHOLDER")
cr := []byte("\r\n")
lf := []byte("\n")
normA := bytes.ReplaceAll(modDatePattern.ReplaceAll(a, placeholder), cr, lf)
normB := bytes.ReplaceAll(modDatePattern.ReplaceAll(b, placeholder), cr, lf)
return bytes.Equal(normA, normB)
}

const documentationTemplate = `---
Expand Down
Loading