html_handlers.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package controller
  2. import (
  3. "net/http"
  4. "git.aetherial.dev/aeth/keiji/pkg/helpers"
  5. "github.com/gin-gonic/gin"
  6. )
  7. // @Name ServePost
  8. // @Summary serves HTML files out of the HTML directory
  9. // @Tags webpages
  10. // @Router /writing/:post-name [get]
  11. func (c *Controller) ServePost(ctx *gin.Context) {
  12. rds := helpers.NewRedisClient(c.RedisConfig)
  13. post, exist := ctx.Params.Get("post-name")
  14. if !exist {
  15. ctx.JSON(404, map[string]string{
  16. "Error": "the requested file could not be found",
  17. })
  18. return
  19. }
  20. doc, err := rds.GetItem(post)
  21. if err != nil {
  22. ctx.JSON(500, map[string]string{
  23. "Error": err.Error(),
  24. })
  25. return
  26. }
  27. if doc.Category == helpers.CONFIGURATION {
  28. ctx.Status(404)
  29. return
  30. }
  31. ctx.HTML(http.StatusOK, "blogpost", gin.H{
  32. "navigation": gin.H{
  33. "menu": c.Menu(),
  34. "headers": c.Headers().Elements,
  35. },
  36. "title": doc.Ident,
  37. "Ident": doc.Ident,
  38. "Created": doc.Created,
  39. "Body": doc.Body,
  40. })
  41. }
  42. // @Name ServeBlogHome
  43. // @Summary serves the HTML file for the blog post homepage
  44. // @Tags webpages
  45. // @Router /blog [get]
  46. func (c *Controller) ServeBlogHome(ctx *gin.Context) {
  47. docs, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
  48. if err != nil {
  49. ctx.JSON(500, map[string]string{
  50. "Error getting docs": err.Error(),
  51. })
  52. return
  53. }
  54. ctx.HTML(http.StatusOK, "home", gin.H{
  55. "navigation": gin.H{
  56. "menu": c.Menu(),
  57. "headers": c.Headers().Elements,
  58. },
  59. "listings": docs,
  60. })
  61. }
  62. // @Name ServeHtml
  63. // @Summary serves HTML files out of the HTML directory
  64. // @Tags webpages
  65. // @Router /home [get]
  66. func (c *Controller) ServeHome(ctx *gin.Context) {
  67. docs, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
  68. if err != nil {
  69. ctx.JSON(500, map[string]string{
  70. "Error getting docs": err.Error(),
  71. })
  72. return
  73. }
  74. ctx.HTML(http.StatusOK, "home", gin.H{
  75. "navigation": gin.H{
  76. "menu": c.Menu(),
  77. "headers": c.Headers().Elements,
  78. },
  79. "listings": docs,
  80. })
  81. }
  82. // @Name ServeCreativeWriting
  83. // @Summary serves the HTML file for the creative writing homepage
  84. // @Tags webpages
  85. // @Router /creative [get]
  86. func (c *Controller) ServeCreativeWriting(ctx *gin.Context) {
  87. docs, err := helpers.GetAllDocuments(helpers.CREATIVE, c.RedisConfig)
  88. if err != nil {
  89. ctx.JSON(500, map[string]string{
  90. "Error getting docs": err.Error(),
  91. })
  92. return
  93. }
  94. ctx.HTML(http.StatusOK, "home", gin.H{
  95. "navigation": gin.H{
  96. "menu": c.Menu(),
  97. "headers": c.Headers().Elements,
  98. },
  99. "listings": docs,
  100. })
  101. }
  102. // @Name ServeTechnicalWriteups
  103. // @Summary serves the HTML file for the technical writeup homepage
  104. // @Tags webpages
  105. // @Router /writeups [get]
  106. func (c *Controller) ServeTechnicalWriteups(ctx *gin.Context) {
  107. docs, err := helpers.GetAllDocuments(helpers.TECHNICAL, c.RedisConfig)
  108. if err != nil {
  109. ctx.JSON(500, map[string]string{
  110. "Error getting docs": err.Error(),
  111. })
  112. return
  113. }
  114. ctx.HTML(http.StatusOK, "home", gin.H{
  115. "navigation": gin.H{
  116. "menu": c.Menu(),
  117. "headers": c.Headers().Elements,
  118. },
  119. "listings": docs,
  120. })
  121. }
  122. // @Name ServeDigitalArt
  123. // @Summary serves the HTML file for the digital art homepage
  124. // @Tags webpages
  125. // @Router /digital [get]
  126. func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
  127. rds := helpers.NewRedisClient(c.RedisConfig)
  128. fnames, err := helpers.GetImageData(rds)
  129. if err != nil {
  130. ctx.HTML(http.StatusInternalServerError, "unhandled_error",
  131. gin.H{
  132. "StatusCode": http.StatusInternalServerError,
  133. "Reason": err.Error(),
  134. },
  135. )
  136. return
  137. }
  138. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  139. "navigation": gin.H{
  140. "menu": c.Menu(),
  141. "headers": c.Headers().Elements,
  142. },
  143. "images": fnames,
  144. })
  145. }