diff --git a/Makefile b/Makefile
index 92754d5..bdb3dfc 100644
--- a/Makefile
+++ b/Makefile
@@ -27,8 +27,8 @@ clean:
rm -rf $(BUILD_DIR)
install-tools:
- go install github.com/pressly/goose/v3/cmd/goose@v3.18.0 0.2.543
- go install github.com/a-h/templ/cmd/templ@v0.2.543 0.2.543
+ go install github.com/pressly/goose/v3/cmd/goose@v3.18.0
+ go install github.com/a-h/templ/cmd/templ@v0.2.543
go install github.com/cosmtrek/air@v1.49.0
.PHONY: all build test clean
diff --git a/app/app.go b/app/app.go
index 4f412f2..37b3f71 100644
--- a/app/app.go
+++ b/app/app.go
@@ -105,7 +105,7 @@ func homeHandler(c *gin.Context, settings common.AppSettings, db database.Databa
}
// if not cached, create the cache
- index_view := views.MakeIndex(posts)
+ index_view := views.MakeIndex(posts, settings.AppNavbar.Links)
html_buffer := bytes.NewBuffer(nil)
err = index_view.Render(c, html_buffer)
diff --git a/app/contact.go b/app/contact.go
index a9cbfc5..6aa8384 100644
--- a/app/contact.go
+++ b/app/contact.go
@@ -59,7 +59,7 @@ func makeContactFormHandler() func(*gin.Context) {
// TODO : This is a duplicate of the index handler... abstract
func contactHandler(c *gin.Context, app_settings common.AppSettings, db database.Database) ([]byte, error) {
- index_view := views.MakeContactPage()
+ index_view := views.MakeContactPage(app_settings.AppNavbar.Links)
html_buffer := bytes.NewBuffer(nil)
if err := index_view.Render(c, html_buffer); err != nil {
log.Error().Msgf("could not render: %v", err)
diff --git a/app/image.go b/app/image.go
index e087b5e..2e65d31 100644
--- a/app/image.go
+++ b/app/image.go
@@ -36,7 +36,7 @@ func imagesHandler(c *gin.Context, app_settings common.AppSettings, database dat
}
// if not cached, create the cache
- index_view := views.MakeImagesPage(images)
+ index_view := views.MakeImagesPage(images, app_settings.AppNavbar.Links)
html_buffer := bytes.NewBuffer(nil)
err = index_view.Render(c, html_buffer)
@@ -60,7 +60,7 @@ func imageHandler(c *gin.Context, app_settings common.AppSettings, database data
}
// if not cached, create the cache
- index_view := views.MakeImagePage(image)
+ index_view := views.MakeImagePage(image, app_settings.AppNavbar.Links)
html_buffer := bytes.NewBuffer(nil)
err = index_view.Render(c, html_buffer)
diff --git a/app/post.go b/app/post.go
index 83a756a..0fc5614 100644
--- a/app/post.go
+++ b/app/post.go
@@ -50,7 +50,7 @@ func postHandler(c *gin.Context, app_settings common.AppSettings, database datab
// Generate HTML page
post.Content = string(mdToHTML([]byte(post.Content)))
- post_view := views.MakePostPage(post.Title, post.Content)
+ post_view := views.MakePostPage(post.Title, post.Content, app_settings.AppNavbar.Links)
html_buffer := bytes.NewBuffer(nil)
if err = post_view.Render(c, html_buffer); err != nil {
log.Error().Msgf("could not render: %v", err)
diff --git a/cmd/urchin-admin/main.go b/cmd/urchin-admin/main.go
index dd329d9..49659a6 100644
--- a/cmd/urchin-admin/main.go
+++ b/cmd/urchin-admin/main.go
@@ -21,7 +21,7 @@ func main() {
flag.Parse()
var app_settings common.AppSettings
- if *config_toml != "" {
+ if *config_toml == "" {
log.Error().Msgf("config not specified (--config)")
os.Exit(-1)
}
diff --git a/common/app_settings.go b/common/app_settings.go
index a19e4f3..0f9db9b 100644
--- a/common/app_settings.go
+++ b/common/app_settings.go
@@ -4,6 +4,10 @@ import (
"github.com/BurntSushi/toml"
)
+type Navbar struct {
+ Links []Link `toml:"links"`
+}
+
type AppSettings struct {
DatabaseAddress string `toml:"database_address"`
DatabasePort int `toml:"database_port"`
@@ -12,6 +16,7 @@ type AppSettings struct {
DatabaseName string `toml:"database_name"`
WebserverPort int `toml:"webserver_port"`
ImageDirectory string `toml:"image_dir"`
+ AppNavbar Navbar `toml:"navbar"`
}
func ReadConfigToml(filepath string) (AppSettings, error) {
diff --git a/common/navigation.go b/common/navigation.go
index ac10c63..e19ef6d 100644
--- a/common/navigation.go
+++ b/common/navigation.go
@@ -1,6 +1,7 @@
package common
type Link struct {
- Name string
- Href string
+ Name string
+ Href string
+ Title string
}
diff --git a/docker/urchin_config.toml b/docker/urchin_config.toml
index c0e834b..d7e2132 100644
--- a/docker/urchin_config.toml
+++ b/docker/urchin_config.toml
@@ -19,3 +19,12 @@ webserver_port = 8080
# Directory to use for storing uploaded images.
image_dir = "./images"
+
+[navbar]
+links = [
+ { name = "Home", href = "/", title = "Homepage" },
+ { name = "About", href = "/about", title = "About page" },
+ { name = "Services", href = "/services", title = "Services page" },
+ { name = "Images", href = "/images", title = "Images page" },
+ { name = "Contact", href = "/contact", title = "Contacts page" },
+]
diff --git a/tests/app_tests/app_settings/app_settings_test.go b/tests/app_tests/app_settings/app_settings_test.go
index 9672dd5..cc880c5 100644
--- a/tests/app_tests/app_settings/app_settings_test.go
+++ b/tests/app_tests/app_settings/app_settings_test.go
@@ -36,6 +36,15 @@ func TestCorrectToml(t *testing.T) {
DatabaseName: "test_database_name",
WebserverPort: 99999,
DatabasePort: 666,
+ AppNavbar: common.Navbar{
+ Links: []common.Link{
+ {Name: "Home", Href: "/", Title: "Homepage"},
+ {Name: "About", Href: "/about", Title: "About page"},
+ {Name: "Services", Href: "/services", Title: "Services page"},
+ {Name: "Images", Href: "/images", Title: "Images page"},
+ {Name: "Contact", Href: "/contact", Title: "Contacts page"},
+ },
+ },
}
bytes, err := toml.Marshal(expected)
assert.Nil(t, err)
diff --git a/urchin_config.toml b/urchin_config.toml
index 2b68fe1..839e93e 100644
--- a/urchin_config.toml
+++ b/urchin_config.toml
@@ -19,3 +19,12 @@ webserver_port = 8080
# Directory to use for storing uploaded images.
image_dir = "./images"
+
+[navbar]
+links = [
+ { name = "Home", href = "/", title = "Homepage" },
+ { name = "About", href = "/about", title = "About page" },
+ { name = "Services", href = "/services", title = "Services page" },
+ { name = "Images", href = "/images", title = "Images page" },
+ { name = "Contact", href = "/contact", title = "Contacts page" },
+]
diff --git a/views/contact.templ b/views/contact.templ
index 76b1db1..2ab0d50 100644
--- a/views/contact.templ
+++ b/views/contact.templ
@@ -1,6 +1,8 @@
package views
-templ MakeContactPage() {
+import "github.com/matheusgomes28/urchin/common"
+
+templ MakeContactPage(links []common.Link) {
@@ -14,7 +16,7 @@ templ MakeContactPage() {
- @MakeNavBar()
+ @MakeNavBar(links)