newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Rexy-Craxy on September 24, 2011, 02:36:56 AM

Title: Some additions to newLISP Wiki
Post by: Rexy-Craxy on September 24, 2011, 02:36:56 AM
Hi all.



I've added "classical" tags support functions to the newLISP Wiki /CMS (//http) v.4.6. Also I've changed its "get-pages" function to work right with non-English locales. Where should/can I post the patch?



Thanks in advance & sorry for poor English.
Title: Re: Some additions to newLISP Wiki
Post by: cormullion on September 24, 2011, 07:12:27 AM
Hi. You could probably post the patch here - I've seen patches posted before (e.g. by Kosh) but if it's too long, I don't know - email it to Lutz, I suppose. There's no github or anything for newLISP... :)
Title: Re: Some additions to newLISP Wiki
Post by: rickyboy on September 24, 2011, 09:43:05 AM
Quote from: "cormullion"There's no github or anything for newLISP... :)

GADFLY!!!  ;-)
Title: Re: Some additions to newLISP Wiki
Post by: Lutz on September 24, 2011, 10:54:07 AM
C'mon folks , no offense ;), but how much of a barrier is it, to zip or tar up a file and email it? Or even just post the changed and added functions or the patch on the forum, and everybody can see it and comment on it tooo. The whole wiki/index.cgi thing is only ~ 60K, zipped up, in an email about 12K.



A Github account/site is just another piece of infrastructure to maintain make updates etc., and another third party gate, where you have to walk through to get to what you want. Complete overkill for the amount of contributions I have to handle.



Ps: but if anybody wants to start a Github account for it, go ahead ... and maintain it.
Title: Re: Some additions to newLISP Wiki
Post by: cormullion on September 24, 2011, 12:48:47 PM
Quote from: "rickyboy"
Quote from: "cormullion"There's no github or anything for newLISP... :)

GADFLY!!!  ;-)


...Innocent smile ... :)
Title: The patch
Post by: Rexy-Craxy on September 25, 2011, 01:35:07 AM
*** index.cgi.ORIG 2011-09-24 13:14:44.000000000 +0700
--- index.cgi 2011-09-25 15:17:43.000000000 +0700
***************
*** 395,400 ****
--- 395,406 ----
          (replace {[include:.*]} (format-page content) " " 512))
  )
 
