html_handlers.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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.Headers().Elements,
  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.Menu(),
  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, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
  49. if err != nil {
  50. ctx.JSON(500, map[string]string{
  51. "Error getting docs": err.Error(),
  52. })
  53. return
  54. }
  55. ctx.HTML(http.StatusOK, "home", gin.H{
  56. "navigation": gin.H{
  57. "headers": c.Headers().Elements,
  58. },
  59. "listings": docs,
  60. "menu": c.Menu(),
  61. })
  62. }
  63. // @Name ServeHtml
  64. // @Summary serves HTML files out of the HTML directory
  65. // @Tags webpages
  66. // @Router /home [get]
  67. func (c *Controller) ServeHome(ctx *gin.Context) {
  68. docs, err := helpers.GetAllDocuments(helpers.BLOG, c.RedisConfig)
  69. if err != nil {
  70. ctx.JSON(500, map[string]string{
  71. "Error getting docs": err.Error(),
  72. })
  73. return
  74. }
  75. ctx.HTML(http.StatusOK, "home", gin.H{
  76. "navigation": gin.H{
  77. "headers": c.Headers().Elements,
  78. },
  79. "menu": c.Menu(),
  80. "listings": docs,
  81. })
  82. }
  83. // @Name ServeCreativeWriting
  84. // @Summary serves the HTML file for the creative writing homepage
  85. // @Tags webpages
  86. // @Router /creative [get]
  87. func (c *Controller) ServeCreativeWriting(ctx *gin.Context) {
  88. docs, err := helpers.GetAllDocuments(helpers.CREATIVE, c.RedisConfig)
  89. if err != nil {
  90. ctx.JSON(500, map[string]string{
  91. "Error getting docs": err.Error(),
  92. })
  93. return
  94. }
  95. ctx.HTML(http.StatusOK, "home", gin.H{
  96. "navigation": gin.H{
  97. "headers": c.Headers().Elements,
  98. },
  99. "listings": docs,
  100. "menu": c.Menu(),
  101. })
  102. }
  103. // @Name ServeTechnicalWriteups
  104. // @Summary serves the HTML file for the technical writeup homepage
  105. // @Tags webpages
  106. // @Router /writeups [get]
  107. func (c *Controller) ServeTechnicalWriteups(ctx *gin.Context) {
  108. docs, err := helpers.GetAllDocuments(helpers.TECHNICAL, c.RedisConfig)
  109. if err != nil {
  110. ctx.JSON(500, map[string]string{
  111. "Error getting docs": err.Error(),
  112. })
  113. return
  114. }
  115. ctx.HTML(http.StatusOK, "home", gin.H{
  116. "navigation": gin.H{
  117. "headers": c.Headers().Elements,
  118. },
  119. "listings": docs,
  120. "menu": c.Menu(),
  121. })
  122. }
  123. // @Name ServeDigitalArt
  124. // @Summary serves the HTML file for the digital art homepage
  125. // @Tags webpages
  126. // @Router /digital [get]
  127. func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
  128. rds := helpers.NewRedisClient(c.RedisConfig)
  129. fnames, err := helpers.GetImageData(rds)
  130. if err != nil {
  131. ctx.HTML(http.StatusInternalServerError, "unhandled_error",
  132. gin.H{
  133. "StatusCode": http.StatusInternalServerError,
  134. "Reason": err.Error(),
  135. },
  136. )
  137. return
  138. }
  139. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  140. "navigation": gin.H{
  141. "headers": c.Headers().Elements,
  142. },
  143. "images": fnames,
  144. "menu": c.Menu(),
  145. })
  146. }