changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > core / lisp/lib/web/index.lisp

changeset 698: 96958d3eb5b0
parent: 4d8451fe5423
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 04 Oct 2024 22:04:59 -0400
permissions: -rw-r--r--
description: fixes
1 ;;; web/index.lisp --- local user index
2 
3 ;;; Code:
4 (uiop:define-package :web/index
5  (:use :cl :std :hunchentoot :lass :spinneret)
6  (:export
7  :main
8  :*web-index-port*))
9 
10 (in-package :web/index)
11 
12 (defparameter *last-update* (get-universal-time))
13 
14 (defun current-time () (setq *last-update* (get-universal-time)))
15 
16 (defparameter *web-index-port* 8888)
17 
18 (defparameter *server*
19  (make-instance 'easy-acceptor
20  :port 8888
21  :name "index"))
22 
23 (define-easy-handler (b :uri "/b") (user)
24  (setf (content-type*) "text/plain")
25  (format nil "showing buffers for ~@[ ~A~]." user))
26 
27 (define-easy-handler (i :uri "/i") (user)
28  (setf (content-type*) "text/plain")
29  (format nil "showing inbox for ~@[ ~A~]." user))
30 
31 (define-easy-handler (a :uri "/a") (user)
32  (setf (content-type*) "text/plain")
33  (format nil "showing agenda for ~@[ ~A~]." user))
34 
35 (define-easy-handler (org :uri "/org") (user)
36  (setf (content-type*) "text/plain")
37  (format nil "showing org-files for ~@[ ~A~]." user))
38 
39 (deftag link (link body)
40  `(:a :href ,@link ,@body))
41 
42 (defmacro with-index-page (&optional (title "local index") &body body)
43  `(with-html
44  (:doctype)
45  (:html
46  (:head
47  (:title ,title)
48  (:body
49  (:div :class "nav"
50  "( "
51  (link "https://compiler.company" "~")
52  (link "https://compiler.company/blog" "blog")
53  (link "https://compiler.company/docs" "docs")
54  (link "https://compiler.company/code" "code")
55  " )")
56  ,@body
57  (:footer ("Last update: ~A" (current-time))))))))
58 
59  (defun tabulate (&rest rows)
60  (with-html
61  (flet ((tabulate ()
62  (loop for row in rows do
63  (:tr (loop for cell in row do
64  (:td cell))))))
65  (if (find :table (get-html-path))
66  (tabulate)
67  (:table (:tbody (tabulate)))))))
68 
69 (defun inner-section ()
70  "Binds *HTML-PATH* to replicate the depth the output is used in."
71  (with-html-string
72  (let ((*html-path* (append *html-path* '(:section :section))))
73  (:h* "Heading three levels deep"))))
74 
75 (defun outer-section (html)
76  "Uses HTML from elsewhere and embed it into a section"
77  (with-html-string
78  (:section
79  (:h* "Heading two levels deep")
80  (:section
81  (:raw html)))))
82 
83 (defun main (&key (output *standard-output*) (port *web-index-port*))
84  (let ((*standard-output* output))
85  (print "starting index server on ~A" port)
86  (start *server*)))
87 
88 (defun shutdown (&optional (target *server*))
89  (stop target))