chiark / gitweb /
m.images: make it possible to provide custom titles for image grid.
authorVladimír Vondruš <mosra@centrum.cz>
Fri, 29 Mar 2019 10:14:50 +0000 (11:14 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Fri, 29 Mar 2019 12:44:31 +0000 (13:44 +0100)
doc/plugins/images.rst
pelican-plugins/m/images.py
pelican-plugins/m/test/images/page.html
pelican-plugins/m/test/images/page.rst

index b5900d98100f47c8cda78c07f5b928e55c2e2c03..3c5e021abc4a06917817933b142f833e3eb3f29c 100644 (file)
@@ -130,10 +130,13 @@ option for both images and figures.
 Use the :rst:`.. image-grid::` directive for creating
 `image grid <{filename}/css/components.rst#image-grid>`_. Directive contents
 are a list of image URLs, blank lines separate grid rows. The plugin
-automatically extracts size information and scales the images accordingly. If
-the image has EXIF information, properties such as aperture, shutter speed and
-ISO are extracted and displayed in the caption on hover. The images are also
-made clickable, the target is the image file itself.
+automatically extracts size information and scales the images accordingly. The images are made clickable, the target is the image file itself.
+
+If the image has EXIF information, properties such as aperture, shutter speed
+and ISO are extracted and displayed in the caption on hover. It's also possible
+to provide a custom title --- everything after the filename will be taken as
+a title. If you use ``..`` as a title (a reST comment), it will disable EXIF
+extraction and no title will be shown.
 
 Example of a two-row image grid is below. Sorry for reusing the same two images
 all over (I'm making it easier for myself); if you want to see a live example
@@ -146,16 +149,16 @@ with non-repeating images, head over to `my blog <http://blog.mosra.cz/cesty/mai
         {static}/ship.jpg
         {static}/flowers.jpg
 
-        {static}/flowers.jpg
-        {static}/ship.jpg
+        {static}/flowers.jpg A custom title
+        {static}/ship.jpg ..
 
 .. image-grid::
 
     {static}/static/ship.jpg
     {static}/static/flowers.jpg
 
-    {static}/static/flowers.jpg
-    {static}/static/ship.jpg
+    {static}/static/flowers.jpg A custom title
+    {static}/static/ship.jpg ..
 
 .. note-warning::
 
index e6c834d395453f88af15e2d2e14063bb83202aae..062606af5adff9182df3e8b8d0e707ade3d611b1 100644 (file)
@@ -199,21 +199,23 @@ class ImageGrid(rst.Directive):
 
         rows = [[]]
         total_widths = [0]
-        for uri in self.content:
+        for uri_caption in self.content:
             # New line, calculating width from 0 again
-            if not uri:
+            if not uri_caption:
                 rows.append([])
                 total_widths.append(0)
                 continue
 
+            uri, _, caption = uri_caption.partition(' ')
+
             # Open the files and calculate the overall width
             # Support both {filename} (3.7.1) and {static} (3.8) placeholders
             file = os.path.join(os.getcwd(), settings['PATH'])
             absuri = uri.format(filename=file, static=file)
             im = PIL.Image.open(absuri)
 
-            # Get EXIF info, if it's there
-            if hasattr(im, '_getexif') and im._getexif() is not None:
+            # If no caption provided, get EXIF info, if it's there
+            if not caption and hasattr(im, '_getexif') and im._getexif() is not None:
                 exif = {
                     PIL.ExifTags.TAGS[k]: v
                     for k, v in im._getexif().items()
@@ -234,8 +236,8 @@ class ImageGrid(rst.Directive):
                     caption += ["ISO {}".format(exif['ISOSpeedRatings'])]
                 caption = ', '.join(caption)
 
-            # It's not (e.g. a PNG file), empty caption
-            else: caption = ""
+            # If the caption is `..`, it's meant to be explicitly disabled
+            if caption == '..': caption = ''
 
             rel_width = float(im.width)/im.height
             total_widths[-1] += rel_width
index 3e16d9fa57de0ba09b61ca2347caebc8f20dcc04..04d20af0f082e3a357caac1115ac8c3f10f87131 100644 (file)
@@ -68,7 +68,7 @@ Yes.</span>
 <a href="./ship.jpg"><img src="./ship.jpg" style="height: 200px" /></a>
 <figcaption>A Ship</figcaption>
 </figure>
-<p>Image grid:</p>
+<p>Image grid, second row with a custom title and no title:</p>
 <div class="m-imagegrid m-container-inflate">
 <div>
 <figure style="width: 69.127%">
@@ -82,11 +82,12 @@ Yes.</span>
 </div>
 <div>
 <figure style="width: 30.873%">
-<a href="./flowers.jpg"><img src="./flowers.jpg" /><figcaption>F2.8, 1/1600 s, ISO 100</figcaption>
+<a href="./flowers.jpg"><img src="./flowers.jpg" /><figcaption>A custom title</figcaption>
 </a>
 </figure>
 <figure style="width: 69.127%">
-<a href="./ship.jpg"><img src="./ship.jpg" /><figcaption>F9.0, 1/250 s, ISO 100</figcaption>
+<a href="./ship.jpg"><img src="./ship.jpg" /><div>
+</div>
 </a>
 </figure>
 </div>
index 1aea1188cb9799e92480fa7ad4f85ee5dcb5af62..983031459fb2a97edcbc2a70735252b56b46cbba 100644 (file)
@@ -81,15 +81,15 @@ Figure with a height:
 
     A Ship
 
-Image grid:
+Image grid, second row with a custom title and no title:
 
 .. image-grid::
 
     {static}/ship.jpg
     {static}/flowers.jpg
 
-    {static}/flowers.jpg
-    {static}/ship.jpg
+    {static}/flowers.jpg A custom title
+    {static}/ship.jpg ..
 
 Image grid with a PNG file, JPEG with sparse EXIF data, JPEG with no EXIF data
 and long exposure (>1 second):