123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- package controller
- import (
- "fmt"
- "net/http"
- "adeptus-mechanicus.void/git/keiji/pkg/helpers"
- "github.com/gin-gonic/gin"
- )
- // @Name ServePost
- // @Summary serves HTML files out of the HTML directory
- // @Tags webpages
- // @Router /writing/:post-name [get]
- func (c *Controller) ServePost(ctx *gin.Context) {
- rds := helpers.NewRedisClient(c.RedisConfig)
- post, exist := ctx.Params.Get("post-name")
- if !exist {
- ctx.JSON(404, map[string]string{
- "Error": "the requested file could not be found",
- })
- return
- }
- doc, err := rds.GetItem(post)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error": err.Error(),
- })
- return
- }
- if doc.Category == helpers.CONFIGURATION {
- ctx.Status(404)
- return
- }
- ctx.HTML(http.StatusOK, "blogpost", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "title": doc.Ident,
- "Ident": doc.Ident,
- "Created": doc.Created,
- "Body": doc.Body,
- })
- }
- // @Name ServeBlogHome
- // @Summary serves the HTML file for the blog post homepage
- // @Tags webpages
- // @Router /blog [get]
- func (c *Controller) ServeBlogHome(ctx *gin.Context) {
- docs, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error getting docs": err.Error(),
- })
- return
- }
- ctx.HTML(http.StatusOK, "home", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "listings": docs,
- })
- }
- // @Name ServeHtml
- // @Summary serves HTML files out of the HTML directory
- // @Tags webpages
- // @Router /home [get]
- func (c *Controller) ServeHome(ctx *gin.Context) {
- docs, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error getting docs": err.Error(),
- })
- return
- }
- ctx.HTML(http.StatusOK, "home", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "listings": docs,
- })
- }
- // @Name ServeCreativeWriting
- // @Summary serves the HTML file for the creative writing homepage
- // @Tags webpages
- // @Router /creative [get]
- func (c *Controller) ServeCreativeWriting(ctx *gin.Context) {
- docs, err := helpers.GetAllDocuments(helpers.CREATIVE, c.RedisConfig)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error getting docs": err.Error(),
- })
- return
- }
- ctx.HTML(http.StatusOK, "home", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "listings": docs,
- })
- }
- // @Name ServeTechnicalWriteups
- // @Summary serves the HTML file for the technical writeup homepage
- // @Tags webpages
- // @Router /writeups [get]
- func (c *Controller) ServeTechnicalWriteups(ctx *gin.Context) {
- docs, err := helpers.GetAllDocuments(helpers.TECHNICAL, c.RedisConfig)
- if err != nil {
- ctx.JSON(500, map[string]string{
- "Error getting docs": err.Error(),
- })
- return
- }
- ctx.HTML(http.StatusOK, "home", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "listings": docs,
- })
- }
- // @Name ServeDigitalArt
- // @Summary serves the HTML file for the digital art homepage
- // @Tags webpages
- // @Router /digital [get]
- func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
- ctx.HTML(http.StatusOK, "digital_art", gin.H{
- "navigation": gin.H{
- "menu": c.Menu(),
- "headers": c.Headers().Elements,
- },
- "images": []string{
- fmt.Sprintf("/api/v1/images/%s", "keepoff_small.jpg"),
- fmt.Sprintf("/api/v1/images/%s", "someoneatthedoor_small.jpg"),
- fmt.Sprintf("/api/v1/images/%s", "whyhere.gif"),
- },
- })
- }
|