Skip to content

Commit

Permalink
Do not show front page link on the front page
Browse files Browse the repository at this point in the history
  • Loading branch information
espebra committed Aug 21, 2020
1 parent 2cb516e commit 0edc945
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ds/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package ds

type Common struct {
Page string `json:"-"`
}
2 changes: 2 additions & 0 deletions http_bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ func (h *HTTP) ViewBin(w http.ResponseWriter, r *http.Request) {
inputBin := params["bin"]

type Data struct {
ds.Common
Bin ds.Bin `json:"bin"`
Files []ds.File `json:"files"`
}
var data Data
data.Page = "viewbin"

bin, found, err := h.dao.Bin().GetById(inputBin)
if err != nil {
Expand Down
16 changes: 15 additions & 1 deletion http_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import (
func (h *HTTP) Index(w http.ResponseWriter, r *http.Request) {

type Data struct {
ds.Common
Bin ds.Bin `json:"bin"`
}
var data Data

data.Page = "front"

bin := &ds.Bin{}
bin.Expiration = time.Now().UTC().Add(h.expirationDuration)
err := h.dao.Bin().Insert(bin)
Expand All @@ -35,7 +38,14 @@ func (h *HTTP) Index(w http.ResponseWriter, r *http.Request) {

func (h *HTTP) About(w http.ResponseWriter, r *http.Request) {
//w.Header().Set("Cache-Control", "max-age=900")
if err := h.templates.ExecuteTemplate(w, "about", nil); err != nil {
type Data struct {
ds.Common
Bin ds.Bin `json:"bin"`
}
var data Data
data.Page = "about"

if err := h.templates.ExecuteTemplate(w, "about", data); err != nil {
fmt.Printf("Failed to execute template: %s\n", err.Error())
http.Error(w, "Errno 302", http.StatusInternalServerError)
return
Expand All @@ -44,9 +54,11 @@ func (h *HTTP) About(w http.ResponseWriter, r *http.Request) {

func (h *HTTP) API(w http.ResponseWriter, r *http.Request) {
type Data struct {
ds.Common
Bin ds.Bin `json:"bin"`
}
var data Data
data.Page = "api"

//w.Header().Set("Cache-Control", "max-age=900")
if err := h.templates.ExecuteTemplate(w, "api", data); err != nil {
Expand All @@ -59,9 +71,11 @@ func (h *HTTP) API(w http.ResponseWriter, r *http.Request) {
func (h *HTTP) APISpec(w http.ResponseWriter, r *http.Request) {

type Data struct {
ds.Common
Bin ds.Bin `json:"bin"`
}
var data Data
data.Page = "api"

w.Header().Set("Content-Type", "application/json")
//w.Header().Set("Cache-Control", "max-age=900")
Expand Down
4 changes: 4 additions & 0 deletions templates/topbar.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{{ define "topbar" }}

<nav class="navbar navbar-expand-sm navbar-light d-flex justify-content-between align-items-start small">
<div>
<ul class="navbar-nav">
<li class="nav-item">
{{ if eq .Page "front" }}
{{ else }}
<a class="nav-link" href="/">Front page</a>
{{ end }}
</li>
</ul>
</div>
Expand Down

0 comments on commit 0edc945

Please sign in to comment.