Skip to content

Commit

Permalink
Rebuild ui/bindata.go for #336 (#338)
Browse files Browse the repository at this point in the history
* Allow to customize title via config.json

* Rebuld ui/bindata.go

Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
  • Loading branch information
kellegous and simon04 committed Feb 12, 2020
1 parent 838e045 commit 8374f32
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
1 change: 1 addition & 0 deletions config-example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"max-concurrent-indexers" : 2,
"dbpath" : "data",
"title" : "Hound",
"health-check-uri" : "/healthz",
"repos" : {
"SomeGitRepo" : {
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
defaultMaxConcurrentIndexers = 2
defaultPushEnabled = false
defaultPollEnabled = true
defaultTitle = "Hound"
defaultVcs = "git"
defaultBaseUrl = "{url}/blob/master/{path}{anchor}"
defaultAnchor = "#L{line}"
Expand Down Expand Up @@ -55,6 +56,7 @@ func (r *Repo) PushUpdatesEnabled() bool {

type Config struct {
DbPath string `json:"dbpath"`

This comment was marked as spam.

Copy link
@Barberj859

Barberj859 Oct 4, 2021

What's up with you studying my genes looking for the gay genotype?

Title string `json:"title"`
Repos map[string]*Repo `json:"repos"`
MaxConcurrentIndexers int `json:"max-concurrent-indexers"`
HealthCheckURI string `json:"health-check-uri"`
Expand Down Expand Up @@ -136,6 +138,10 @@ func (c *Config) LoadFromFile(filename string) error {
return err
}

if c.Title == "" {
c.Title = defaultTitle
}

if !filepath.IsAbs(c.DbPath) {
path, err := filepath.Abs(
filepath.Join(filepath.Dir(filename), c.DbPath))
Expand Down
4 changes: 2 additions & 2 deletions ui/assets/index.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<title>Hound</title>
<title>{{ .Title }}</title>
<link rel="stylesheet" href="css/octicons/octicons.css">
<link rel="stylesheet" href="css/hound.css">
<link rel="search" href="//{{ .Host }}/open_search.xml"
type="application/opensearchdescription+xml"
title="Hound" />
title="{{ .Title }}" />
</head>
<body>
<div id="root">
Expand Down
46 changes: 23 additions & 23 deletions ui/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func renderForDev(w io.Writer, root string, c *content, cfg *config.Config, r *h
"ReactVersion": ReactVersion,
"jQueryVersion": JQueryVersion,
"ReposAsJson": json,
"Title": cfg.Title,
"Source": html_template.HTML(buf.String()),
"Host": r.Host,
})
Expand Down Expand Up @@ -128,7 +129,7 @@ func (h *prdHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ct := h.content[p]
if ct != nil {
// if so, render it
if err := renderForPrd(w, ct, h.cfgJson, r); err != nil {
if err := renderForPrd(w, ct, h.cfg, h.cfgJson, r); err != nil {
log.Panic(err)
}
return
Expand All @@ -142,7 +143,7 @@ func (h *prdHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {

// Renders a templated asset in prd-mode. This strategy will embed
// the sources directly in a script tag on the templated page.
func renderForPrd(w io.Writer, c *content, cfgJson string, r *http.Request) error {
func renderForPrd(w io.Writer, c *content, cfg *config.Config, cfgJson string, r *http.Request) error {
var buf bytes.Buffer
buf.WriteString("<script>")
for _, src := range c.sources {
Expand All @@ -158,6 +159,7 @@ func renderForPrd(w io.Writer, c *content, cfgJson string, r *http.Request) erro
"ReactVersion": ReactVersion,
"jQueryVersion": JQueryVersion,
"ReposAsJson": cfgJson,
"Title": cfg.Title,
"Source": html_template.HTML(buf.String()),
"Host": r.Host,
})
Expand Down

0 comments on commit 8374f32

Please sign in to comment.