diff --git a/bootstrap/routes.go b/bootstrap/routes.go index af91a6f..19b58ec 100644 --- a/bootstrap/routes.go +++ b/bootstrap/routes.go @@ -19,17 +19,21 @@ along with this program. If not, see .Rawley Fow import ( "github.com/gin-gonic/gin" - "gitlab.com/rawleyifowler/site-rework/controllers" - "gitlab.com/rawleyifowler/site-rework/utils" + "github.com/rawleyfowler/rawleydotxyz/controllers" + "github.com/rawleyfowler/rawleydotxyz/utils" ) -// Initializes all routes from the controller package +// Initializes all routes from the controller package. +// Uses the ServePage function from utils to generate static route handlers. func InitializeRoutes(router *gin.Engine) { + // No route will serve the not found page. router.NoRoute(utils.ServePage("not_found.tmpl")) + // Router groups for dynamic routing and dynamic pages. blogGroup := router.Group("/blog") controllers.RegisterBlogGroup(blogGroup) adminGroup := router.Group("/admin") controllers.RegisterAdminGroup(adminGroup) + // Static routes that serve the same html every time. router.GET("/", utils.ServePage("index.tmpl")) router.GET("/resume", utils.ServePage("resume.tmpl")) router.GET("/contact", utils.ServePage("contact.tmpl")) diff --git a/controllers/admin.go b/controllers/admin.go index b57bdc2..e982518 100644 --- a/controllers/admin.go +++ b/controllers/admin.go @@ -22,9 +22,9 @@ import ( "time" "github.com/gin-gonic/gin" - "gitlab.com/rawleyifowler/site-rework/models" - "gitlab.com/rawleyifowler/site-rework/repos" - "gitlab.com/rawleyifowler/site-rework/utils" + "github.com/rawleyfowler/rawleydotxyz/models" + "github.com/rawleyfowler/rawleydotxyz/repos" + "github.com/rawleyfowler/rawleydotxyz/utils" ) var ( diff --git a/controllers/blog.go b/controllers/blog.go index a5ed30f..6c519be 100644 --- a/controllers/blog.go +++ b/controllers/blog.go @@ -19,7 +19,7 @@ import ( "net/http" "github.com/gin-gonic/gin" - "gitlab.com/rawleyifowler/site-rework/repos" + "github.com/rawleyfowler/rawleydotxyz/repos" ) type CommentDto struct { @@ -52,12 +52,11 @@ func (bc *BlogController) IndexBlogPage(c *gin.Context) { } func (bc *BlogController) IndividualBlogPage(c *gin.Context) { + // Using the repository, get the plug that correlates to the url post, err := bc.Repository.GetBlogByUrl(c.Param("url")) if err != nil { c.HTML(http.StatusNotFound, "not_found.tmpl", &gin.H{}) return } - // TODO: Re implement captcha here. It is already included on the blog post model, though not in the database. - // The idea is to generate a captcha for each post, and index them by title. The async service should then update each captcha every hour. c.HTML(http.StatusOK, "blog_post.tmpl", post) } diff --git a/go.mod b/go.mod index 94b2dd1..1f4d271 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module gitlab.com/rawleyifowler/site-rework +module github.com/rawleyfowler/rawleydotxyz go 1.15 diff --git a/main.go b/main.go index e0d49da..c00f1c5 100644 --- a/main.go +++ b/main.go @@ -21,7 +21,7 @@ import ( "html/template" "github.com/gin-gonic/gin" - "gitlab.com/rawleyifowler/site-rework/bootstrap" + "github.com/rawleyfowler/rawleydotxyz/bootstrap" ) var router *gin.Engine diff --git a/repos/admin_repo.go b/repos/admin_repo.go index b2706e6..39b5959 100644 --- a/repos/admin_repo.go +++ b/repos/admin_repo.go @@ -23,8 +23,8 @@ import ( "fmt" "github.com/google/uuid" - "gitlab.com/rawleyifowler/site-rework/models" - "gitlab.com/rawleyifowler/site-rework/utils" + "github.com/rawleyfowler/rawleydotxyz/models" + "github.com/rawleyfowler/rawleydotxyz/utils" "gorm.io/gorm" ) diff --git a/repos/blog_repo.go b/repos/blog_repo.go index 50a9159..debb3d3 100644 --- a/repos/blog_repo.go +++ b/repos/blog_repo.go @@ -20,8 +20,8 @@ along with this program. If not, see .Rawley Fow import ( "errors" - "gitlab.com/rawleyifowler/site-rework/models" - "gitlab.com/rawleyifowler/site-rework/utils" + "github.com/rawleyfowler/rawleydotxyz/models" + "github.com/rawleyfowler/rawleydotxyz/utils" "gorm.io/gorm" ) diff --git a/utils/api_key.go b/utils/api_key.go index eff08e4..060a022 100644 --- a/utils/api_key.go +++ b/utils/api_key.go @@ -22,6 +22,8 @@ import ( "os" ) +// Loads the api key from a local file given by path. +// This api key is used to make admins. func LoadApiKey(path string) string { file, err := os.Open(path) if err != nil { diff --git a/utils/serve_page.go b/utils/serve_page.go index aab78ec..af46d27 100644 --- a/utils/serve_page.go +++ b/utils/serve_page.go @@ -24,6 +24,11 @@ import ( "github.com/gin-gonic/gin" ) +// Serves a static page, based on its name. +// Returns a handler func that renders a given page. +// Page input t should always be .tmpl +// Also sets the title for the page if it allows for dyanmic titles. +// index.tmpl will have an empty title. func ServePage(t string) gin.HandlerFunc { title := strings.Split(t, ".")[0] if title == "index" {