Compare commits

...

3 Commits

Author SHA1 Message Date
Romain 9def14a641 docs: update container image URL in README 5 months ago
Romain 4ffba3b276 fix: relative() helper with --link-prefix
The previous implementation did not work when the link prefix
went back deeper than the current folder allows
e.g. ../../.. when running from /app

Which is expected to work regardless because the link prefix
is assumed to exist relative to the final deployment

Fixes #351
5 months ago
Romain 6871f6edd2 test: add more tests for relative() helper 5 months ago

@ -62,7 +62,7 @@ And optionally:
- [dcraw](https://www.cybercom.net/~dcoffin/dcraw/) to process RAW photos: `brew install dcraw` - [dcraw](https://www.cybercom.net/~dcoffin/dcraw/) to process RAW photos: `brew install dcraw`
- [ImageMagick](https://imagemagick.org/) for HEIC support (needs to be compiled with `--with-heic`) - [ImageMagick](https://imagemagick.org/) for HEIC support (needs to be compiled with `--with-heic`)
You can run thumbsup as a Docker container ([thumbsupgallery/thumbsup](https://hub.docker.com/r/thumbsupgallery/thumbsup/)) which pre-packages all the dependencies above. Read the [thumbsup on Docker](https://thumbsup.github.io/docs/2-installation/docker/) documentation for more detail. You can run thumbsup as a Docker container ([ghcr.io/thumbsup/thumbsup](https://github.com/thumbsup/thumbsup/pkgs/container/thumbsup)) which pre-packages all the dependencies above. Read the [thumbsup on Docker](https://thumbsup.github.io/docs/2-installation/docker/) documentation for more detail.
```bash ```bash
docker run -v `pwd`:/work thumbsupgallery/thumbsup [...] docker run -v `pwd`:/work thumbsupgallery/thumbsup [...]

@ -6,7 +6,8 @@ module.exports = (target, options) => {
return target return target
} }
const albumPath = options.data.root.album.path 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, '/') const url = relative.replace(/\\/g, '/')
// Escape single/double quotes // Escape single/double quotes
return url.replace(/'/g, '%27').replace(/"/g, '%22') return url.replace(/'/g, '%27').replace(/"/g, '%22')

@ -1,59 +1,105 @@
const date = require('../../../src/website/theme-base/helpers/relative') const relative = require('../../../src/website/theme-base/helpers/relative')
const handlebars = require('handlebars') const handlebars = require('handlebars')
const should = require('should/as-function') const should = require('should/as-function')
describe('Handlebars helpers: relative', () => { describe('Handlebars helpers: relative', () => {
handlebars.registerHelper('relative', date) handlebars.registerHelper('relative', relative)
it('returns a path in the same folder', () => { describe('theme assets', () => {
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'public/theme.css\'}}" />') it('returns a path in the same folder', () => {
const res = template({ const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'public/theme.css\'}}" />')
album: { const res = template({
path: 'index.html' album: {
} path: 'index.html'
}
})
should(res).eql('<link rel="stylesheet" href="public/theme.css" />')
}) })
should(res).eql('<link rel="stylesheet" href="public/theme.css" />')
})
it('returns a relative path for albums in nested folders', () => { it('returns a relative path for albums in nested folders', () => {
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'public/theme.css\'}}" />') const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'public/theme.css\'}}" />')
const res = template({ const res = template({
album: { album: {
path: 'albums/holidays.html' path: 'albums/holidays.html'
} }
})
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
}) })
should(res).eql('<link rel="stylesheet" href="../public/theme.css" />')
}) })
it('does not do anything if the path is an absolute URL', () => { describe('images and videos', () => {
// This can happen when using --link-prefix it('returns a path from the root album', () => {
const url = 'http://example.com/photo.jpg' const template = handlebars.compile('<img src="{{relative \'media/thumbs/img.jpg\'}}" />')
const template = handlebars.compile(`<img src="{{relative '${url}'}}" />`) const res = template({
const res = template({}) album: {
should(res).eql(`<img src="${url}" />`) path: 'index.html'
}) }
})
should(res).eql('<img src="media/thumbs/img.jpg" />')
})
// TODO: this should not be needed anymore because all URLs are already escaped it('returns a path from a nested album', () => {
it('escapes single quotes so they can be used in CSS background-image', () => { const template = handlebars.compile('<img src="{{relative \'media/thumbs/img.jpg\'}}" />')
const template = handlebars.compile("background-image('{{relative url}}')") const res = template({
const res = template({ album: {
url: "l'histoire.jpg", path: 'albums/holidays.html'
album: { }
path: 'index.html' })
} should(res).eql('<img src="../media/thumbs/img.jpg" />')
})
it('can use a relative link from the root album', () => {
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'../../photos/img.jpg\'}}" />')
const res = template({
album: {
path: 'index.html'
}
})
should(res).eql('<link rel="stylesheet" href="../../photos/img.jpg" />')
})
it('can use relative link from a nested album', () => {
const template = handlebars.compile('<link rel="stylesheet" href="{{relative \'../../photos/img.jpg\'}}" />')
const res = template({
album: {
path: 'albums/holidays.html'
}
})
should(res).eql('<link rel="stylesheet" href="../../../photos/img.jpg" />')
})
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'
const template = handlebars.compile(`<img src="{{relative '${url}'}}" />`)
const res = template({})
should(res).eql(`<img src="${url}" />`)
}) })
should(res).eql("background-image('l%27histoire.jpg')")
}) })
// TODO: this should not be needed anymore because all URLs are already escaped describe('escaping', () => {
it('escapes double quotes so they can be used in <img> tags', () => { // TODO: this should not be needed anymore because all URLs are already escaped
const template = handlebars.compile('<img src="{{relative url}}" />') it('escapes single quotes so they can be used in CSS background-image', () => {
const res = template({ const template = handlebars.compile("background-image('{{relative url}}')")
url: 'l"histoire.jpg', const res = template({
album: { url: "l'histoire.jpg",
path: 'index.html' album: {
} path: 'index.html'
}
})
should(res).eql("background-image('l%27histoire.jpg')")
})
// TODO: this should not be needed anymore because all URLs are already escaped
it('escapes double quotes so they can be used in <img> tags', () => {
const template = handlebars.compile('<img src="{{relative url}}" />')
const res = template({
url: 'l"histoire.jpg',
album: {
path: 'index.html'
}
})
should(res).eql('<img src="l%22histoire.jpg" />')
}) })
should(res).eql('<img src="l%22histoire.jpg" />')
}) })
}) })

Loading…
Cancel
Save