From 04df19a88a381e6bdc60d7f566e02e99b40c0087 Mon Sep 17 00:00:00 2001 From: Grant Shangreaux Date: Tue, 21 Feb 2023 22:39:29 -0600 Subject: Add: text browser tavern view --- endpoints.lisp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'endpoints.lisp') diff --git a/endpoints.lisp b/endpoints.lisp index af07f6e..4cd9aef 100644 --- a/endpoints.lisp +++ b/endpoints.lisp @@ -49,6 +49,10 @@ NIL if there is no session for the current request. I.e. It should be called within the scope of a request handler." (session-with-id (lzb:request-cookie +session-cookie-name+ ))) +(defun text-browser-p (user-agent) + "Returns T if user agent string matches on a list of known text browsers." + (some (lambda (s) (search s user-agent)) '("Emacs" "Lynx" "w3m"))) + (defmacro with-session ((player &key session (redirect "/tavern-door")) &body body) (let ((session (or session (gensym "SESSION")))) `(a:if-let (,session (current-session)) @@ -57,7 +61,6 @@ I.e. It should be called within the scope of a request handler." ,@body) (redirect-to ,redirect)))) - (defmacro with-checked-plist (typed-keys plist &rest body) "Like WITH-PLIST, but allows you to pass a checking function to automatically tansform plist values into something you actually @@ -126,7 +129,9 @@ functions in url parameters in endpoint definitions." (defendpoint* :get "/tavern" () () (with-session (me) - (tavern me))) + (if (text-browser-p (lzb:request-header :user-agent)) + (tavern-text me) + (tavern me)))) (defendpoint* :get "/godess-shrine" () () (with-session (player) @@ -144,3 +149,4 @@ functions in url parameters in endpoint definitions." (let ((campaign (create-campaign creator title))) (redirect-to (urlpath :details campaign)))))) + -- cgit v1.2.3