From d97f327f670d881b72f3b818502e29e9fbcb2e6b Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 1 Jan 2020 19:28:08 +0000 Subject: Include the channel news entries within the posts --- src/reader.scm | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/reader.scm b/src/reader.scm index 90d90eb..222a9f9 100644 --- a/src/reader.scm +++ b/src/reader.scm @@ -1,4 +1,5 @@ (define-module (src reader) + #:use-module (srfi srfi-1) #:use-module (srfi srfi-19) #:use-module (ice-9 match) #:use-module (ice-9 regex) @@ -6,6 +7,7 @@ #:use-module (commonmark) #:use-module (haunt reader) #:use-module (haunt post) + #:use-module (sxml simple) #:use-module (src date-utils) #:use-module (src urls) #:export (post-reader @@ -41,6 +43,23 @@ related to Guix, please submit it for the next issue!")) (vector)))) string<=?)) +(define (lookup-news-text target-locale news-entry name type) + (cdr + (xml->sxml + (peek + (any (lambda (locale) + (assoc-ref + (assoc-ref + (assoc-ref news-entry name) + locale) + type)) + (list target-locale + (first (string-split target-locale #\_)) + "en"))) + #:entities '((nbsp . "\xa0") + (hellip . "…"))))) + + ;;; Post reader (define post-reader @@ -79,13 +98,47 @@ related to Guix, please submit it for the next issue!")) (date->string start-date "~1") " to " (date->string end-date "~1"))))))) - (let ((compare-data - (lookup-compare-data-for-week year week))) + (let* ((compare-data + (lookup-compare-data-for-week year week)) + (news + (and=> (assoc-ref compare-data "channel-news") + (lambda (news) + (if (eq? 0 (vector-length news)) + #f + news))))) (append (let ((content (commonmark->sxml port))) (if (null? content) - %placeholder-content - content)) + (if news + `((h3 "News") + ,@(map (lambda (news-entry) + `(div + (h4 + ,(lookup-news-text locale + news-entry + "title-text" + "html")) + ,(peek (lookup-news-text locale + news-entry + "body-text" + "html")))) + (vector->list news))) + %placeholder-content) + `(,@content + ,@(if news + (map (lambda (news-entry) + `(div + (h4 + ,(lookup-news-text locale + news-entry + "title-text" + "html")) + ,(peek (lookup-news-text locale + news-entry + "body-text" + "html")))) + (vector->list news)) + '())))) `((h3 "Package changes") (h4 "New packages") ,@(match (get-compare-data-packages-list compare-data -- cgit v1.2.3