package controller import ( "html/template" "net/http" "git.aetherial.dev/aeth/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{ "headers": c.Headers().Elements, }, "title": doc.Ident, "Ident": doc.Ident, "Created": doc.Created, "Body": template.HTML(helpers.MdToHTML([]byte(doc.Body))), "menu": c.Menu(), }) } // @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{ "headers": c.Headers().Elements, }, "listings": docs, "menu": c.Menu(), }) } // @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{ "headers": c.Headers().Elements, }, "menu": c.Menu(), "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{ "headers": c.Headers().Elements, }, "listings": docs, "menu": c.Menu(), }) } // @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{ "headers": c.Headers().Elements, }, "listings": docs, "menu": c.Menu(), }) } // @Name ServeDigitalArt // @Summary serves the HTML file for the digital art homepage // @Tags webpages // @Router /digital [get] func (c *Controller) ServeDigitalArt(ctx *gin.Context) { rds := helpers.NewRedisClient(c.RedisConfig) fnames, err := helpers.GetImageData(rds) if err != nil { ctx.HTML(http.StatusInternalServerError, "unhandled_error", gin.H{ "StatusCode": http.StatusInternalServerError, "Reason": err.Error(), }, ) return } ctx.HTML(http.StatusOK, "digital_art", gin.H{ "navigation": gin.H{ "headers": c.Headers().Elements, }, "images": fnames, "menu": c.Menu(), }) }