summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am9
-rw-r--r--configure.ac6
-rw-r--r--guix.scm6
-rw-r--r--haunt/config.scm.in6
-rw-r--r--haunt/publisher/sourcehut.scm58
5 files changed, 82 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 1b12737..7a6583e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,9 +97,18 @@ SOURCES += haunt/publisher/rsync.scm
endif
+if HAVE_HUT
+if HAVE_TAR
+
+SOURCES += haunt/publisher/sourcehut.scm
+
+endif
+endif
+
TESTS = \
tests/helper.scm \
tests/post.scm \
+ tests/publisher-hut.scm \
tests/utils.scm
TEST_EXTENSIONS = .scm
diff --git a/configure.ac b/configure.ac
index a1c4620..02c6c8f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -36,4 +36,10 @@ AC_CHECK_FUNC([inotify_init], [AM_CONDITIONAL(HAVE_INOTIFY, true)], [AM_CONDITIO
AC_PATH_PROG([RSYNC], [rsync])
AM_CONDITIONAL([HAVE_RSYNC], [test "x$RSYNC" != "x"])
+AC_PATH_PROG([HUT], [hut])
+AM_CONDITIONAL([HAVE_HUT], [test "x$HUT" != "x"])
+
+AC_PATH_PROG([TAR], [tar])
+AM_CONDITIONAL([HAVE_TAR], [test "x$TAR" != "x"])
+
AC_OUTPUT
diff --git a/guix.scm b/guix.scm
index 8685eb2..6ee9262 100644
--- a/guix.scm
+++ b/guix.scm
@@ -34,10 +34,12 @@
(guix build-system gnu)
(gnu packages)
(gnu packages autotools)
+ (gnu packages base)
(gnu packages guile)
(gnu packages guile-xyz)
(gnu packages pkg-config)
- (gnu packages texinfo))
+ (gnu packages texinfo)
+ (gnu packages version-control))
(package
(name "haunt")
@@ -50,7 +52,7 @@
(add-after 'unpack 'bootstrap
(lambda _ (zero? (system* "sh" "bootstrap")))))))
(native-inputs (list autoconf automake pkg-config texinfo))
- (inputs (list guile-3.0))
+ (inputs (list guile-3.0 hut tar))
(propagated-inputs (list guile-commonmark guile-reader))
(synopsis "Functional static site generator")
(description "Haunt is a static site generator written in Guile
diff --git a/haunt/config.scm.in b/haunt/config.scm.in
index 945dfa5..5256c44 100644
--- a/haunt/config.scm.in
+++ b/haunt/config.scm.in
@@ -24,8 +24,12 @@
(define-module (haunt config)
#:export (%haunt-version
- %rsync))
+ %rsync
+ %hut
+ %tar))
(define %haunt-version "@PACKAGE_VERSION@")
(define %rsync "@RSYNC@")
+(define %hut "@HUT@")
+(define %tar "@TAR@")
diff --git a/haunt/publisher/sourcehut.scm b/haunt/publisher/sourcehut.scm
new file mode 100644
index 0000000..035d399
--- /dev/null
+++ b/haunt/publisher/sourcehut.scm
@@ -0,0 +1,58 @@
+;;; Haunt --- Static site generator for GNU Guile
+;;; Copyright © 2023 Filip Lajszczak <filip@lajszczak.dev>
+;;;
+;;; This file is part of Haunt.
+;;;
+;;; Haunt is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or
+;;; (at your option) any later version.
+;;;
+;;; Haunt is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;;; General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with Haunt. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;;
+;; Sourcehut publisher.
+;;
+;;; Code:
+
+(define-module (haunt publisher sourcehut)
+ #:use-module (haunt config)
+ #:use-module (haunt publisher)
+ #:use-module (haunt site)
+ #:export (sourcehut-publisher))
+
+(define* (sourcehut-publisher #:key
+ (name %default-publisher-name)
+ ;; TODO: Factor out some helper for this.
+ (hut (if (file-exists? %hut) %hut "hut"))
+ (tar (if (file-exists? %tar) %tar "tar")))
+ "Return a new publisher named NAME that publishes a site to
+Sourcehut pages."
+ (define (publish site)
+ (let ((tarball (string-append (or (getenv "TMPDIR") "/tmp")
+ "/haunt-publish-sourcehut-"
+ (number->string (current-time))
+ ".tar.gz")))
+ (dynamic-wind
+ (lambda () #t)
+ (lambda ()
+ (run-command tar
+ "--directory" (site-absolute-build-directory site)
+ "--create" "--gzip"
+ "--file" tarball
+ ".")
+ (run-command hut "pages"
+ "publish"
+ "--domain" (site-domain site)
+ tarball))
+ (lambda ()
+ (when (file-exists? tarball)
+ (delete-file tarball))))))
+ (make-publisher name publish))