From a27e86a1970b4a43da0af7e17fb9adc48339cf06 Mon Sep 17 00:00:00 2001 From: David Botton Date: Tue, 5 Apr 2022 22:32:28 -0400 Subject: [PATCH] added search engine optimization functionality --- FUTURE.md | 4 ---- source/clog-connection.lisp | 23 ++++++++++++++++------- source/clog-system.lisp | 7 ++++++- static-files/boot.html | 2 ++ static-files/bootstrap.html | 2 ++ static-files/debug.html | 2 ++ templates/www/www/boot.html | 2 ++ templates/www/www/bootstrap.html | 2 ++ tutorial/12-tutorial.lisp | 31 +++++++++++++++++++++++-------- 9 files changed, 55 insertions(+), 20 deletions(-) diff --git a/FUTURE.md b/FUTURE.md index d6bd0c2..a88187a 100644 --- a/FUTURE.md +++ b/FUTURE.md @@ -24,10 +24,6 @@ Demo between different models - stateless, webpage, windows - Training and documentation tool -- Implement using long polling to optimize CLOG sites for use with - search engines. If not long polling at least initial output sent by - initial html request until first query. - - Optionaly, for local apps, allow direct transport of CLOG data to webpage via apis remove need for websocket transport. diff --git a/source/clog-connection.lisp b/source/clog-connection.lisp index 608bc89..60fa980 100644 --- a/source/clog-connection.lisp +++ b/source/clog-connection.lisp @@ -304,15 +304,19 @@ the default answer. (Private)" (host "0.0.0.0") (port 8080) (boot-file "/boot.html") + (boot-function nil) (static-boot-js nil) (static-root #P"./static-files/")) - "Initialize CLOG on a socket using HOST and PORT to serve BOOT-FILE as -the default route for '/' to establish web-socket connections and static files -located at STATIC-ROOT. If BOOT-FILE is nil no initial clog-path's will be -setup, use clog-path to add. The on-connect-handler needs to indentify the -path by querying the browser. See PATH-NAME (in CLOG-LOCATION). If -static-boot-js is nil then boot.js is served from the file /js/boot.js -instead of the compiled version." + "Initialize CLOG on a socket using HOST and PORT to serve BOOT-FILE +as the default route for '/' to establish web-socket connections and +static files located at STATIC-ROOT. If BOOT-FILE is nil no initial +clog-path's will be setup, use clog-path to add. The +on-connect-handler needs to indentify the path by querying the +browser. See PATH-NAME (in CLOG-LOCATION). If static-boot-js is nil +then boot.js is served from the file /js/boot.js instead of the +compiled version. boot-function if set is called with the url and the +contents of boot-file and its return value replaces the contents sent +to the brower." (set-on-connect on-connect-handler) (when boot-file (set-clog-path "/" boot-file)) @@ -338,6 +342,10 @@ instead of the compiled version." (let ((page-data (make-string (file-length stream))) (post-data)) (read-sequence page-data stream) + (when boot-function + (setf page-data (funcall boot-function + (getf env :path-info) + page-data))) (when (search "multipart/form-data;" (getf env :content-type)) (let ((id (get-universal-time)) @@ -402,6 +410,7 @@ instead of the compiled version." ;;;;;;;;;;;;;;;;;;; (defun set-clog-path (path boot-file) + "Associate URL path to BOOT-FILE" (if boot-file (setf (gethash path *url-to-boot-file*) ;; Make clog-path into a relative path of diff --git a/source/clog-system.lisp b/source/clog-system.lisp index eff4fd4..cfc6056 100644 --- a/source/clog-system.lisp +++ b/source/clog-system.lisp @@ -51,6 +51,7 @@ the same as the clog directy this overides the relative paths used in them.") (host "0.0.0.0") (port 8080) (boot-file "/boot.html") + (boot-function nil) (static-boot-js nil) (static-root (merge-pathnames "./static-files/" (asdf:system-source-directory :clog)))) @@ -64,7 +65,10 @@ is installed in ./static-files\" If the variable clog:*overide-static-root* is set STATIC-ROOT will be ignored. If BOOT-FILE is nil no default boot-file will be set for root path, i.e. /. If static-boot-js is t then boot.js is served from the file /js/boot.js instead of the -compiled version." +compiled version. boot-function if set is called with the url and the +contents of boot-file and its return value replaces the contents sent +to the brower, this allows adding content for search engine optimization, +see tutorial 12 for an example." (when on-new-window-handler (set-on-new-window on-new-window-handler :path "/" :boot-file boot-file)) (unless *clog-running* @@ -76,6 +80,7 @@ compiled version." :host host :port port :boot-file boot-file + :boot-function boot-function :static-boot-js static-boot-js :static-root *static-root*))) diff --git a/static-files/boot.html b/static-files/boot.html index e63f62e..9e19839 100644 --- a/static-files/boot.html +++ b/static-files/boot.html @@ -8,8 +8,10 @@ + + diff --git a/static-files/bootstrap.html b/static-files/bootstrap.html index 910eaca..b84f5fc 100644 --- a/static-files/bootstrap.html +++ b/static-files/bootstrap.html @@ -10,8 +10,10 @@ + + diff --git a/static-files/debug.html b/static-files/debug.html index 100d802..26e6c6f 100644 --- a/static-files/debug.html +++ b/static-files/debug.html @@ -9,8 +9,10 @@ + + diff --git a/templates/www/www/boot.html b/templates/www/www/boot.html index 11a6c21..120ec96 100644 --- a/templates/www/www/boot.html +++ b/templates/www/www/boot.html @@ -8,8 +8,10 @@ + + diff --git a/templates/www/www/bootstrap.html b/templates/www/www/bootstrap.html index 910eaca..b84f5fc 100644 --- a/templates/www/www/bootstrap.html +++ b/templates/www/www/bootstrap.html @@ -10,8 +10,10 @@ + + diff --git a/tutorial/12-tutorial.lisp b/tutorial/12-tutorial.lisp index cc4582b..9db40c7 100644 --- a/tutorial/12-tutorial.lisp +++ b/tutorial/12-tutorial.lisp @@ -48,13 +48,6 @@ (create-div body :content "You are in on-page2") (log-console (window body) "A message in the browser's log")) -(defun on-default (body) - (cond ((equalp (path-name (location body)) - "/tutorial/tut-11.html") - (on-tutorial11 body)) - (t - (create-div body :content "No dice!")))) - (defun on-tutorial11 (body) (let* ((form (attach-as-child body "form1" :clog-type 'clog-form)) (good-button (attach-as-child body "button1id")) @@ -80,9 +73,31 @@ (set-on-click good-button 'on-click-good) (set-on-click scary-button 'on-click-scary)))) +(defun on-default (body) + (cond ((equalp (path-name (location body)) + "/tutorial/tut-11.html") + (on-tutorial11 body)) + (t + (create-div body :content "No dice!")))) + +(defun add-search-optimizations (path content) + ;; The default boot.html that comes with CLOG has template + ;; markers inside of the meta section and body section + ;; that are set to be transparent to the user but show to + ;; search engines and text browser. This allows setting + ;; custom data for search engine optimizations which are + ;; aware of these type of dynamic sites. + (declare (ignore path)) + (funcall (cl-template:compile-template content) + (list :meta "" + :body "Tutorial 12 for CLOG"))) + (defun start-tutorial () "Start turtorial." - (initialize 'on-main) + ;; Setup the default route / to on-main + ;; :boot-function allows us to add or modify our boot-files content + ;; for search engine optimization + (initialize 'on-main :boot-function 'add-search-optimizations) ;; Navigating to http://127.0.0.1:8080/page1 executes on-page1 (set-on-new-window 'on-page1 :path "/page1") ;; Navigating to http://127.0.0.1:8080/page1.html executes on-page1