| 1 |
// Copyright 2025 The Hugo Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package hugolib |
| 15 |
|
| 16 |
import ( |
| 17 |
"testing" |
| 18 |
) |
| 19 |
|
| 20 |
func TestMountFilters(t *testing.T) { |
| 21 |
t.Parallel() |
| 22 |
|
| 23 |
files := ` |
| 24 |
-- hugo.toml -- |
| 25 |
baseURL = "http://example.com/" |
| 26 |
[module] |
| 27 |
[[module.mounts]] |
| 28 |
source = 'content' |
| 29 |
target = 'content' |
| 30 |
files = "! /a/c/**" |
| 31 |
[[module.mounts]] |
| 32 |
source = 'static' |
| 33 |
target = 'static' |
| 34 |
[[module.mounts]] |
| 35 |
source = 'layouts' |
| 36 |
target = 'layouts' |
| 37 |
files = "! /**/foo.html" |
| 38 |
[[module.mounts]] |
| 39 |
source = 'data' |
| 40 |
target = 'data' |
| 41 |
files = "/mydata/**" |
| 42 |
[[module.mounts]] |
| 43 |
source = 'assets' |
| 44 |
target = 'assets' |
| 45 |
files = ["! /**exclude.*", "! /moooo.*"] |
| 46 |
[[module.mounts]] |
| 47 |
source = 'i18n' |
| 48 |
target = 'i18n' |
| 49 |
[[module.mounts]] |
| 50 |
source = 'archetypes' |
| 51 |
target = 'archetypes' |
| 52 |
-- layouts/single.html -- |
| 53 |
Single page. |
| 54 |
-- content/a/b/p1.md -- |
| 55 |
--- |
| 56 |
title: Include |
| 57 |
--- |
| 58 |
-- content/a/c/p2.md -- |
| 59 |
--- |
| 60 |
title: Exclude |
| 61 |
--- |
| 62 |
-- data/mydata/b.toml -- |
| 63 |
b1='bval' |
| 64 |
-- data/nodata/c.toml -- |
| 65 |
c1='bval' |
| 66 |
-- layouts/_partials/foo.html -- |
| 67 |
foo |
| 68 |
-- assets/exclude.txt -- |
| 69 |
foo |
| 70 |
-- assets/js/exclude.js -- |
| 71 |
foo |
| 72 |
-- assets/js/include.js -- |
| 73 |
foo |
| 74 |
-- layouts/home.html -- |
| 75 |
Data: {{ hugo.Data }}:END |
| 76 |
|
| 77 |
Template: {{ templates.Exists "partials/foo.html" }}:END |
| 78 |
Resource1: {{ resources.Get "js/include.js" }}:END |
| 79 |
Resource2: {{ resources.Get "js/exclude.js" }}:END |
| 80 |
Resource3: {{ resources.Get "exclude.txt" }}:END |
| 81 |
Resources: {{ resources.Match "**.js" }} |
| 82 |
` |
| 83 |
b := Test(t, files) |
| 84 |
|
| 85 |
b.AssertFileExists("public/a/b/p1/index.html", true) |
| 86 |
b.AssertFileExists("public/a/c/p2/index.html", false) |
| 87 |
|
| 88 |
b.AssertFileContent("public/index.html", ` |
| 89 |
Data: map[mydata:map[b:map[b1:bval]]]:END |
| 90 |
Template: false |
| 91 |
Resource1: /js/include.js:END |
| 92 |
Resource2: :END |
| 93 |
Resource3: :END |
| 94 |
Resources: [/js/include.js] |
| 95 |
`) |
| 96 |
} |