From fa23c4d881c0e83b9f0784ae85d4629ac2e879b4 Mon Sep 17 00:00:00 2001 From: David Botton Date: Wed, 21 Sep 2022 22:10:36 -0400 Subject: [PATCH] add url rewrites --- tutorial/27-tutorial.lisp | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/tutorial/27-tutorial.lisp b/tutorial/27-tutorial.lisp index a71d1c3..9baded4 100644 --- a/tutorial/27-tutorial.lisp +++ b/tutorial/27-tutorial.lisp @@ -29,10 +29,24 @@ "windmills.jpg" "yellow-clogs.jpg" "clogicon.png")) - (set-on-change lbox (lambda (obj) - (declare (ignore obj)) - (setf (url-src viewer) (format nil "/img/~A" - (value lbox))))) + (flet ((img-changed (obj) + (declare (ignore obj)) + (let* ((new-img (value lbox)) + (new-src (format nil "/img/~A" new-img)) + (new-url (format nil "~A//~A/?img=~A" + (protocol (location body)) + (host (location body)) + (quri:url-encode new-img)))) + ;; rewrite the url with selected img + (url-rewrite (window body) new-url) + ;; select img + (setf (url-src viewer) new-src)))) + (set-on-change lbox #'img-changed) + ;; On start up check if an image passed in url + (let ((url-img (form-data-item (form-get-data body) "img"))) + (when url-img + (setf (value lbox) url-img) + (img-changed lbox)))) ;; Setup Bottom (center-children (bottom-panel console) :horizontal nil)))