Yu-Gi-Oh! Deck Building and Card Inventory Management web interface written in Common Lisp, utilizing HTMX.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

82 rindas
2.9KB

  1. #|
  2. src/web/index.lisp
  3. Some static top-level routes.
  4. If there isn't much to the page it probably appears here e.g. / /about /news
  5. |#
  6. (in-package :cl-deck-builder2.web)
  7. (defroute index "/" ()
  8. "Main HTML index."
  9. (with-logged-in-user
  10. (render-with-env #P"index.html" `(:active "/"))))
  11. ;; (render-markdown
  12. ;; (relative-pathname "doc/index.md")
  13. ;; :title "Index" :env `(:active "/index"))
  14. (defroute "/about" ()
  15. "About page."
  16. (with-logged-in-user
  17. (render-markdown
  18. (relative-pathname "doc/about.md")
  19. :title "About" :env `(:active "/about"))))
  20. (defroute "/news" ()
  21. "News page. We use parse git log in toolkit/git.lisp."
  22. (with-logged-in-user
  23. (render-with-env #P"news.html"
  24. `(:active "/news"
  25. :git-log ,(mapcar #'parse-git-log (git-log))))))
  26. (defroute ("/todo" :method :GET) ()
  27. "To-Do list page. This is my personal professional todo list!"
  28. (with-logged-in-user
  29. (render-markdown
  30. (asdf:system-relative-pathname :cl-deck-builder2
  31. "doc/todo.md")
  32. :title "To-Do List"
  33. :env `(:active "/todo"))))
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35. (defroute ("/markdown" :method :GET) (&key _parsed)
  36. "A utility URL to parse markdown files.
  37. In a production environment you would probably want to disable this URL, as it could potentially allow an attacker to read arbitrary source files. That isn't a concern since we're running in a Docker container."
  38. (with-logged-in-user
  39. (let* ((path (query-param "path" _parsed))
  40. (pathspec (asdf:system-relative-pathname :cl-deck-builder2 path)))
  41. (alexandria:if-let ((extracted-title (ignore-errors
  42. (car (uiop:read-file-lines pathspec)))))
  43. (render-markdown pathspec :title extracted-title)
  44. (render-with-env #P"markdown.html" (list :title "Oops!" :html "Nothing to see here..."))))))
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46. (defun extract-router-docs (app)
  47. "Courtesy of knobo: https://github.com/fukamachi/caveman/pull/108"
  48. (sort
  49. (mapcar (lambda (route)
  50. (list
  51. (myway.rule::rule-url (myway.route:route-rule route))
  52. (documentation (ningle.route:route-controller route) 'function)
  53. (car (map-set:ms-map 'list 'identity (myway.rule::rule-methods (myway.route:route-rule route))))
  54. (myway.rule::rule-param-keys (myway.route:route-rule route))))
  55. (myway:mapper-routes (ningle.app::mapper app)))
  56. #'string<
  57. :key #'car))
  58. (defroute doc "/doc" (&key |org|)
  59. "This url shows this the documentation."
  60. (with-logged-in-user
  61. (let ((docs (extract-router-docs *web*))
  62. (tpl (if |org|
  63. #P"docs.md"
  64. #P"docs.html")))
  65. (render-with-env tpl
  66. `(:active "/doc"
  67. :docs ,docs)))))