From fe6910a5877ad039e2d6cf95efc10a62c0762871 Mon Sep 17 00:00:00 2001
From: Julien Lepiller <julien@lepiller.eu>
Date: Fri, 9 Oct 2020 00:32:56 +0200
Subject: [PATCH] website: Add community page.

* website/apps/media/templates/community.scm: New file.
* website/apps/media/builder.scm: Add community builder.
* website/apps/base/templates/components.scm: Add it to the menu.
* website/apps/media/templates/components.scm: Add resource->shtml.
* website/apps/media/types.scm: New resource data type.
* website/apps/media/data.scm: Add community resources.
* website/static/base/css/index.css: Add css for new classes.
* website/static/media/css/community.css: New file.
* website/static/media/img/community/carl-dong-bitcoin-security.webp: New file.
---
 website/apps/base/templates/components.scm    |   3 +-
 website/apps/media/builder.scm                |  16 ++++-
 website/apps/media/data.scm                   |  49 ++++++++++++++
 website/apps/media/templates/community.scm    |  34 ++++++++++
 website/apps/media/templates/components.scm   |  24 ++++++-
 website/apps/media/types.scm                  |  63 +++++++++++++++++-
 website/static/base/css/index.css             |  12 ++++
 website/static/media/css/community.css        |  13 ++++
 .../community/carl-dong-bitcoin-security.webp | Bin 0 -> 13952 bytes
 9 files changed, 210 insertions(+), 4 deletions(-)
 create mode 100644 website/apps/media/templates/community.scm
 create mode 100644 website/static/media/css/community.css
 create mode 100644 website/static/media/img/community/carl-dong-bitcoin-security.webp

