aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2020-05-24 20:18:53 +0200
committerctucx <c@ctu.cx>2020-05-24 20:18:53 +0200
commit6d3ffe4fd1b24cf6a8f11e8c118173145a972429 (patch)
tree1b98fe40ef09ffbe672aa127edffff4da5f2795c
parentd1cd69b239efd1604e8ae04fb179e8bad7248d29 (diff)
downloadgallery-6d3ffe4fd1b24cf6a8f11e8c118173145a972429.tar.gz
gallery-6d3ffe4fd1b24cf6a8f11e8c118173145a972429.tar.bz2
gallery-6d3ffe4fd1b24cf6a8f11e8c118173145a972429.zip
configuration now completly parsed
-rw-r--r--sample.config17
-rw-r--r--src/assets/album.html21
-rw-r--r--src/assets/picture.html69
-rw-r--r--src/gallery.nim62
4 files changed, 101 insertions, 68 deletions
diff --git a/sample.config b/sample.config
index 46e970b..7f622e8 100644
--- a/sample.config
+++ b/sample.config
@@ -6,12 +6,13 @@ Author=ctucx
Name="ctucx' sample gallery"
Description="a short discription for your site"
Tags="a list of tags for seo stuff"
-ShowOriginalsButton=true ;not implemented yet
-SymlinkOriginals=false ;not implemented yet
+ShowOriginalsButton=false
+SymlinkOriginals=false
+EnableJS=true ;if disabled no exif data will get parsed and keyboard navigation does not work
-[Thumbnails]
-MediumMaxWidth=1920 ;not implemented yet
-MediumMaxHeight=1080 ;not implemented yet
-ThumbMaxWidth=200 ;not implemented yet
-ThumbMaxHeight=200 ;not implemented yet
-ThumbQuality=90 ;not implemented yet
+[Thumbnail]
+MediumMaxWidth=1920
+MediumMaxHeight=1080
+ThumbMaxWidth=200
+ThumbMaxHeight=200
+ThumbQuality=90
diff --git a/src/assets/album.html b/src/assets/album.html
index dd0016c..3334560 100644
--- a/src/assets/album.html
+++ b/src/assets/album.html
@@ -115,7 +115,7 @@
{{#pictures}}
<a href="{{name}}/" class="photo">
- <img src="./thumbnails/{{name}}.png" alt="Photo thumbnail" width="200" height="200">
+ <img src="./thumbnails/{{name}}.png" alt="Photo thumbnail" width="{{ThumbThumbMaxWidth}}" height="{{ThumbThumbMaxHeight}}">
<span class="overlay">
<h1>{{name}}</h1>
<!--<p><span title="Camera Date"><svg class="iconic "><use xlink:href="/iconic.svg#camera-slr"></use></svg></span></p>-->
@@ -124,13 +124,16 @@
{{/pictures}}
</div>
+ {{#isSubalbum}}
+ {{#SiteEnableJS}}
+ <script type="text/javascript">
+ window.onkeyup = function(e) {
+ if (e.keyCode == 27) window.location = "..";
+ if (e.keyCode == 32) document.getElementById("toggle").checked = true;
+ }
+ </script>
+ {{/SiteEnableJS}}
+ {{/isSubalbum}}
+
</body>
- {{#isSubalbum}}
- <script type="text/javascript">
- window.onkeyup = function(e) {
- if (e.keyCode == 27) window.location = "..";
- if (e.keyCode == 32) document.getElementById("toggle").checked = true;
- }
- </script>
- {{/isSubalbum}}
</html>
diff --git a/src/assets/picture.html b/src/assets/picture.html
index 2cc69c1..c617c05 100644
--- a/src/assets/picture.html
+++ b/src/assets/picture.html
@@ -23,8 +23,10 @@
<a class="button" href=".." id="button_close" title="Close Photo"><svg class="iconic"><use xlink:href="/iconic.svg#chevron-left"></use></svg></a>
<a class="header-title">{{name}}<svg class="iconic "><use xlink:href="/iconic.svg#caret-bottom"></use></svg></a>
- <a class="button" href="/originals/{{orig}}" title="Download"><svg class="iconic"><use xlink:href="/iconic.svg#cloud-download"></use></svg></a>
-
+ {{#SiteShowOrigBtn}}
+ <a class="button" href="/originals{{orig}}" title="Download"><svg class="iconic"><use xlink:href="/iconic.svg#cloud-download"></use></svg></a>
+ {{/SiteShowOrigBtn}}
+
<a class="header-divider"></a>
<input type="checkbox" id="toggle">
@@ -128,6 +130,11 @@
</tr>
</tbody>
</table>
+ {{^SiteEnableJS}}
+ <p>
+ Exif parsing is disabled by owner of this site.
+ </p>
+ {{/SiteEnableJS}}
</div>
</div>
</header>
@@ -151,33 +158,35 @@
</div>
{{/hasNext}}
</div>
+ {{#SiteEnableJS}}
+ <script type="text/javascript" src="/exif.js"></script>
+ <script type="text/javascript">
+ window.onload=getExif;
+ window.onkeyup = function(e) {
+ if (e.keyCode == 27) window.location = "..";
+ if (e.keyCode == 39) window.location = "../{{next_name}}";
+ if (e.keyCode == 37) window.location = "../{{prev_name}}";
+ if (e.keyCode == 32) document.getElementById("toggle").checked = true;
+ }
+
+ function getExif() {
+ let image = document.getElementById("image");
+
+ EXIF.getData(image, function() {
+ document.getElementById("attr_resolution").innerHTML = EXIF.getTag(this, "PixelXDimension") + 'x' + EXIF.getTag(this, "PixelYDimension");
+
+ document.getElementById("attr_captured").innerHTML = EXIF.getTag(this, "DateTimeOriginal");
+ document.getElementById("attr_make").innerHTML = EXIF.getTag(this, "Make");
+ document.getElementById("attr_type/model").innerHTML = EXIF.getTag(this, "Model");
+ document.getElementById("attr_shutter-speed").innerHTML = EXIF.getTag(this, "ExposureTime") + ' s';
+ document.getElementById("attr_shutter-program").innerHTML = EXIF.getTag(this, "ExposureProgram");
+ document.getElementById("attr_aperture").innerHTML = EXIF.getTag(this, "FNumber");
+ document.getElementById("attr_focal-length").innerHTML = EXIF.getTag(this, "FocalLength") + 'mm';
+ document.getElementById("attr_iso").innerHTML = EXIF.getTag(this, "ISOSpeedRatings");
+ document.getElementById("attr_flash").innerHTML = EXIF.getTag(this, "Flash");
+ });
+ }
+ </script>
+ {{/SiteEnableJS}}
</body>
- <script type="text/javascript" src="/exif.js"></script>
- <script type="text/javascript">
- window.onload=getExif;
- window.onkeyup = function(e) {
- if (e.keyCode == 27) window.location = "..";
- if (e.keyCode == 39) window.location = "../{{next_name}}";
- if (e.keyCode == 37) window.location = "../{{prev_name}}";
- if (e.keyCode == 32) document.getElementById("toggle").checked = true;
- }
-
- function getExif() {
- let image = document.getElementById("image");
-
- EXIF.getData(image, function() {
- document.getElementById("attr_resolution").innerHTML = EXIF.getTag(this, "PixelXDimension") + 'x' + EXIF.getTag(this, "PixelYDimension");
-
- document.getElementById("attr_captured").innerHTML = EXIF.getTag(this, "DateTimeOriginal");
- document.getElementById("attr_make").innerHTML = EXIF.getTag(this, "Make");
- document.getElementById("attr_type/model").innerHTML = EXIF.getTag(this, "Model");
- document.getElementById("attr_shutter-speed").innerHTML = EXIF.getTag(this, "ExposureTime") + ' s';
- document.getElementById("attr_shutter-program").innerHTML = EXIF.getTag(this, "ExposureProgram");
- document.getElementById("attr_aperture").innerHTML = EXIF.getTag(this, "FNumber");
- document.getElementById("attr_focal-length").innerHTML = EXIF.getTag(this, "FocalLength") + 'mm';
- document.getElementById("attr_iso").innerHTML = EXIF.getTag(this, "ISOSpeedRatings");
- document.getElementById("attr_flash").innerHTML = EXIF.getTag(this, "Flash");
- });
- }
- </script>
</html>
diff --git a/src/gallery.nim b/src/gallery.nim
index 5af8cf8..1dc42f0 100644
--- a/src/gallery.nim
+++ b/src/gallery.nim
@@ -85,15 +85,15 @@ proc createAlbum(path: string, isRoot: bool): Album =
result.pictures.sort(sortPictures)
-proc placeAssets(targetDir: string) =
+proc placeAssets(targetDir: string, enableJS: bool) =
echo "============"
echo "Create Assets in target dir"
discard existsOrCreateDir(targetDir)
- writeFile(joinPath(targetDir, "exif.js"), asset_exif_js)
writeFile(joinPath(targetDir, "style.css"), asset_style_css)
writeFile(joinPath(targetDir, "no_images.svg"), asset_noimages_svg)
writeFile(joinPath(targetDir, "iconic.svg"), asset_iconic_svg)
+ if enableJS: writeFile(joinPath(targetDir, "exif.js"), asset_exif_js)
proc generateWebsite(sourceDir: string, targetDir: string, album: Album, config: JsonNode) =
@@ -169,10 +169,10 @@ proc generateWebsite(sourceDir: string, targetDir: string, album: Album, config:
writeFile(joinPath(targetDir, picture.name, "index.html"), render(asset_picture_html, pictureTemplateContext))
if not fileExists(targetDir & "/thumbnails/" & picture.name & ".png"):
- smallThumbnails.add("/usr/bin/env mogrify -strip -quality 90 -format png -path " & quoteShell(joinPath(targetDir, "thumbnails")) & " -thumbnail 200x200^ -gravity center -extent 200x200 " & quoteShell(joinPath(picture.path, picture.filename)))
+ smallThumbnails.add("/usr/bin/env mogrify -strip -quality " & $config["ThumbThumbQuality"].getInt & " -format png -path " & quoteShell(joinPath(targetDir, "thumbnails")) & " -thumbnail " & $config["ThumbThumbMaxWidth"].getInt & "x" & $config["ThumbThumbMaxHeight"].getInt & "^ -gravity center -extent " & $config["ThumbThumbMaxWidth"].getInt & "x" & $config["ThumbThumbMaxHeight"].getInt & " " & quoteShell(joinPath(picture.path, picture.filename)))
if not fileExists(targetDir & "/medium/" & picture.name & ".jpg"):
- mediumThumbnails.add("/usr/bin/env mogrify -format jpg -path " & quoteShell(joinPath(targetDir, "medium")) & " -resize 1920x\\> " & quoteShell(joinPath(picture.path, picture.filename)))
+ mediumThumbnails.add("/usr/bin/env mogrify -format jpg -path " & quoteShell(joinPath(targetDir, "medium")) & " -resize " & $config["ThumbMediumMaxWidth"].getInt & "x\\> " & quoteShell(joinPath(picture.path, picture.filename)))
templateContext["pictures"].add(%* {
"name": picture.name,
@@ -216,29 +216,45 @@ proc main =
config.setSectionKey("Thumbnails", "ThumbMaxWidth", "200")
config.setSectionKey("Thumbnails", "ThumbMaxHeight", "200")
config.setSectionKey("Thumbnails", "ThumbQuality", "90")
+ config.setSectionKey("Thumbnails", "EnableJS", "true")
config.writeConfig(paramStr(1))
echo "Have written a default config to this file: " & paramStr(1)
echo "Please check it and rerun this program."
quit()
- var configFile = loadConfig(paramStr(1))
- let config = %* {
- "SourceDir": configFile.getSectionValue("", "SourceDir"),
- "TargetDir": configFile.getSectionValue("", "TargetDir"),
- "SiteName": configFile.getSectionValue("Site", "Name"),
- "SiteAuthor": configFile.getSectionValue("Site", "Author"),
- "SiteDescription": configFile.getSectionValue("Site", "Description"),
- "SiteTags": configFile.getSectionValue("Site", "Tags"),
- "SiteShowOrigBtn": configFile.getSectionValue("Site", "ShowOriginalsButton"), #not implemented yet
- "SiteSymlinkOrig": configFile.getSectionValue("Site", "SymlinkOriginals"), #not implemented yet
- "ThumbMediumMaxWidth": configFile.getSectionValue("Thumbnail", "MediumMaxWidth"), #not implemented yet
- "ThumbMediumMaxHeight": configFile.getSectionValue("Thumbnail", "MediumMaxHeight"), #not implemented yet
- "ThumbThumbMaxWidth": configFile.getSectionValue("Thumbnail", "ThumbMaxWidth"), #not implemented yet
- "ThumbThumbMaxHeight": configFile.getSectionValue("Thumbnail", "ThumbMaxHeight"), #not implemented yet
- "ThumbThumbQuality": configFile.getSectionValue("Thumbnail", "ThumbQuality") #not implemented yet
- }
+ var config = %* {}
+
+ try:
+ var configFile = loadConfig(paramStr(1))
+ config = %* {
+ "SourceDir": configFile.getSectionValue("", "SourceDir"),
+ "TargetDir": configFile.getSectionValue("", "TargetDir"),
+ "SiteName": configFile.getSectionValue("Site", "Name"),
+ "SiteAuthor": configFile.getSectionValue("Site", "Author"),
+ "SiteDescription": configFile.getSectionValue("Site", "Description"),
+ "SiteTags": configFile.getSectionValue("Site", "Tags"),
+ "SiteShowOrigBtn": configFile.getSectionValue("Site", "ShowOriginalsButton").parseBool, #not implemented yet
+ "SiteSymlinkOrig": configFile.getSectionValue("Site", "SymlinkOriginals").parseBool, #not implemented yet
+ "SiteEnableJS": configFile.getSectionValue("Site", "EnableJS").parseBool,
+ "ThumbMediumMaxWidth": configFile.getSectionValue("Thumbnail", "MediumMaxWidth").parseInt, #not implemented yet
+ "ThumbMediumMaxHeight": configFile.getSectionValue("Thumbnail", "MediumMaxHeight").parseInt, #not implemented yet
+ "ThumbThumbMaxWidth": configFile.getSectionValue("Thumbnail", "ThumbMaxWidth").parseInt, #not implemented yet
+ "ThumbThumbMaxHeight": configFile.getSectionValue("Thumbnail", "ThumbMaxHeight").parseInt, #not implemented yet
+ "ThumbThumbQuality": configFile.getSectionValue("Thumbnail", "ThumbQuality").parseInt #not implemented yet
+ }
+
+ except ValueError:
+ let
+ e = getCurrentException()
+ msg = getCurrentExceptionMsg()
+
+ echo "Got exception while parsing config: ", repr(e), " with message ", msg
+ quit()
+ except:
+ echo "Unknown exception while parsing of configuration!"
+ quit()
if not dirExists(config["SourceDir"].getStr):
echo "The source directory does not exist!\nBye!"
@@ -251,7 +267,11 @@ proc main =
let mainAlbum = createAlbum(config["SourceDir"].getStr, true)
- placeAssets(config["TargetDir"].getStr)
+ if config["SiteSymlinkOrig"].getBool != false:
+ if not symlinkExists(joinPath(config["TargetDir"].getStr, "originals")):
+ createSymlink(config["SourceDir"].getStr, joinPath(config["TargetDir"].getStr, "originals"))
+
+ placeAssets(config["TargetDir"].getStr, config["SiteEnableJS"].getBool)
generateWebsite(config["SourceDir"].getStr, config["TargetDir"].getStr, mainAlbum, config)