Skip to content

Commit

Permalink
fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
hjhee committed Sep 8, 2019
1 parent 2d7441f commit 3878d6d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
version = "v0.1.3.1"
version = "v0.1.3.2"
numFetcher = 10
numParser = 50
numRenderer = 5
Expand Down
10 changes: 8 additions & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"html/template"
"os"
"regexp"
"sort"
"sync"
)
Expand Down Expand Up @@ -61,7 +62,12 @@ func renderHTML(done <-chan struct{}, tempc <-chan *TemplateField, tmpl *templat
t.Merge()
// t.Unique()

filename := fmt.Sprintf("output/file_%s.json", t.Title)
// #6: remove illegal character in title
// ref: https://www.codeproject.com/tips/758861/removing-characters-which-are-not-allowed-in-windo
filenameRegex := regexp.MustCompile(`[\\/:*?""<>|]`)
validFilename := filenameRegex.ReplaceAllLiteralString(t.Title, "")

filename := fmt.Sprintf("output/file_%s.json", validFilename)

b, err := json.Marshal(t)
if err != nil {
Expand All @@ -79,7 +85,7 @@ func renderHTML(done <-chan struct{}, tempc <-chan *TemplateField, tmpl *templat
continue
}

filename = fmt.Sprintf("output/file_%s.html", t.Title)
filename = fmt.Sprintf("output/file_%s.html", validFilename)
err = writeOutput(filename, func(w *bufio.Writer) error {
if err := tmpl.Execute(w, struct {
Title string
Expand Down

0 comments on commit 3878d6d

Please sign in to comment.