Browse Source

Always use slashes for urls (ref #81).

pull/87/merge
Simon Conseil 12 years ago
parent
commit
792bd0a6b5
  1. 10
      sigal/gallery.py
  2. 9
      sigal/utils.py
  3. 4
      sigal/writer.py
  4. 6
      tests/test_utils.py

10
sigal/gallery.py

@ -42,7 +42,7 @@ from .compat import UnicodeMixin, strxfrm
from .image import process_image, get_exif_tags
from .log import colored, BLUE
from .settings import get_thumb, get_orig
from .utils import copy, check_or_create_dir
from .utils import copy, check_or_create_dir, url_from_path
from .video import process_video
from .writer import Writer
@ -67,6 +67,7 @@ class Media(UnicodeMixin):
def __init__(self, filename, path, settings):
self.filename = filename
self.url = filename
self.settings = settings
self.file_path = join(path, filename)
self.src_path = join(settings['source'], path, filename)
@ -182,8 +183,8 @@ class Album(UnicodeMixin):
self.url_ext = self.output_file if settings['index_in_url'] else ''
self.url = self.name + '/' + self.url_ext
self.index_url = os.path.relpath(settings['destination'],
self.dst_path) + '/' + self.url_ext
self.index_url = url_from_path(os.path.relpath(
settings['destination'], self.dst_path)) + '/' + self.url_ext
# sort sub-albums
dirnames.sort(key=strxfrm, reverse=settings['albums_sort_reverse'])
@ -355,7 +356,8 @@ class Album(UnicodeMixin):
if path == '.':
break
url = os.path.relpath(path, self.path) + '/' + self.url_ext
url = (url_from_path(os.path.relpath(path, self.path)) + '/' +
self.url_ext)
breadcrumb.append((url, self.gallery.albums[path].title))
breadcrumb.reverse()

9
sigal/utils.py

@ -17,3 +17,12 @@ def check_or_create_dir(path):
if not os.path.isdir(path):
os.makedirs(path)
def url_from_path(path):
"""Transform path to url, converting backslashes to slashes if needed."""
if os.sep == '/':
return path
else:
return '/'.join(path.split(os.sep))

4
sigal/writer.py

@ -34,6 +34,7 @@ from jinja2 import Environment, FileSystemLoader, ChoiceLoader, PrefixLoader
from jinja2.exceptions import TemplateNotFound
from .pkgmeta import __url__ as sigal_link
from .utils import url_from_path
THEMES_PATH = os.path.normpath(os.path.join(
os.path.abspath(os.path.dirname(__file__)), 'themes'))
@ -99,7 +100,8 @@ class Writer(object):
'settings': self.settings,
'sigal_link': sigal_link,
'theme': {'name': os.path.basename(self.theme),
'url': os.path.relpath(self.theme_path, album.dst_path)},
'url': url_from_path(os.path.relpath(self.theme_path,
album.dst_path))},
}
def write(self, album):

6
tests/test_utils.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import os
from sigal.utils import copy, check_or_create_dir
from sigal.utils import copy, check_or_create_dir, url_from_path
CURRENT_DIR = os.path.dirname(__file__)
SAMPLE_DIR = os.path.join(CURRENT_DIR, 'sample')
@ -32,3 +32,7 @@ def test_check_or_create_dir(tmpdir):
path = str(tmpdir.join('new_directory'))
check_or_create_dir(path)
assert os.path.isdir(path)
def test_url_from_path():
assert url_from_path(os.sep.join(['foo', 'bar'])) == 'foo/bar'

Loading…
Cancel
Save