all repos — searchix @ a3cea0d9c64e759683207f55d1f534a330540b1a

Search engine for NixOS, nix-darwin, home-manager and NUR users

feat: enable linking to alternate instance via config

Alin
commit

a3cea0d9c64e759683207f55d1f534a330540b1a

parent

76dcd62d21e962479926f2f2b7dece202ea0b666

M frontend/static/style.cssfrontend/static/style.css
@@ -45,6 +45,18 @@ font-size: 1.15rem;
text-wrap: nowrap; } +header > nav a.other-instance { + padding: unset; + border: unset; + margin-left: auto; + margin-bottom: unset; + font-size: 1rem; + + &:hover { + background: unset; + } +} + nav > h1 > a { margin: 0; padding: 1ex 0;
M internal/components/data.gointernal/components/data.go
@@ -24,6 +24,7 @@ Message string
Title string Description string BaseURL config.URL + OtherInstance *config.Link Assets *frontend.AssetCollection SearchNav SearchNav DetailContent g.Node
M internal/components/page.gointernal/components/page.go
@@ -113,6 +113,13 @@ ),
g.Text(source.Name), ) }), + g.Iff(tdata.OtherInstance != nil, func() g.Node { + return A( + Class("other-instance"), + Href(tdata.OtherInstance.URL.String()), + g.Textf("⇄ %s", tdata.OtherInstance.Name), + ) + }), ), ), Main(children...),
M internal/config/structs.gointernal/config/structs.go
@@ -18,6 +18,11 @@ Web Web `comment:"Settings for the web server"`
Importer Importer `comment:"Settings for the import job"` } +type Link struct { + Name string `comment:"Human-readable name of link."` + URL URL `comment:"URL target."` +} + type Web struct { ContentSecurityPolicy CSP `comment:"Content-Security-Policy header to send with requests. Should only need changing if ExtraHeadHTML is used."` GracefulShutdownTimeout Duration `comment:"How long to wait for connections to finish before shutting down."`
@@ -30,6 +35,7 @@ ExtraHeadHTML string `comment:"Content to add to HTML <head>. Can be used to override styling, add scripts, etc."`
Headers map[string]string `comment:"Extra headers to send with HTTP requests"` LogRequests bool `comment:"Whether to log incoming HTTP requests"` SearchTimeout Duration `comment:"Timeout for search requests"` + OtherInstance *Link `comment:"Link to another instance (e.g. stable <-> unstable)."` } type Importer struct {
M internal/server/error.gointernal/server/error.go
@@ -26,6 +26,7 @@ Sources: sources,
Code: code, Message: message, BaseURL: config.Web.BaseURL, + OtherInstance: config.Web.OtherInstance, Assets: assets, } w.Header().Set("Cache-Control", "no-store")
M internal/server/global.gointernal/server/global.go
@@ -151,6 +151,7 @@ Query: qs,
Title: g.getTitle(source, qs), Description: searchDesc, BaseURL: g.cfg.Web.BaseURL, + OtherInstance: g.cfg.Web.OtherInstance, SearchNav: components.NewSearchNav(*searchURL).WithPagination(page), }, Query: qs,
@@ -194,6 +195,7 @@ Source: source,
Title: g.getTitle(source, ""), Description: "Search Nix packages and options", BaseURL: g.cfg.Web.BaseURL, + OtherInstance: g.cfg.Web.OtherInstance, Assets: g.assets, }, components.ResultData{},
M internal/server/source.gointernal/server/source.go
@@ -117,6 +117,7 @@ Assets: h.global.assets,
Title: h.getTitle(doc), Description: components.MetaDescription(doc), BaseURL: h.global.cfg.Web.BaseURL, + OtherInstance: h.global.cfg.Web.OtherInstance, } baseErr = components.DetailPage(tdata, doc).Render(w) }