+
+ ;; create tagsearch links
+ (define (make-tagsearch tagstr, taglst)
+   (when (setq taglst (map trim (parse tagstr ",")))
+ (join (map (fn (s) (string {<a href="index.cgi?tagsearch=} s {">} s {</a>})) taglst) ", ")))
+
  ;; format a line
  (define (format-line str)
 
***************
*** 449,454 ****
--- 455,463 ----
      ;; don't show post option
      (replace {[post:.*]} str "" 512)
 
+     ;;; create tag links
+     (replace {[tags:(.*)]} str (string "Tags: " (make-tagsearch $1)) 512)
+
      ;; system variable with page title
      (replace "%this%" str page-name)
 
***************
*** 683,691 ****
     
  ;; return a list of all pages
  (define (get-pages , files)
!     (set 'files (slice (directory "pages/") 2))
!     (replace ".htaccess" files)
!     (replace "setup.lsp" files))
 
  ;; resturn a list of all backup files
  (define (get-backup , files)
--- 692,698 ----
     
  ;; return a list of all pages
  (define (get-pages , files)
!     (difference (directory "pages/") '("." ".." ".htaccess" "setup.lsp")))
 
  ;; resturn a list of all backup files
  (define (get-backup , files)
***************
*** 1441,1447 ****
                    {<td>&nbsp;} (first fle)  
                    {&nbsp;</td></tr>}) files))
 
!         (if (empty? file-list)
              (set 'result-text (string "Not found in " no-files " files.<br>"))
              (set 'result-text (append
              {<br><small><font style="color:#888;">found }
--- 1448,1454 ----
                    {<td>&nbsp;} (first fle)  
                    {&nbsp;</td></tr>}) files))
 
!         (if (empty? file-list)
              (set 'result-text (string "Not found in " no-files " files.<br>"))
              (set 'result-text (append
              {<br><small><font style="color:#888;">found }
***************
*** 1458,1463 ****
--- 1465,1509 ----
          (exit)))
 
 
+ ;; request for tag search
+ (if (CGI:get "tagsearch")
+     (begin
+       (set 'tag (CGI:get "tagsearch"))
+       (setf show-home (fn () (display-page "Home") (exit)))
+       (if (null? tag)
+  (show-home)
+  (begin
+    (setf match-tag? (fn (pg)
+       (let ((file (open (string "pages/" pg) "r")) (tagstr ""))
+ (when file
+       (and (search file {[tags:(.*)]} true 512) (setq tagstr $1))
+       (close file))
+ (find tag (map trim (parse tagstr ","))))))
+    (set 'file-list (filter match-tag? (get-pages)))
+    (set 'no-files (length file-list))
+    (set 'files '("</table>"))
+    (dolist (fle (sort file-list >))
+    (push (string
+   "<tr><td> &nbsp;<a href="index.cgi?page="
+   fle "">" (replace "_" fle " ") "</a>&nbsp;</td></tr>")
+  files))
+
+             (if (empty? file-list)
+ (set 'result-text "Not found.<br>")
+ (set 'result-text (append
+   "<br><small><font style="color:#888;">found "
+   (string no-files) { files</font></small>})))
+    (if (not (empty? file-list))
+ (push "<tr><th>&nbsp;Page</th></tr>" files))
+    
+    (push {<table style="border-width: 0px;">} files)
+    (set 'body (append (join files "rn") result-text))
+    (set 'page-name (string "Pages tagged with "" tag """))
+    (CGI:put-page SETUP:template)
+    (exit)))))
+
+
+
  ;; request to show the first page with pattern in content
  ;; mainly used to find posts/comments by author post-time pattern
  (if (CGI:get "find")
***************
*** 1486,1490 ****
--- 1532,1542 ----
 
  (exit)
 
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;; Local Variables:     ;;
+ ;; mode:newlisp         ;;
+ ;; coding: utf-8-unix   ;;
+ ;; End:                 ;;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;
 
  ;; eof


Some comments.



1. "get-pages" changed because on my system "directory" might return "." and ".." NOT at first positions.



2. Wiki tags markup:
Quote[tags: comma-separated-strings]

Example: [tags: person, 1980s, miners strikes]
Note: don't use multiple "[tags: ...]" tags on a single a page, because tag search function matches/uses only the 1st occurrence in the file.
Title: TOC + rename + tags patch
Post by: Rexy-Craxy on September 25, 2011, 06:13:23 AM
A better patch to be applied to the straight 4.6 wiki. Adds TOC and rename features (//http://www.tprimke.net/public/toc_rename.patch) as well as wiki tags. Now "Tags: ..." section is a separate html "<div>" with class="toc".
Title: Re: Some additions to newLISP Wiki
Post by: Lutz on September 26, 2011, 08:04:33 AM
Thank you very much for updating these great additions. I have updated this page:



http://www.newlisp.org/index.cgi?Applications



It would be great to also have these features documented on the "How To Use Advanced Features" page. When that is done, I would include your patch into a new v.4.7 as a standard download.



Applying the patch, I got a little error for the syle sheet:


~/Sites/wiki> patch -p0 < ~/patch
patching file ./index.cgi
patching file ./pages/Default_Style
Hunk #1 FAILED at 215.
1 out of 1 hunk FAILED -- saving rejects to file ./pages/Default_Style.rej
~/Sites/wiki>


seems to be trivial, but perhaps there is a way to avoid it. Perhaps, if you post the entire index.cgi and Default_Style at http://www.tprimke.net, people don't run into the same issue. You could also use Github or Bitbucket for these files.
Title: Re: Some additions to newLISP Wiki
Post by: Rexy-Craxy on September 28, 2011, 02:21:22 AM
Lutz, I'm posting index.cgi and DefaultStyle right here, hope you don't mind :)



About documenting the feature: I had no English practice for last few years, so I'm afraid the text would be really Pidgin, not English :-/ But I'll try, in few days, and then will put the wiki page here.
Title: Re: Some additions to newLISP Wiki
Post by: Lutz on September 28, 2011, 10:41:30 AM
Thanks, there is also a link to it here: http://www.newlisp.org/index.cgi?Applications