Allow to configure avatar source
gitile/config.scm
| 1 | 1 | ;;;; Copyright (C) 2021 Julien Lepiller <julien@lepiller.eu> | |
| 2 | + | ;;;; Copyright (C) 2024 Evgeny Pisemsky <mail@pisemsky.site> | |
| 2 | 3 | ;;;; | |
| 3 | 4 | ;;;; SPDX-License-Identifier: AGPL-3.0-or-later | |
| 4 | 5 | ;;;; | |
… | |||
| 28 | 29 | config-base-git-url | |
| 29 | 30 | config-index-title | |
| 30 | 31 | config-intro | |
| 31 | - | config-footer)) | |
| 32 | + | config-footer | |
| 33 | + | avatar-url-template | |
| 34 | + | avatar-hash-algorithm | |
| 35 | + | set-parameters-from-config!)) | |
| 32 | 36 | ||
| 33 | 37 | (define-record-type <config> | |
| 34 | 38 | (make-config port host database repositories base-git-url index-title intro footer) | |
… | |||
| 41 | 45 | (index-title config-index-title) | |
| 42 | 46 | (intro config-intro) | |
| 43 | 47 | (footer config-footer)) | |
| 48 | + | ||
| 49 | + | (define avatar-url-template | |
| 50 | + | (make-parameter "https://avatar.lepiller.eu/cat-avatar-generator.php?seed=$hash")) | |
| 51 | + | ||
| 52 | + | (define avatar-hash-algorithm | |
| 53 | + | (make-parameter 'sha1)) | |
| 54 | + | ||
| 55 | + | (define (set-parameters-from-config! config) | |
| 56 | + | (let ((params (config-database config))) | |
| 57 | + | (if (list? params) | |
| 58 | + | (begin | |
| 59 | + | (avatar-url-template | |
| 60 | + | (or (assoc-ref params 'avatar-url-template) | |
| 61 | + | (avatar-url-template))) | |
| 62 | + | (avatar-hash-algorithm | |
| 63 | + | (or (assoc-ref params 'avatar-hash-algorithm) | |
| 64 | + | (avatar-hash-algorithm))))))) | |
gitile/pages.scm
| 23 | 23 | #:use-module (gcrypt hash) | |
| 24 | 24 | #:use-module (gitile code) | |
| 25 | 25 | #:use-module (gitile repo) | |
| 26 | + | #:use-module (gitile config) | |
| 26 | 27 | #:use-module (git) | |
| 27 | 28 | #:use-module (git types) | |
| 28 | 29 | #:use-module (ice-9 match) | |
| 30 | + | #:use-module (ice-9 string-fun) | |
| 29 | 31 | #:use-module (rnrs bytevectors) | |
| 30 | 32 | #:use-module (srfi srfi-1); fold | |
| 31 | 33 | #:use-module (srfi srfi-19); date/time | |
… | |||
| 170 | 172 | ,(project-files repository-name repo))) | |
| 171 | 173 | ||
| 172 | 174 | (define (author-image author) | |
| 173 | - | (string-append "https://avatar.lepiller.eu/cat-avatar-generator.php?seed=" | |
| 174 | - | (bytevector->base16-string | |
| 175 | - | (bytevector-hash | |
| 176 | - | (string->utf8 (signature-email author)) | |
| 177 | - | (hash-algorithm sha1))))) | |
| 175 | + | (string-replace-substring | |
| 176 | + | (avatar-url-template) "$hash" | |
| 177 | + | (bytevector->base16-string | |
| 178 | + | (bytevector-hash | |
| 179 | + | (string->utf8 (signature-email author)) | |
| 180 | + | (lookup-hash-algorithm (avatar-hash-algorithm)))))) | |
| 178 | 181 | ||
| 179 | 182 | (define (time->date-string time) | |
| 180 | 183 | (date->string | |
scripts/gitile.in
| 42 | 42 | intro footer))))) | |
| 43 | 43 | (_ (format #t "Usage: ~a [-c config-file]~%" (car args)))))) | |
| 44 | 44 | (set-owner-validation! #f) | |
| 45 | + | (set-parameters-from-config! config) | |
| 45 | 46 | (run-server (gitile-handler config) | |
| 46 | 47 | #:port (config-port config)))) | |
| 47 | 48 |