github.com/neohugo/neohugo@v0.123.8/hugolib/minify_publisher_test.go (about)

     1  // Copyright 2019 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  	"github.com/neohugo/neohugo/config"
    20  )
    21  
    22  func TestMinifyPublisher(t *testing.T) {
    23  	t.Parallel()
    24  
    25  	v := config.New()
    26  	v.Set("minify", true)
    27  	v.Set("baseURL", "https://example.org/")
    28  
    29  	htmlTemplate := `
    30  <!DOCTYPE html>
    31  <html lang="en">
    32  <head>
    33  	<meta charset="utf-8">
    34  	<title>HTML5 boilerplate – all you really need…</title>
    35  	<link rel="stylesheet" href="css/style.css">
    36  	<!--[if IE]>
    37  		<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    38  	<![endif]-->
    39  </head>
    40  
    41  <body id="home">
    42  
    43  	<h1>{{ .Title }}</h1>
    44  	<p>{{ .Permalink }}</p>
    45  
    46  </body>
    47  </html>
    48  `
    49  
    50  	b := newTestSitesBuilder(t)
    51  	b.WithViper(v).WithTemplatesAdded("layouts/index.html", htmlTemplate)
    52  	b.CreateSites().Build(BuildCfg{})
    53  
    54  	// Check minification
    55  	// HTML
    56  	b.AssertFileContent("public/index.html", "<!doctype html>")
    57  
    58  	// RSS
    59  	b.AssertFileContent("public/index.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel><title/><link>https://example.org/</link>")
    60  
    61  	// Sitemap
    62  	b.AssertFileContent("public/sitemap.xml", "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns:xhtml=\"http://www.w3.org/1999/xhtml\"><url><loc>h")
    63  }