DATARAMA

Allow keeping dead links

June 05, 2016
Project: plutonium

This revision adds a keepdead vwcode, which will allow rendering of links to nonexistent pages. This is generally a bad idea, but it's useful for the frontpage.

1 files changed, 11 insertions / 9 deletions

diff --git a/plutonium.scm b/plutonium.scm
index aec410a..a0a673d 100755
--- a/plutonium.scm
+++ b/plutonium.scm
@@ -153,7 +153,7 @@
     (lambda (x)
       (let ((link (irregex-match-substring x 'link))
             (desc (irregex-match-substring x 'desc)))
-        (if (dead-wikilink? link) 
+        (if (and (not (keep-dead-links? txt)) (dead-wikilink? link) )
           desc
           (string-append "[" desc "](" (uri-encode-string link) ".html)"))))))
 
@@ -163,10 +163,10 @@
     txt
     (lambda (x) 
       (let ((link (irregex-match-substring x 'link)))
-        (if (dead-wikilink? link)
+        (if (and (not (keep-dead-links? txt)) (dead-wikilink? link))
           link
           (string-append "<a href=\"" (uri-encode-string link) ".html\""
-          (if (link-rating link)
+          (if (and (not (dead-wikilink? link)) (link-rating link))
             (string-append " class=star" (number->string (link-rating link)))
             "")
           ">" link "</a>"))))))
@@ -194,13 +194,14 @@
                  feed))))))
 
 (define (preprocess txt)
-  (replace-wikilinks (strip-vwcodes (vw-insert-recent txt))))
+  (strip-vwcodes (replace-wikilinks (vw-insert-recent txt))))
 
 ; == Data Extractors ==========================================================
 (define (render? file)
   (not (read-vwcode "%nohtml" (read-all file))))
 
 (define (nodropcap? txt) (read-vwcode "%nodropcap" txt))
+(define (keep-dead-links? txt) (read-vwcode "%keepdead" txt))
 
 (define (exclude? element content)
   (read-vwcode (string-append "%no" (symbol->string element)) content))
@@ -380,11 +381,12 @@
   `(h2 (@ (id "page_subtitle")) ,ELEMENT))
 
 (page-element content
-  (if (nodropcap? TEXT)
-    (markdown->sxml (preprocess TEXT))
-    (let* ((vwwords (read-vwcode "%capwords" TEXT))
-           (num-words (if vwwords (string->number vwwords) 1)))
-    (mkdropcap  num-words (markdown->sxml (preprocess TEXT)))))
+  (let ((pcontent (markdown->sxml (preprocess TEXT))))
+    (if (nodropcap? TEXT)
+      pcontent
+      (let* ((vwwords (read-vwcode "%capwords" TEXT))
+             (num-words (if vwwords (string->number vwwords) 1)))
+      (mkdropcap num-words pcontent))))
   ELEMENT)
 
 (page-element image 
 
Powered by Plutonium