Skip to content

Commit

Permalink
refactor: url linking to DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Jan 21, 2024
1 parent 622f3d9 commit 6be6931
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
7 changes: 5 additions & 2 deletions blog/about/about.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package about

import "darklab_blog/blog/common/compon"
import (
"darklab_blog/blog/common/compon"
"darklab_blog/blog/common/urls"
)

type About struct {
compon.Component
Expand All @@ -9,7 +12,7 @@ type About struct {
func NewAbout() *About {
return &About{
compon.NewComponent(
"about.html",
urls.About,
AboutT(),
),
}
Expand Down
7 changes: 5 additions & 2 deletions blog/articles/home.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package articles

import "darklab_blog/blog/common/compon"
import (
"darklab_blog/blog/common/compon"
"darklab_blog/blog/common/urls"
)

/*
Article navigation page
Expand All @@ -13,7 +16,7 @@ type Home struct {
func NewHome() *Home {
return &Home{
compon.NewComponent(
"index.html",
urls.Home,
HomeT(),
),
}
Expand Down
7 changes: 4 additions & 3 deletions blog/common/menu.templ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"darklab_blog/blog/settings"
"darklab_blog/blog/common/urls"
)

templ NavElem(url string) {
Expand All @@ -15,11 +16,11 @@ templ Menu() {
@NavElem(settings.SiteRoot) {
Articles
}
@NavElem(settings.SiteRoot + "pet_projects.html") {
@NavElem(settings.SiteRoot + urls.PetProjects) {
Pet projects
}
@NavElem(settings.SiteRoot + "about.html") {
@NavElem(settings.SiteRoot + urls.About) {
About
}
}
</menu>
}
9 changes: 9 additions & 0 deletions blog/common/urls/urls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package urls

const (
Home = "index.html"

About = "about.html"

PetProjects = "pet_projects.html"
)
7 changes: 5 additions & 2 deletions blog/pet_projects/pet_projects.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package pet_projects

import "darklab_blog/blog/common/compon"
import (
"darklab_blog/blog/common/compon"
"darklab_blog/blog/common/urls"
)

type PetProjects struct {
compon.Component
Expand All @@ -9,7 +12,7 @@ type PetProjects struct {
func NewPetProjects() *PetProjects {
return &PetProjects{
compon.NewComponent(
"pet_projects.html",
urls.PetProjects,
PetProjectsT(),
),
}
Expand Down

0 comments on commit 6be6931

Please sign in to comment.