Display README after directory content

Julien LepillerSun Mar 07 21:09:09+0100 2021

2f57e4e

Display README after directory content

gitile/pages.scm

5252
       "/")
5353
     path))
5454
55+
(define (file-content repo path ref repository-name)
56+
  `((div (@ (class "content"))
57+
     (p ,(basename path))
58+
     (p (@ (class "button-row"))
59+
       (a (@ (href "/" ,repository-name "/raw/" ,(or ref "-")
60+
                   "/" ,path))
61+
          (img (@ (src "/images/file-type-3.svg"))))))
62+
    (pre ,(utf8->string (get-file-content repo path #:ref ref)))))
63+
5564
(define* (project-files repository-name repo #:key (ref "-") (path '()))
5665
  (let* ((ref (if (equal? ref "-") #f ref))
5766
         (path-box (parent-paths-box repository-name ref path))

5968
         (dir-path (if (string-null? path) path (string-append path "/")))
6069
         (files (sort (get-files repo #:ref ref #:path dir-path)
6170
                      (lambda (f1 f2)
62-
                        (string<=? (file-name f1) (file-name f2))))))
71+
                        (string<=? (file-name f1) (file-name f2)))))
72+
         (readme (filter
73+
                   (lambda (f)
74+
                     (or (string-ci=? (file-name f) "README.md")
75+
                         (string-ci=? (file-name f) "README")))
76+
                   files)))
6377
    (if (and (string-null? path) (null? files))
6478
        `(p "Empty repository")
6579
        (if (null? files)
6680
            `(,path-box
67-
              (div (@ (class "content"))
68-
                 (p ,(basename path))
69-
                 (p (@ (class "button-row"))
70-
                   (a (@ (href "/" ,repository-name "/raw/" ,(or ref "-")
71-
                               "/" ,path))
72-
                      (img (@ (src "/images/file-type-3.svg"))))))
73-
              (pre ,(utf8->string (get-file-content repo path #:ref ref))))
81+
              ,(file-content repo path ref repository-name))
7482
            `(,(last-commit-infobox repository-name repo ref)
7583
              ,path-box
7684
              (table

95103
                                                             (commit-id commit))))
96104
                                      ,(commit-summary commit)))
97105
                               (td ,(time->date-string (commit-time commit)))))))
98-
                     files))))))))
106+
                     files)))
107+
              ,@(if (null? readme)
108+
                    '()
109+
                    (file-content
110+
                      repo
111+
                      (string-append path (if (equal? path "") "" "/")
112+
                                     (file-name (car readme)))
113+
                      ref
114+
                      repository-name)))))))
99115
100116
(define get-config-string
101117
  (let ((proc (libgit2->procedure int "git_config_get_string" '(* * *))))