added comments, updated go.mod to reflect new repo
This commit is contained in:
@@ -19,17 +19,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.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"))
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
||||
module gitlab.com/rawleyifowler/site-rework
|
||||
module github.com/rawleyfowler/rawleydotxyz
|
||||
|
||||
go 1.15
|
||||
|
||||
|
||||
2
main.go
2
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
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 <Page Name>.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" {
|
||||
|
||||
Reference in New Issue
Block a user