;; Demonstrates clog-web-site from clog-web instant websites (defpackage #:clog-tut-30 (:use #:cl #:clog #:clog-web) (:export start-tutorial)) (in-package :clog-tut-30) ;; Site setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;l;; (defun init-site (body) (clog-web-initialize body) (create-web-site body :settings '(:menu-class "w3-black") :title "CLOG - The Common Lisp Omnificent GUI" :footer "(c) 2022 David Botton" :logo "/img/clog-liz.png")) ;; This is the menu structure (defparameter *menu* `(("Content" (("Home" "/") ("Content from Lambda" "/lambda") ("Content from File" "/readme"))) ("Help" (("About" "/about"))))) ;; Page handlers ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; / - a simple content string (defun on-main (body) ;; We call init-site on every page to load our theme and settings (init-site body) (create-web-page body :main `(:menu ,*menu* :content "Welcome to tutorial 30

Any HTML works!"))) ;; /readme - get content from a text file (defun on-readme (body) (init-site body) (let ((readme (alexandria:read-file-into-string (format nil "~A~A" (asdf:system-source-directory :clog) "README.md")))) (create-web-page body :main `(:menu ,*menu* :content ,(format nil "

~A
" readme))))) ;; /lambda - use a function to output to the page content (defun on-lambda (body) (init-site body) (create-web-page body :main `(:menu ,*menu* :content ,(lambda (obj) (create-div obj :content "I am in the content area"))))) ;; /about (defun on-about (body) (init-site body) (create-web-page body :main `(:menu ,*menu* :content "About Me"))) ;; Start the webserver (defun start-tutorial () ;; Initialize CLOG and the / url path (initialize 'on-main ;; Use long polling technique so pages are crawled by google :long-poll-first t ;; Supply so meta info :boot-function (clog-web-meta "clogpower.com - CLOG - the common lisp omnificent gui")) ;; Setup additional paths (set-on-new-window 'on-about :path "/about") (set-on-new-window 'on-lambda :path "/lambda") (set-on-new-window 'on-readme :path "/readme") (open-browser))