Skip to content
Open
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
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ReadConfigFile() {
logger.Error(err, "Config file not found")

err = json.Unmarshal(e, &jsonConfig)
logger.Fatal(err, "Unable to parse " + os.Getenv("CONFIG_FILE"))
logger.Fatal(err, "Unable to parse "+os.Getenv("CONFIG_FILE"))

}

Expand Down
32 changes: 32 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,20 @@ type ViewJobError struct {
Message string `json:"message"`
}

type NovaClient struct {
Src string `json:"src"`
}

type Meta struct {
NovaClient NovaClient `json:"novaClient"`
}

type hypernovaResult struct {
Success bool
Html string
Name string
Error ViewJobError
Meta Meta
}

type hypernovaResponse struct {
Expand Down Expand Up @@ -95,6 +104,9 @@ func ModifyBody(html string) string {

json.Unmarshal(body, &hypernovaResponse)

novaClientUrls := make(map[string]bool)
novaViewEntries := make(map[string]string)

for uuid, result := range hypernovaResponse.Results {
divQuery := createQuery("div", uuid, result.Name)

Expand All @@ -103,12 +115,32 @@ func ModifyBody(html string) string {
continue
}

if result.Meta.NovaClient.Src != "" {
novaClientUrls[result.Meta.NovaClient.Src] = true
novaViewEntries[result.Name] = result.Meta.NovaClient.Src
}

scriptQuery := createQuery("script", uuid, result.Name)
doc.Find(scriptQuery).Remove()

doc.Find(divQuery).ReplaceWithHtml(result.Html)
}

if len(batch) > 0 {
bodyNode := doc.Find("body")
for url := range novaClientUrls {
bodyNode.AppendHtml("<script async src=\"" + url + "\">")
}

b, encodeErr := json.Marshal(novaViewEntries)

if encodeErr != nil {
logger.Fatal(encodeErr, "Cannot encode nova view entries")
}

bodyNode.PrependHtml("<script> window.__NOVA_VIEWS__=" + string(b) + "</script>")
}

html, htmlError := doc.Html()

if htmlError != nil {
Expand Down