html_handlers.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/:id [get]
  12. func (c *Controller) ServePost(ctx *gin.Context) {
  13. post, exist := ctx.Params.Get("id")
  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 := c.database.GetDocument(helpers.Identifier(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. "headers": c.database.GetNavBarLinks(),
  34. },
  35. "Title": doc.Title,
  36. "Ident": doc.Ident,
  37. "Created": doc.Created,
  38. "Body": template.HTML(helpers.MdToHTML([]byte(doc.Body))),
  39. "menu": c.database.GetDropdownElements(),
  40. })
  41. }
  42. // @Name ServeBlogHome
  43. // @Summary serves the HTML file for the blog post homepage
  44. // @Tags webpages
  45. // @Router / [get]
  46. func (c *Controller) ServeHome(ctx *gin.Context) {
  47. home := c.database.GetByCategory(helpers.HOMEPAGE)
  48. var content helpers.Document
  49. if len(home) == 0 {
  50. content = helpers.Document{
  51. Body: "Under construction. Sry :(",
  52. }
  53. } else {
  54. content = home[0]
  55. }
  56. ctx.HTML(http.StatusOK, "home", gin.H{
  57. "navigation": gin.H{
  58. "headers": c.database.GetNavBarLinks(),
  59. },
  60. "menu": c.database.GetDropdownElements(),
  61. "default": content,
  62. })
  63. }
  64. // @Name ServeBlog
  65. // @Summary serves the HTML for written post listings
  66. // @Tags webpages
  67. // @Router /blog [get]
  68. func (c *Controller) ServeBlog(ctx *gin.Context) {
  69. ctx.HTML(http.StatusOK, "writing", c.database.GetByCategory(helpers.BLOG))
  70. }
  71. // @Name ServeCreative
  72. // @Summary serves the HTML for the creative writing listings
  73. // @Tags webpages
  74. // @Router /creative [get]
  75. func (c *Controller) ServeCreative(ctx *gin.Context) {
  76. ctx.HTML(http.StatusOK, "writing", c.database.GetByCategory(helpers.CREATIVE))
  77. }
  78. // @Name ServeDigitalArt
  79. // @Summary serves the HTML file for the digital art homepage
  80. // @Tags webpages
  81. // @Router /digital [get]
  82. func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
  83. images := c.database.GetAllImages()
  84. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  85. "navigation": gin.H{
  86. "headers": c.database.GetNavBarLinks(),
  87. },
  88. "images": images,
  89. "menu": c.database.GetDropdownElements(),
  90. })
  91. }