From d6a196bcdd5c3329ee2aeb02eb228884c23fc5f3 Mon Sep 17 00:00:00 2001 From: Simon Conseil Date: Tue, 8 Apr 2014 00:07:20 +0200 Subject: [PATCH] Better handling of album urls (quoting special caracters). --- sigal/compat.py | 2 ++ sigal/gallery.py | 12 ++++++++---- tests/test_gallery.py | 6 +++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/sigal/compat.py b/sigal/compat.py index 7716781..33ccd4c 100644 --- a/sigal/compat.py +++ b/sigal/compat.py @@ -12,6 +12,7 @@ if not PY2: strxfrm = locale.strxfrm from http import server + from urllib.parse import quote as url_quote import socketserver else: text_type = unicode # NOQA @@ -21,6 +22,7 @@ else: def strxfrm(s): return locale.strxfrm(s.encode('utf-8')) + from urllib import quote as url_quote import SimpleHTTPServer as server import SocketServer as socketserver diff --git a/sigal/gallery.py b/sigal/gallery.py index 47a3026..f079215 100644 --- a/sigal/gallery.py +++ b/sigal/gallery.py @@ -38,7 +38,7 @@ from os.path import isfile, join, splitext from PIL import Image as PILImage from . import image, video -from .compat import UnicodeMixin, strxfrm +from .compat import UnicodeMixin, strxfrm, url_quote from .image import process_image, get_exif_tags from .log import colored, BLUE from .settings import get_thumb @@ -182,7 +182,6 @@ class Album(UnicodeMixin): # optionally add index.html to the URLs self.url_ext = self.output_file if settings['index_in_url'] else '' - self.url = self.name + '/' + self.url_ext self.index_url = url_from_path(os.path.relpath( settings['destination'], self.dst_path)) + '/' + self.url_ext @@ -252,8 +251,7 @@ class Album(UnicodeMixin): self.meta = md.Meta.copy() else: # default: get title from directory name - self.title = os.path.basename(self.path).replace('_', ' ')\ - .replace('-', ' ').capitalize() + self.title = os.path.basename(self.path) self.description = '' self.meta = {} @@ -292,6 +290,12 @@ class Album(UnicodeMixin): return [self.gallery.albums[join(root_path, path)] for path in self.subdirs] + @property + def url(self): + """URL of the album, relative to its parent.""" + url = self.name.encode('utf-8') + return url_quote(url) + '/' + self.url_ext + @property def thumbnail(self): """Path to the thumbnail of the album.""" diff --git a/tests/test_gallery.py b/tests/test_gallery.py index ea957af..d9e60f2 100644 --- a/tests/test_gallery.py +++ b/tests/test_gallery.py @@ -26,7 +26,7 @@ REF = { 'flickr_jerquiaga_2394751088_cc-by-nc.jpg'], }, 'dir1/test2': { - 'title': 'Test2', + 'title': 'test2', 'name': 'test2', 'thumbnail': 'test2/thumbnails/21.tn.jpg', 'subdirs': [], @@ -43,14 +43,14 @@ REF = { 'm57_the_ring_nebula-587px.jpg'], }, u'accentué': { - 'title': u'Accentué', + 'title': u'accentué', 'name': u'accentué', 'thumbnail': u'accentué/thumbnails/hélicoïde.tn.jpg', 'subdirs': [], 'medias': [u'hélicoïde.jpg', 'superdupont_source_wikipedia_en.jpg'], }, 'video': { - 'title': 'Video', + 'title': 'video', 'name': 'video', 'thumbnail': ('video/thumbnails/' 'stallman software-freedom-day-low.tn.jpg'),