html_handlers.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package controller
  2. import (
  3. "fmt"
  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. "menu": c.Menu(),
  35. "headers": c.Headers().Elements,
  36. },
  37. "title": doc.Ident,
  38. "Ident": doc.Ident,
  39. "Created": doc.Created,
  40. "Body": doc.Body,
  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. "menu": c.Menu(),
  58. "headers": c.Headers().Elements,
  59. },
  60. "listings": docs,
  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. "menu": c.Menu(),
  78. "headers": c.Headers().Elements,
  79. },
  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. "menu": c.Menu(),
  98. "headers": c.Headers().Elements,
  99. },
  100. "listings": docs,
  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. "menu": c.Menu(),
  118. "headers": c.Headers().Elements,
  119. },
  120. "listings": docs,
  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. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  129. "navigation": gin.H{
  130. "menu": c.Menu(),
  131. "headers": c.Headers().Elements,
  132. },
  133. "images": []string{
  134. fmt.Sprintf("/api/v1/images/%s", "keepoff_small.jpg"),
  135. fmt.Sprintf("/api/v1/images/%s", "someoneatthedoor_small.jpg"),
  136. fmt.Sprintf("/api/v1/images/%s", "whyhere.gif"),
  137. },
  138. })
  139. }