html_handlers.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. ctx.HTML(http.StatusOK, "home", gin.H{
  48. "navigation": gin.H{
  49. "headers": c.database.GetNavBarLinks(),
  50. },
  51. "menu": c.database.GetDropdownElements(),
  52. "listings": c.database.GetByCategory(helpers.BLOG),
  53. })
  54. }
  55. // @Name ServeBlog
  56. // @Summary serves the HTML for written post listings
  57. // @Tags webpages
  58. // @Router /blog [get]
  59. func (c *Controller) ServeBlog(ctx *gin.Context) {
  60. ctx.HTML(http.StatusOK, "writing", c.database.GetByCategory(helpers.BLOG))
  61. }
  62. // @Name ServeDigitalArt
  63. // @Summary serves the HTML file for the digital art homepage
  64. // @Tags webpages
  65. // @Router /digital [get]
  66. func (c *Controller) ServeDigitalArt(ctx *gin.Context) {
  67. images := c.database.GetAllImages()
  68. /*
  69. if err != nil {
  70. ctx.HTML(http.StatusInternalServerError, "unhandled_error",
  71. gin.H{
  72. "StatusCode": http.StatusInternalServerError,
  73. "Reason": err.Error(),
  74. },
  75. )
  76. return
  77. }
  78. */
  79. ctx.HTML(http.StatusOK, "digital_art", gin.H{
  80. "navigation": gin.H{
  81. "headers": c.database.GetNavBarLinks(),
  82. },
  83. "images": images,
  84. "menu": c.database.GetDropdownElements(),
  85. })
  86. }