Skip to content

Commit

Permalink
(fix) limit screenshot filename lengths
Browse files Browse the repository at this point in the history
fixes #121
  • Loading branch information
leonjza committed Jun 10, 2022
1 parent 2f87924 commit 19b4e15
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ func SliceContainsString(s []string, e string) bool {

return false
}

// TruncateString truncates a string for l characters
func TruncateString(s string, l int) string {

if len(s) <= l {
return s
}

var n string
for _, char := range s {
n = n + string(char)
}

return n
}
3 changes: 3 additions & 0 deletions lib/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ func (p *Processor) init() {
p.fn = SafeFileName(p.URL.String())
}

// limit filename length
p.fn = TruncateString(p.fn, 30)

// set the extention depending on the screenshot format
if p.Chrome.AsPDF {
p.fn = p.fn + ".pdf"
Expand Down

0 comments on commit 19b4e15

Please sign in to comment.