diff --git a/src/website/theme-base/helpers/relative.js b/src/website/theme-base/helpers/relative.js
index 584c185..b865b7f 100644
--- a/src/website/theme-base/helpers/relative.js
+++ b/src/website/theme-base/helpers/relative.js
@@ -6,7 +6,8 @@ module.exports = (target, options) => {
return target
}
const albumPath = options.data.root.album.path
- const relative = path.relative(path.dirname(albumPath), target)
+ const backToGalleryRoot = path.relative(path.dirname(albumPath), '.')
+ const relative = path.join(backToGalleryRoot, target)
const url = relative.replace(/\\/g, '/')
// Escape single/double quotes
return url.replace(/'/g, '%27').replace(/"/g, '%22')
diff --git a/test/themes/helpers/relative.spec.js b/test/themes/helpers/relative.spec.js
index 814ea82..6722f06 100644
--- a/test/themes/helpers/relative.spec.js
+++ b/test/themes/helpers/relative.spec.js
@@ -48,6 +48,26 @@ describe('Handlebars helpers: relative', () => {
should(res).eql('')
})
+ it('can use a relative link from the root album', () => {
+ const template = handlebars.compile('')
+ const res = template({
+ album: {
+ path: 'index.html'
+ }
+ })
+ should(res).eql('')
+ })
+
+ it('can use relative link from a nested album', () => {
+ const template = handlebars.compile('')
+ const res = template({
+ album: {
+ path: 'albums/holidays.html'
+ }
+ })
+ should(res).eql('')
+ })
+
it('does not do anything if the path is an absolute URL', () => {
// This can happen when using --link-prefix
const url = 'http://example.com/photo.jpg'