summaryrefslogtreecommitdiffstats
path: root/resource/image_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-03-21 17:21:46 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-04-02 08:06:21 +0200
commiteb42774e587816b1fbcafbcea59ed65df703882a (patch)
treefdb62cf17355b47fa485941f3c3fffd604896daa /resource/image_test.go
parentf27977809ce5d5dce4db41db6323a4ad1b095985 (diff)
Add support for a content dir set per language
A sample config: ```toml defaultContentLanguage = "en" defaultContentLanguageInSubdir = true [Languages] [Languages.en] weight = 10 title = "In English" languageName = "English" contentDir = "content/english" [Languages.nn] weight = 20 title = "På Norsk" languageName = "Norsk" contentDir = "content/norwegian" ``` The value of `contentDir` can be any valid path, even absolute path references. The only restriction is that the content dirs cannot overlap. The content files will be assigned a language by 1. The placement: `content/norwegian/post/my-post.md` will be read as Norwegian content. 2. The filename: `content/english/post/my-post.nn.md` will be read as Norwegian even if it lives in the English content folder. The content directories will be merged into a big virtual filesystem with one simple rule: The most specific language file will win. This means that if both `content/norwegian/post/my-post.md` and `content/english/post/my-post.nn.md` exists, they will be considered duplicates and the version inside `content/norwegian` will win. Note that translations will be automatically assigned by Hugo by the content file's relative placement, so `content/norwegian/post/my-post.md` will be a translation of `content/english/post/my-post.md`. If this does not work for you, you can connect the translations together by setting a `translationKey` in the content files' front matter. Fixes #4523 Fixes #4552 Fixes #4553
Diffstat (limited to 'resource/image_test.go')
-rw-r--r--resource/image_test.go29
1 files changed, 16 insertions, 13 deletions
diff --git a/resource/image_test.go b/resource/image_test.go
index 0111d0850..39e538d33 100644
--- a/resource/image_test.go
+++ b/resource/image_test.go
@@ -16,6 +16,7 @@ package resource
import (
"fmt"
"math/rand"
+ "os"
"path/filepath"
"strconv"
"testing"
@@ -57,12 +58,14 @@ func TestParseImageConfig(t *testing.T) {
}
}
-func TestImageTransform(t *testing.T) {
+func TestImageTransformBasic(t *testing.T) {
assert := require.New(t)
image := fetchSunset(assert)
+ printFs(image.sourceFs(), "", os.Stdout)
+
assert.Equal("/a/sunset.jpg", image.RelPermalink())
assert.Equal("image", image.ResourceType())
@@ -75,19 +78,19 @@ func TestImageTransform(t *testing.T) {
assert.NoError(err)
assert.Equal(320, resized0x.Width())
assert.Equal(200, resized0x.Height())
- assertFileCache(assert, image.spec.Fs, resized0x.RelPermalink(), 320, 200)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, resized0x.RelPermalink(), 320, 200)
resizedx0, err := image.Resize("200x")
assert.NoError(err)
assert.Equal(200, resizedx0.Width())
assert.Equal(125, resizedx0.Height())
- assertFileCache(assert, image.spec.Fs, resizedx0.RelPermalink(), 200, 125)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, resizedx0.RelPermalink(), 200, 125)
resizedAndRotated, err := image.Resize("x200 r90")
assert.NoError(err)
assert.Equal(125, resizedAndRotated.Width())
assert.Equal(200, resizedAndRotated.Height())
- assertFileCache(assert, image.spec.Fs, resizedAndRotated.RelPermalink(), 125, 200)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, resizedAndRotated.RelPermalink(), 125, 200)
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_300x200_resize_q68_linear.jpg", resized.RelPermalink())
assert.Equal(300, resized.Width())
@@ -112,20 +115,20 @@ func TestImageTransform(t *testing.T) {
assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_bottomleft.jpg", filled.RelPermalink())
assert.Equal(200, filled.Width())
assert.Equal(100, filled.Height())
- assertFileCache(assert, image.spec.Fs, filled.RelPermalink(), 200, 100)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, filled.RelPermalink(), 200, 100)
smart, err := image.Fill("200x100 smart")
assert.NoError(err)
assert.Equal(fmt.Sprintf("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_200x100_fill_q68_linear_smart%d.jpg", smartCropVersionNumber), smart.RelPermalink())
assert.Equal(200, smart.Width())
assert.Equal(100, smart.Height())
- assertFileCache(assert, image.spec.Fs, smart.RelPermalink(), 200, 100)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, smart.RelPermalink(), 200, 100)
// Check cache
filledAgain, err := image.Fill("200x100 bottomLeft")
assert.NoError(err)
assert.True(filled == filledAgain)
- assertFileCache(assert, image.spec.Fs, filledAgain.RelPermalink(), 200, 100)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, filledAgain.RelPermalink(), 200, 100)
}
@@ -295,10 +298,10 @@ func TestImageResizeInSubPath(t *testing.T) {
assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resized.RelPermalink())
assert.Equal(101, resized.Width())
- assertFileCache(assert, image.spec.Fs, resized.RelPermalink(), 101, 101)
- publishedImageFilename := filepath.Join("/public", resized.RelPermalink())
- assertImageFile(assert, image.spec.Fs, publishedImageFilename, 101, 101)
- assert.NoError(image.spec.Fs.Destination.Remove(publishedImageFilename))
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, resized.RelPermalink(), 101, 101)
+ publishedImageFilename := filepath.Clean(resized.RelPermalink())
+ assertImageFile(assert, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
+ assert.NoError(image.spec.BaseFs.PublishFs.Remove(publishedImageFilename))
// Cleare mem cache to simulate reading from the file cache.
resized.spec.imageCache.clear()
@@ -307,8 +310,8 @@ func TestImageResizeInSubPath(t *testing.T) {
assert.NoError(err)
assert.Equal("/a/sub/gohugoio2_hu0e1b9e4a4be4d6f86c7b37b9ccce3fbc_73886_101x101_resize_linear_2.png", resizedAgain.RelPermalink())
assert.Equal(101, resizedAgain.Width())
- assertFileCache(assert, image.spec.Fs, resizedAgain.RelPermalink(), 101, 101)
- assertImageFile(assert, image.spec.Fs, publishedImageFilename, 101, 101)
+ assertFileCache(assert, image.spec.BaseFs.ResourcesFs, resizedAgain.RelPermalink(), 101, 101)
+ assertImageFile(assert, image.spec.BaseFs.PublishFs, publishedImageFilename, 101, 101)
}