diff --git a/website/apps/base/templates/components.scm b/website/apps/base/templates/components.scm
index 44d410e..7482503 100644
--- a/website/apps/base/templates/components.scm
+++ b/website/apps/base/templates/components.scm
@@ -413,7 +413,8 @@ manual.
         #:items
         (list
          (C_ "website menu" (menu-item #:label "Videos" #:active-item active-item #:url (guix-url "videos/")))
-         (C_ "website menu" (menu-item #:label "Screenshots" #:active-item active-item #:url (guix-url "screenshots/")))))
+         (C_ "website menu" (menu-item #:label "Screenshots" #:active-item active-item #:url (guix-url "screenshots/")))
+         (C_ "website menu" (menu-item #:label "Community Resources" #:active-item active-item #:url (guix-url "community/")))))
 
       ,(C_ "website menu" (menu-item #:label "Donate" #:active-item active-item #:url (guix-url "donate/")))
 
diff --git a/website/apps/media/builder.scm b/website/apps/media/builder.scm
index 53378e6..c4cb17b 100644
--- a/website/apps/media/builder.scm
+++ b/website/apps/media/builder.scm
@@ -1,11 +1,13 @@
 ;;; GNU Guix web site
 ;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
+;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
 ;;; Initially written by sirgazil who waives all
 ;;; copyright interest on this file.
 
 (define-module (apps media builder)
   #:use-module (apps aux system)
   #:use-module (apps media data)
+  #:use-module (apps media templates community)
   #:use-module (apps media templates screenshot)
   #:use-module (apps media templates screenshots-overview)
   #:use-module (apps media templates video)
@@ -17,6 +19,7 @@
   #:use-module (apps aux web)
   #:use-module (apps media utils)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-19)
   #:export (builder))
 
 
@@ -41,7 +44,8 @@
      A list of page objects that represent the web resources of the
      application. See Haunt <page> objects for more information."
   (flatten
-   (list (screenshots-overview-builder)
+   (list (community-builder)
+         (screenshots-overview-builder)
          (screenshots-builder)
          (videos-builder)
          (video-list-builder))))
@@ -51,6 +55,16 @@
 ;;; Helper builders.
 ;;;
 
+(define (community-builder)
+  "Return a Haunt page representing the community resources page."
+  (make-page "community/index.html"
+             (community-t (sort resources
+                                (lambda (a b)
+                                  (time>=?
+                                    (date->time-utc (resource-date a))
+                                    (date->time-utc (resource-date b))))))
+             sxml->html))
+
 (define (screenshots-builder)
   "Return a list of Haunt pages representing screenshot pages."
   (map
diff --git a/website/apps/media/data.scm b/website/apps/media/data.scm
index 76af25d..89f7a8c 100644
--- a/website/apps/media/data.scm
+++ b/website/apps/media/data.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix web site
 ;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
+;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
 ;;; Initially written by sirgazil who waives all
 ;;; copyright interest on this file.
 
@@ -9,6 +10,7 @@
   #:use-module (apps media types)
   #:use-module (srfi srfi-19)
   #:export (playlists
+            resources
             screenshots))
 
 
@@ -85,6 +87,53 @@ distribution."))
      #:last-updated (string->date "2020-03-28T16:00:00" "~Y-~m-~dT~H:~M:~S")))))
 
 
+(define resources
+  (list
+    (resource
+      #:title (C_ "community resource title" "Everyday use of Guix")
+      #:link "https://media.marusich.info/everyday-use-of-gnu-guix-chris-marusich-seagl-2018.webm"
+      #:type 'video
+      #:language (G_ "English")
+      #:author "Chris Marushich"
+      #:date (string->date "2018-10-10" "~Y-~m-~d"))
+    (resource
+      #:title (C_ "community resource title" "Bitcoin Build System Security")
+      #:link "https://www.youtube.com/watch?v=I2iShmUTEl8"
+      #:type 'video
+      #:language (G_ "English")
+      #:preview (guix-url "static/media/img/community/carl-dong-bitcoin-security.webp")
+      #:author "Carl Dong"
+      #:date (string->date "2019-06-08" "~Y-~m-~d"))
+    (resource
+      #:title (C_ "community resource title" "Reproducible System Administration with GNU Guix")
+      #:link "https://replay.jres.org/videos/watch/c77b3a44-b75f-4c10-9f39-8fb55ae096d7"
+      #:type 'video
+      #:language (G_ "French")
+      #:author "Julien Lepiller"
+      #:date (string->date "2019-12-04" "~Y-~m-~d"))
+    (resource
+      #:title (C_ "community resource title" "Au-delà des conteneurs : environnements logiciels reproductibles avec GNU Guix")
+      #:link "https://webcast.in2p3.fr/video/au-dela-des-conteneurs-environnements-logiciels-reproductibles-avec-gnu-guix-1"
+      #:type 'video
+      #:language (G_ "French")
+      #:author "Ludovic Courtès"
+      #:date (string->date "2019-05-23" "~Y-~m-~d"))
+    (resource
+      #:title (C_ "community resource title" "Code Staging in GNU Guix")
+      #:link "https://arxiv.org/abs/1709.00833"
+      #:type 'article
+      #:language (G_ "English")
+      #:author "Ludovic Courtès"
+      #:date (string->date "2017-09-04" "~Y-~m-~d"))
+    (resource
+      #:title (C_ "community resource title" "Guix: A most advanced operating system")
+      #:link "https://ambrevar.xyz/guix-advance/index.html"
+      #:type 'blog
+      #:language (G_ "English")
+      #:author "Pierre Neidhardt"
+      #:date (string->date "2019-01-14" "~Y-~m-~d"))))
+
+
 (define screenshots
   (list
    (screenshot
diff --git a/website/apps/media/templates/community.scm b/website/apps/media/templates/community.scm
new file mode 100644
index 0000000..6cd51a0
--- /dev/null
+++ b/website/apps/media/templates/community.scm
@@ -0,0 +1,34 @@
+;;; GNU Guix web site
+;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
+;;; Initially written by sirgazil who waives all
+;;; copyright interest on this file.
+
+(define-module (apps media templates community)
+  #:use-module (apps base templates theme)
+  #:use-module (apps base utils)
+  #:use-module (apps i18n)
+  #:use-module (apps media templates components)
+  #:export (community-t))
+
+(define (community-t community-resources)
+  "Return an SHTML page for all COMMUNITY-RESOURCES."
+  (theme
+   #:title (C_ "webpage title" '("Community"))
+   #:description (G_ "Links to resources created by the community")
+   #:keywords
+   (string-split ;TRANSLATORS: |-separated list of webpage keywords
+    (G_ "GNU|Linux|Unix|Free software|Libre software|Operating \
+system|GNU Hurd|GNU Guix package manager|GNU Guile|Guile \
+Scheme|Transactional upgrades|Functional package \
+management|Reproducibility") #\|)
+   #:active-menu-item (C_ "website menu" "Media")
+   #:css (list (guix-url "static/base/css/index.css")
+               (guix-url "static/base/css/item-preview.css")
+               (guix-url "static/media/css/community.css"))
+   #:content
+   `(main
+     (section
+      (@ (class "page"))
+      (div
+       (@ (class "resource-box"))
+       ,@(map resource->shtml community-resources))))))
diff --git a/website/apps/media/templates/components.scm b/website/apps/media/templates/components.scm
index d928d23..85574ee 100644
--- a/website/apps/media/templates/components.scm
+++ b/website/apps/media/templates/components.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix web site
 ;;; Copyright © 2019 Florian Pelz <pelzflorian@pelzflorian.de>
+;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu>
 ;;; Initially written by sirgazil who waives all
 ;;; copyright interest on this file.
 
@@ -14,7 +15,8 @@
   #:use-module (apps media types)
   #:use-module (apps media utils)
   #:use-module (srfi srfi-19)
-  #:export (screenshot->shtml
+  #:export (resource->shtml
+            screenshot->shtml
             screenshots-box
             video->shtml
             video-content
@@ -25,6 +27,26 @@
 ;;; Components.
 ;;;
 
+(define (resource->shtml resource)
+  `(a
+    (@ (class "community-preview item-preview")
+       (href ,(resource-link resource)))
+    (div
+     (@ (class "community-image"))
+     (div
+      (img
+       (@ (class "responsive-image")
+          (src ,(or (resource-preview resource)
+                    (case (resource-type resource)
+                      ((video) (guix-url "static/base/img/videos-icon.png"))
+                      ((article blog) (guix-url "static/base/img/manual-icon.png")))))
+          (alt "")))))
+    (h3 ,(resource-title resource))
+    (p
+     ,(G_ `(" published " ,(date->string (resource-date resource) "~b ~d, ~Y")
+            " by " ,(resource-author resource)
+            " in " ,(resource-language resource))))))
+
 (define (screenshot->shtml shot)
   "Return an SHTML representation of the given screenshot object.
 
diff --git a/website/apps/media/types.scm b/website/apps/media/types.scm
index 50c0989..ab54af8 100644
--- a/website/apps/media/types.scm
+++ b/website/apps/media/types.scm
@@ -5,7 +5,16 @@
 
 (define-module (apps media types)
   #:use-module (srfi srfi-9)
-  #:export (screenshot
+  #:export (resource
+            resource?
+            resource-author
+            resource-date
+            resource-language
+            resource-link
+            resource-preview
+            resource-title
+            resource-type
+            screenshot
             screenshot?
             screenshot-caption
             screenshot-image
@@ -32,6 +41,58 @@
 ;;; Data types.
 ;;;
 
+;;; Resource (record type)
+;;; ----------------------
+;;;
+;;; A community resource object represents a link to a resource created outside
+;;; of the Guix project, that talks about Guix.
+;;;
+;;; Objects of this type can be created with the "resource" precodure (see
+;;; Helper procedures below).
+;;;
+;;; Fields:
+;;;
+;;; title (string)
+;;;   The title of the resource
+;;;
+;;; link (string)
+;;;   The link to the resource
+;;;
+;;; author (string)
+;;;   The name of the author
+;;;
+;;; date (date)
+;;;   The date of publication
+;;;
+;;; preview (string)
+;;;   A URL to a small size image that represents the resource, or `#f' if
+;;;   it cannot be represented by an image.
+;;;
+;;; language (string)
+;;;   The name of the language in which the resource is written or spoken.
+;;;
+;;; type (symbol)
+;;;   The type of the resource, which can be one of:
+;;;   - 'article: a scientific or journalistic publication
+;;;   - 'blog: a blog post
+;;;   - 'video: a video presentation
+(define-record-type <resource>
+  (make-resource title link author date preview language type)
+  resource?
+  (title    resource-title)
+  (link     resource-link)
+  (author   resource-author)
+  (date     resource-date)
+  (preview  resource-preview)
+  (language resource-language)
+  (type     resource-type))
+
+;;; Helper procedures.
+
+(define* (resource #:key title link author date preview language type)
+  "Return a <screenshot> object with the given attributes."
+  (make-resource title link author date preview language type))
+
 ;;; Screenshot (record type)
 ;;; ------------------------
 ;;;
diff --git a/website/static/base/css/index.css b/website/static/base/css/index.css
index ea52a6d..707091b 100644
--- a/website/static/base/css/index.css
+++ b/website/static/base/css/index.css
@@ -66,6 +66,18 @@ h3 {
     color: #E6E6E6;
 }
 
+.resource-box {
+    padding: 40px 10px 0px 10px;
+    display: flex;
+    flex-direction: row;
+    flex-wrap: wrap;
+}
+
+.community-preview {
+    max-width: 270px;
+    padding: 0.5em;
+}
+
 .screenshots-box {
     padding: 40px 0px 0px 0px;
 }
diff --git a/website/static/media/css/community.css b/website/static/media/css/community.css
new file mode 100644
index 0000000..54de8d7
--- /dev/null
+++ b/website/static/media/css/community.css
@@ -0,0 +1,13 @@
+.community-image {
+  width: 180px;
+  height: 180px;
+  display: flex;
+  margin: auto;
+  flex-direction: row;
+  align-items: center;
+}
+
+.community-image img {
+  max-width: 180px;
+  max-height: 180px;
+}
diff --git a/website/static/media/img/community/carl-dong-bitcoin-security.webp b/website/static/media/img/community/carl-dong-bitcoin-security.webp
new file mode 100644
index 0000000000000000000000000000000000000000..017c00dd5c4b76614102b50a6bdb2f6887145a07
GIT binary patch
-- 
2.28.0

