ctucx.git: gallery

static-site-generator for image-galleries [used @ photos.ctu.cx]

commit 82479e4961d7058374454b3e4d962653d196d625
parent f3e5dfcedf2cdddbcce62b79486e2a16d714d523
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 14 Mar 2021 12:29:28 +0100

gallery.nim: path to mogrify-command as config-option
1 file changed, 9 insertions(+), 6 deletions(-)
M
src/gallery.nim
|
15
+++++++++------
diff --git a/src/gallery.nim b/src/gallery.nim
@@ -6,6 +6,7 @@ type
     Config* = object
         sourceDir*:           string
         targetDir*:           string
+        mogrifyCmd*:          string
         siteName*:            string
         siteAuthor*:          string
         siteTags*:            string

@@ -281,7 +282,7 @@ proc generateWebsite(targetDir: string, album: Album) =
         writeFile(joinPath(targetDir, picture.name & ".html"), render(asset_picture_html, pictureTemplateContext))
 
         if not fileExists(joinPath(targetDir, "thumbnails/small", picture.name & ".jpg")):
-            smallThumbnails.add(["/usr/bin/env mogrify",
+            smallThumbnails.add([config.mogrifyCmd,
                 "-format", "jpg",
                 "-interlace", "plane",
                 "-quality", $config.thumbSmallQuality,

@@ -291,7 +292,7 @@ proc generateWebsite(targetDir: string, album: Album) =
             ].join(" "))
 
         if not fileExists(joinPath(targetDir, "thumbnails/medium", picture.filename)):
-            mediumThumbnails.add(["/usr/bin/env mogrify",
+            mediumThumbnails.add([config.mogrifyCmd,
                 "-strip",
                 "-interlace", "plane",
                 "-format", $picture.filetype,

@@ -327,10 +328,6 @@ proc main =
     randomize()
     init_jpg()
 
-    if (execProcess("/usr/bin/env mogrify -v").contains("No such file or directory")):
-        echo "It seems like you don't have ImageMagick installed, which is mandatory to use this tool.\nBye!"
-        quit(QuitFailure)
-
     if paramCount() == 0:
         echo "No config-file given! Exiting..."
         quit(QuitFailure)

@@ -342,6 +339,7 @@ proc main =
             var config = newConfig()
             config.setSectionKey("",            "SourceDir",              "./foobar")
             config.setSectionKey("",            "TargetDir",              "./out")
+            config.setSectionKey("",            "MogrifyCmd",             "/usr/bin/mogrify")
 
             config.setSectionKey("Site",        "Author",                 "Max Musermann")
             config.setSectionKey("Site",        "Name",                   "ctucx gallery sample")

@@ -370,6 +368,7 @@ proc main =
         config = Config(
             sourceDir:           normalizedPath(configFile.getSectionValue("",               "SourceDir",           "")),
             targetDir:           normalizedPath(configFile.getSectionValue("",               "TargetDir",           "")),
+            mogrifyCmd:          configFile.getSectionValue("",                              "MogrifyCmd",          "/usr/bin/mogrify"),
             siteName:            configFile.getSectionValue("Site",                          "Name",                "default title - change me plese"),
             siteAuthor:          configFile.getSectionValue("Site",                          "Author",              "Max Mustermann"),
             siteTags:            configFile.getSectionValue("Site",                          "Tags",                ""),

@@ -394,6 +393,10 @@ proc main =
             echo "Config-value 'TargetDir' has to be set!"
             quit(QuitFailure)
 
+        if (execProcess(config.mogrifyCmd & " -v").contains("No such file or directory")):
+            echo "It seems like you don't have ImageMagick installed or the specified path in the config is incorrect.\nBye!"
+            quit(QuitFailure)
+
         if config.thumbSmallHeight == 0:
             config.thumbSmallHeight = 200