import/utils: Add beautify-synopsis.
authorRicardo Wurmus <rekado@elephly.net>
Wed, 28 Sep 2022 20:05:52 +0000 (22:05 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Wed, 28 Sep 2022 20:10:33 +0000 (22:10 +0200)
* guix/import/utils.scm (beautify-synopsis): New procedure.

guix/import/utils.scm

index 7e7d116..dd8c61b 100644 (file)
@@ -72,6 +72,7 @@
 
             snake-case
             beautify-description
+            beautify-synopsis
 
             alist->package
 
@@ -295,7 +296,22 @@ LENGTH characters."
     ;; Use double spacing between sentences
     (fill-paragraph (regexp-substitute/global #f "\\. \\b"
                                           cleaned 'pre ".  " 'post)
-                length)))
+                    length)))
+
+(define (beautify-synopsis synopsis)
+  "Improve the package SYNOPSIS."
+  (let ((cleaned (cond
+                  ((not (string? synopsis))
+                   (G_ "This package lacks a synopsis.  Run \
+\"info '(guix) Synopses and Descriptions'\" for more information."))
+                  ((string-prefix? "A " synopsis)
+                   (substring synopsis 1))
+                  ;; Remove trailing period.
+                  ((string-suffix? "." synopsis)
+                   (substring synopsis 0
+                              (1- (string-length synopsis))))
+                  (else synopsis))))
+    (string-trim-both cleaned)))
 
 (define* (package-names->package-inputs names #:optional (output #f))
   "Given a list of PACKAGE-NAMES or (PACKAGE-NAME VERSION) pairs, and an