html_handlers.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package controller
  2. import (
  3. "html/template"
  4. "net/http"
  5. "git.aetherial.dev/aeth/keiji/pkg/helpers"
  6. "github.com/gin-gonic/gin"
  7. )
  8. // @Name ServePost
  9. // @Summary serves HTML files out of the HTML directory
  10. // @Tags webpages
  11. // @Router /writing/:post-name [get]
  12. func (c *Controller) ServePost(ctx *gin.Context) {
  13. rds := helpers.NewRedisClient(c.RedisConfig)
  14. post, exist := ctx.Params.Get("post-name")
  15. if !exist {
  16. ctx.JSON(404, map[string]string{
  17. "Error": "the requested file could not be found",
  18. })
  19. return
  20. }
  21. doc, err := rds.GetItem(post)
  22. if err != nil {
  23. ctx.JSON(500, map[string]string{
  24. "Error": err.Error(),
  25. })
  26. return
  27. }
  28. if doc.Category == helpers.CONFIGURATION {
  29. ctx.Status(404)
  30. return
  31. }
  32. ctx.HTML(http.StatusOK, "blogpost", gin.H{
  33. "navigation": gin.H{
  34. "headers": c.database.GetNavBarLinks(),
  35. },
  36. "title": doc.Ident,
  37. "Ident": doc.Ident,
  38. "Created": doc.Created,
  39. "Body": template.HTML(helpers.MdToHTML([]byte(doc.Body))),
  40. "menu": c.database.GetDropdownElements(),
  41. })
  42. }
  43. // @Name ServeBlogHome
  44. // @Summary serves the HTML file for the blog post homepage
  45. // @Tags webpages
  46. // @Router /blog [get]
  47. func (c *Controller) ServeBlogHome(ctx *gin.Context) {
  48. docs := c.database.GetByCategory(helpers.BLOG)
  49. ctx.HTML(http.StatusOK, "home", gin.H{
  50. "navigation": gin.H{
  51. "headers": c.database.GetNavBarLinks(),
  52. },
  53. "listings": docs,
  54. "menu": c.database.GetDropdownElements(),
  55. })
  56. }
  57. // @Name ServeDigitalArt
  58. // @Summary serves the HTML file for the digital art homepage
  59. // @Tags webpages
  60. // @Router /digital [get]
  61. func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
  62. rds := helpers.NewRedisClient(c.RedisConfig)
  63. fnames, err := helpers.GetImageData(rds)
  64. if err != nil {
  65. ctx.HTML(http.StatusInternalServerError, "unhandled_error",
  66. gin.H{
  67. "StatusCode": http.StatusInternalServerError,
  68. "Reason": err.Error(),
  69. },
  70. )
  71. return
  72. }
  73. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  74. "navigation": gin.H{
  75. "headers": c.database.GetNavBarLinks(),
  76. },
  77. "images": fnames,
  78. "menu": c.database.GetDropdownElements(),
  79. })
  80. }