Skip to content

Commit

Permalink
add promo support
Browse files Browse the repository at this point in the history
(not tested locally because the project still uses old go and packages versions)
  • Loading branch information
yelizariev committed Jul 20, 2024
1 parent a62f681 commit d123dbb
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Hound is an extremely fast source code search engine. The core is based on this

![Hound Screen Capture](screen_capture.gif)

Live demo: https://odoo-source.com/
Live demo: https://search.odooism.com/

## Quick Start Guide

Expand Down Expand Up @@ -120,6 +120,9 @@ make

If this is your only Go project, you can set your GOPATH just for Hound:
```
cd
mkdir go
cd go
git clone https://github.com/itpp-labs/hound.git src/github.com/itpp-labs/hound
GOPATH=$(pwd) make -C src/github.com/itpp-labs/hound
```
Expand Down
3 changes: 3 additions & 0 deletions config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"init-search": {
"excludeFiles": "ui/bindata.go"
},
"ads": [
"Try it here: <a href=\"https://search.odooism.com/\">search.odooism.com</a>"
],
"repos": [
{
"name" : "SomeGitRepo",
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Config struct {
MaxReposInNextResult int `json:"max-repos-in-next-result"`
HealthCheckURI string `json:"health-check-uri"`
InitSearch map[string]string `json:"init-search"`
Ads []*string `json:"ads"`
}

type Favicon struct {
Expand Down
3 changes: 3 additions & 0 deletions ui/assets/index.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
title="{{ .Title }}" />
</head>
<body>
<div id="promo">
{{ .Promo }}
</div>
<div id="root">
<div id="result">
</div>
Expand Down
14 changes: 14 additions & 0 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,26 @@ func renderForPrd(w io.Writer, c *content, cfg *config.Config, cfgJson string, i
}
buf.WriteString("</script>")

if cfg.Ads != nil && len(cfg.Ads) > 0 {
// Seed the random number generator (typically done once)
rand.Seed(time.Now().UnixNano())

// Generate a random index within the bounds of the Ads slice
randomIndex := rand.Intn(len(cfg.Ads))

// Access the random ad string
randomAd := cfg.Ads[randomIndex]
} else {
randomAd := ""
}

return c.tpl.Execute(w, map[string]interface{}{
"ClientConfigJson": cfgJson,
"Title": cfg.Title,
"Source": html_template.HTML(buf.String()),
"Host": r.Host,
"InitSearch": initSearch,
"Promo": randomAd,
})
}

Expand Down

0 comments on commit d123dbb

Please sign in to comment.