DATARAMA

Add new goon integration

May 02, 2016
Project: plutonium

This revision adds project pages that can automatically render download information and commit activity, using data from Goon. Goon also provides filetree snapshots, but they aren't used in Plutonium (yet?).

1 files changed, 57 insertions / 2 deletions

diff --git a/plutonium.scm b/plutonium.scm
index 7e794fb..2378c95 100755
--- a/plutonium.scm
+++ b/plutonium.scm
@@ -23,6 +23,8 @@
 (define date-format/html "~B ~e, ~Y")
 (define date-format/front "~b ~d ~Y")
 (define template-path "template/page.scm")
+(define goon-path "goon/")
+(define goon-clone-prefix "git://datarama.dk/")
 (define front-feed-size 4)
 (define extension "pu")
 (define default-lang "en")
@@ -35,6 +37,7 @@
 (define ramap '())
 (define extractors '())
 (define html-formatters '())
+(define project-pages '())
 (define elements '())
 
 (define (new-extractor! name func)
@@ -54,6 +57,12 @@
          (new-extractor! ',name (lambda (NAME TEXT VWCODE) ,extract))
          (new-formatter! ',name (lambda (ELEMENT) ,format)))))))
 
+; == Utility functions ==
+(define (clamp-list lst size)
+    (if (> (length lst) size)
+          (take lst size)
+              lst))
+
 ; == Page Titles ==============================================================
 (define (extract-title name txt)
   (or (read-vwcode "%title" txt) name))
@@ -394,6 +403,49 @@
   VWCODE
   (render-metadata "author" ELEMENT))
 
+; == Goon integration =========================================================
+(define (seconds->dstring timestamp)
+  (date->string (seconds->date timestamp) date-format/front))
+
+(define (goon-manifest-path proj)
+  (filepath:combine
+    goon-path
+    (string-append proj "-master.goon")))
+
+(define (goon-manifest path)
+  (read (open-input-file path)))
+
+(define (goon-commits manifest) (car manifest))
+(define (goon-tags manifest) (cadr manifest))
+(define (goon-filetree manifest) (caddr manifest))
+(define (goon-tag-link tag)
+  `(li  (span (@ (class "desc")) "Release (" (span (@ (class "date")) ,(seconds->dstring (cadr tag))) ")")
+     (span (@ (class "link")) (a (@ (href ,(string-append "/projects/" (caddr tag))))
+     ,(caddr tag)))))
+
+(define (goon-commit-link name commit)
+  `(li
+     (a (@ (href ,(string-append "projects/" name "/" (car commit))))
+        ,(caddr commit))
+     (span (@ (class "date")) ,(seconds->dstring (cadr commit)))))
+
+(page-element project
+  VWCODE
+  (let* ((manifest (goon-manifest (goon-manifest-path ELEMENT))))
+    `(div (@ (id "project-info"))
+       (h1 "Download")
+       (ul  (@ (class "download"))
+         ,(goon-tag-link (car (goon-tags manifest)))
+         (li (span (@ (class "desc")) "Development") 
+             (span (@ (class "link")) ,(filepath:combine goon-clone-prefix ELEMENT))))
+        (h1 "Latest Activity")
+        (ul (@ (class "commitlist"))
+          ,(map (lambda (x) (goon-commit-link ELEMENT x))
+                (clamp-list (goon-commits manifest) 8)))
+        (div (@ (class "histlink")) 
+              (a (@ (href ,(string-append "projects/" ELEMENT "/master-commits.html")))
+           "History →")))))
+
 (page-element pageclass
   (string-append "page_" (irregex-replace 
                            "[^a-zA-Z0-9]" 
@@ -418,7 +470,11 @@
 (page-element related
   (and (assoc NAME ramap) (sort (cdr (assoc NAME ramap)) string<?))
   (render-metadata "related"
-    (and (not (null? ELEMENT)) `(ul ,(map rel->link ELEMENT)))))
+    (if (not (null? ELEMENT))
+      `(div (@ (id "rels"))
+         (h2 "See Also")
+           `(ul ,(map rel->link ELEMENT)))
+      '())))
 
 (define (focuslink lnk)
   `(li
@@ -514,7 +570,6 @@
             (append (removed-links (filepath:take-base-name input-file))
                     (new-links (filepath:take-base-name input-file)))
             input-dir output-dir))
-
         (regenerate-from-map (new-entries) ramap input-dir output-dir)
         (regenerate-from-map (deleted-entries) amap-old input-dir output-dir)
         (regenerate-from-map (deleted-entries) ramap-old input-dir output-dir)
 
Powered by Plutonium