2022-02-09 12:29:49 -05:00
|
|
|
//go:build mage
|
2017-10-02 22:29:31 -04:00
|
|
|
// +build mage
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"errors"
|
2017-10-21 11:37:00 -04:00
|
|
|
"fmt"
|
2017-10-02 22:29:31 -04:00
|
|
|
"os"
|
2018-05-04 11:53:56 -04:00
|
|
|
"path"
|
2017-10-02 22:29:31 -04:00
|
|
|
"path/filepath"
|
2017-10-21 12:44:49 -04:00
|
|
|
"runtime"
|
2017-10-02 22:29:31 -04:00
|
|
|
"strings"
|
2018-08-30 06:28:29 -04:00
|
|
|
"sync"
|
2017-10-02 22:29:31 -04:00
|
|
|
"time"
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/codegen"
|
|
|
|
"github.com/gohugoio/hugo/resources/page/page_generate"
|
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
"github.com/magefile/mage/mg"
|
|
|
|
"github.com/magefile/mage/sh"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
packageName = "github.com/gohugoio/hugo"
|
2022-03-17 04:27:11 -04:00
|
|
|
noGitLdflags = "-X github.com/gohugoio/hugo/common/hugo.vendorInfo=mage"
|
2017-10-02 22:29:31 -04:00
|
|
|
)
|
|
|
|
|
2022-03-17 04:27:11 -04:00
|
|
|
var ldflags = noGitLdflags
|
2017-10-02 22:29:31 -04:00
|
|
|
|
|
|
|
// allow user to override go executable by running as GOEXE=xxx make ... on unix-like systems
|
|
|
|
var goexe = "go"
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
if exe := os.Getenv("GOEXE"); exe != "" {
|
|
|
|
goexe = exe
|
|
|
|
}
|
2018-08-25 11:58:04 -04:00
|
|
|
|
|
|
|
// We want to use Go 1.11 modules even if the source lives inside GOPATH.
|
|
|
|
// The default is "auto".
|
|
|
|
os.Setenv("GO111MODULE", "on")
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func runWith(env map[string]string, cmd string, inArgs ...any) error {
|
2020-08-14 06:03:22 -04:00
|
|
|
s := argsToStrings(inArgs...)
|
|
|
|
return sh.RunWith(env, cmd, s...)
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
// Build hugo binary
|
|
|
|
func Hugo() error {
|
2020-08-14 06:03:22 -04:00
|
|
|
return runWith(flagEnv(), goexe, "build", "-ldflags", ldflags, buildFlags(), "-tags", buildTags(), packageName)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build hugo binary with race detector enabled
|
|
|
|
func HugoRace() error {
|
2020-08-14 06:03:22 -04:00
|
|
|
return runWith(flagEnv(), goexe, "build", "-race", "-ldflags", ldflags, buildFlags(), "-tags", buildTags(), packageName)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Install hugo binary
|
|
|
|
func Install() error {
|
2020-08-14 06:03:22 -04:00
|
|
|
return runWith(flagEnv(), goexe, "install", "-ldflags", ldflags, buildFlags(), "-tags", buildTags(), packageName)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
2020-07-24 12:52:31 -04:00
|
|
|
// Uninstall hugo binary
|
|
|
|
func Uninstall() error {
|
|
|
|
return sh.Run(goexe, "clean", "-i", packageName)
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
func flagEnv() map[string]string {
|
|
|
|
hash, _ := sh.Output("git", "rev-parse", "--short", "HEAD")
|
|
|
|
return map[string]string{
|
|
|
|
"PACKAGE": packageName,
|
|
|
|
"COMMIT_HASH": hash,
|
|
|
|
"BUILD_DATE": time.Now().Format("2006-01-02T15:04:05Z0700"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 11:48:37 -04:00
|
|
|
// Generate autogen packages
|
2018-05-04 11:53:56 -04:00
|
|
|
func Generate() error {
|
2019-01-02 06:33:26 -05:00
|
|
|
generatorPackages := []string{
|
2024-05-02 04:35:43 -04:00
|
|
|
"livereload/gen",
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, pkg := range generatorPackages {
|
2020-08-14 06:03:22 -04:00
|
|
|
if err := runWith(flagEnv(), goexe, "generate", path.Join(packageName, pkg)); err != nil {
|
2019-01-02 06:33:26 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dir, _ := os.Getwd()
|
|
|
|
c := codegen.NewInspector(dir)
|
|
|
|
|
|
|
|
if err := page_generate.Generate(c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
goFmtPatterns := []string{
|
|
|
|
// TODO(bep) check: stat ./resources/page/*autogen*: no such file or directory
|
|
|
|
"./resources/page/page_marshaljson.autogen.go",
|
|
|
|
"./resources/page/page_wrappers.autogen.go",
|
2019-03-25 13:18:34 -04:00
|
|
|
"./resources/page/zero_file.autogen.go",
|
2019-01-02 06:33:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, pattern := range goFmtPatterns {
|
|
|
|
if err := sh.Run("gofmt", "-w", filepath.FromSlash(pattern)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-05-04 11:53:56 -04:00
|
|
|
}
|
|
|
|
|
2020-06-05 11:48:37 -04:00
|
|
|
// Generate docs helper
|
|
|
|
func GenDocsHelper() error {
|
|
|
|
return runCmd(flagEnv(), goexe, "run", "-tags", buildTags(), "main.go", "gen", "docshelper")
|
|
|
|
}
|
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
// Build hugo without git info
|
2017-10-05 13:54:40 -04:00
|
|
|
func HugoNoGitInfo() error {
|
2017-10-02 22:29:31 -04:00
|
|
|
ldflags = noGitLdflags
|
2017-10-05 13:54:40 -04:00
|
|
|
return Hugo()
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var docker = sh.RunCmd("docker")
|
|
|
|
|
|
|
|
// Build hugo Docker container
|
|
|
|
func Docker() error {
|
|
|
|
if err := docker("build", "-t", "hugo", "."); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
// yes ignore errors here
|
|
|
|
docker("rm", "-f", "hugo-build")
|
|
|
|
if err := docker("run", "--name", "hugo-build", "hugo ls /go/bin"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := docker("cp", "hugo-build:/go/bin/hugo", "."); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return docker("rm", "hugo-build")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests and linters
|
|
|
|
func Check() {
|
2019-11-24 22:53:38 -05:00
|
|
|
if runtime.GOARCH == "amd64" && runtime.GOOS != "darwin" {
|
2019-10-31 20:04:54 -04:00
|
|
|
mg.Deps(Test386)
|
|
|
|
} else {
|
2019-11-24 22:53:38 -05:00
|
|
|
fmt.Printf("Skip Test386 on %s and/or %s\n", runtime.GOARCH, runtime.GOOS)
|
2019-10-31 20:04:54 -04:00
|
|
|
}
|
2018-08-30 06:28:29 -04:00
|
|
|
|
|
|
|
mg.Deps(Fmt, Vet)
|
|
|
|
|
2017-10-18 01:56:10 -04:00
|
|
|
// don't run two tests in parallel, they saturate the CPUs anyway, and running two
|
|
|
|
// causes memory issues in CI.
|
|
|
|
mg.Deps(TestRace)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func testGoFlags() string {
|
|
|
|
if isCI() {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2022-03-18 03:54:44 -04:00
|
|
|
return "-timeout=1m"
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
// Run tests in 32-bit mode
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
// Note that we don't run with the extended tag. Currently not supported in 32 bit.
|
2017-10-02 22:29:31 -04:00
|
|
|
func Test386() error {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
env := map[string]string{"GOARCH": "386", "GOFLAGS": testGoFlags()}
|
2024-05-29 07:23:36 -04:00
|
|
|
return runCmd(env, goexe, "test", "-p", "2", "./...")
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests
|
|
|
|
func Test() error {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
env := map[string]string{"GOFLAGS": testGoFlags()}
|
2024-05-29 07:23:36 -04:00
|
|
|
return runCmd(env, goexe, "test", "-p", "2", "./...", "-tags", buildTags())
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run tests with race detector
|
|
|
|
func TestRace() error {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
env := map[string]string{"GOFLAGS": testGoFlags()}
|
2024-05-29 07:23:36 -04:00
|
|
|
return runCmd(env, goexe, "test", "-p", "2", "-race", "./...", "-tags", buildTags())
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run gofmt linter
|
|
|
|
func Fmt() error {
|
2024-01-30 05:43:20 -05:00
|
|
|
if !isGoLatest() && !isUnix() {
|
2017-12-07 16:38:54 -05:00
|
|
|
return nil
|
|
|
|
}
|
2024-01-30 05:43:20 -05:00
|
|
|
s, err := sh.Output("./check_gofmt.sh")
|
2017-10-02 22:29:31 -04:00
|
|
|
if err != nil {
|
2024-01-30 05:43:20 -05:00
|
|
|
fmt.Println(s)
|
|
|
|
return fmt.Errorf("gofmt needs to be run: %s", err)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
2024-01-30 05:43:20 -05:00
|
|
|
|
2017-10-02 22:29:31 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-08-30 06:28:29 -04:00
|
|
|
var (
|
|
|
|
pkgPrefixLen = len("github.com/gohugoio/hugo")
|
|
|
|
pkgs []string
|
|
|
|
pkgsInit sync.Once
|
|
|
|
)
|
2017-10-02 22:29:31 -04:00
|
|
|
|
|
|
|
func hugoPackages() ([]string, error) {
|
2018-08-30 06:28:29 -04:00
|
|
|
var err error
|
|
|
|
pkgsInit.Do(func() {
|
|
|
|
var s string
|
|
|
|
s, err = sh.Output(goexe, "list", "./...")
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
pkgs = strings.Split(s, "\n")
|
|
|
|
for i := range pkgs {
|
|
|
|
pkgs[i] = "." + pkgs[i][pkgPrefixLen:]
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return pkgs, err
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run golint linter
|
|
|
|
func Lint() error {
|
|
|
|
pkgs, err := hugoPackages()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
failed := false
|
|
|
|
for _, pkg := range pkgs {
|
2017-10-21 11:37:00 -04:00
|
|
|
// We don't actually want to fail this target if we find golint errors,
|
|
|
|
// so we don't pass -set_exit_status, but we still print out any failures.
|
|
|
|
if _, err := sh.Exec(nil, os.Stderr, nil, "golint", pkg); err != nil {
|
|
|
|
fmt.Printf("ERROR: running go lint on %q: %v\n", pkg, err)
|
2017-10-02 22:29:31 -04:00
|
|
|
failed = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if failed {
|
2017-10-21 11:37:00 -04:00
|
|
|
return errors.New("errors running golint")
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-12-14 06:20:13 -05:00
|
|
|
// Run go vet linter
|
2017-10-02 22:29:31 -04:00
|
|
|
func Vet() error {
|
2017-10-21 10:19:04 -04:00
|
|
|
if err := sh.Run(goexe, "vet", "./..."); err != nil {
|
2018-08-30 16:30:49 -04:00
|
|
|
return fmt.Errorf("error running go vet: %v", err)
|
2017-10-02 22:29:31 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate test coverage report
|
|
|
|
func TestCoverHTML() error {
|
|
|
|
const (
|
|
|
|
coverAll = "coverage-all.out"
|
|
|
|
cover = "coverage.out"
|
|
|
|
)
|
|
|
|
f, err := os.Create(coverAll)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
if _, err := f.Write([]byte("mode: count")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
pkgs, err := hugoPackages()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, pkg := range pkgs {
|
2017-10-21 10:19:04 -04:00
|
|
|
if err := sh.Run(goexe, "test", "-coverprofile="+cover, "-covermode=count", pkg); err != nil {
|
2017-10-02 22:29:31 -04:00
|
|
|
return err
|
|
|
|
}
|
2023-03-01 03:34:13 -05:00
|
|
|
b, err := os.ReadFile(cover)
|
2017-10-02 22:29:31 -04:00
|
|
|
if err != nil {
|
2018-01-15 14:40:39 -05:00
|
|
|
if os.IsNotExist(err) {
|
|
|
|
continue
|
|
|
|
}
|
2017-10-02 22:29:31 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
idx := bytes.Index(b, []byte{'\n'})
|
|
|
|
b = b[idx+1:]
|
|
|
|
if _, err := f.Write(b); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := f.Close(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return sh.Run(goexe, "tool", "cover", "-html="+coverAll)
|
|
|
|
}
|
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func runCmd(env map[string]string, cmd string, args ...any) error {
|
2019-11-25 05:26:47 -05:00
|
|
|
if mg.Verbose() {
|
2020-08-14 06:03:22 -04:00
|
|
|
return runWith(env, cmd, args...)
|
2019-11-25 05:26:47 -05:00
|
|
|
}
|
2020-08-14 06:03:22 -04:00
|
|
|
output, err := sh.OutputWith(env, cmd, argsToStrings(args...)...)
|
2019-11-25 05:26:47 -05:00
|
|
|
if err != nil {
|
|
|
|
fmt.Fprint(os.Stderr, output)
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-02-21 03:23:43 -05:00
|
|
|
func isGoLatest() bool {
|
2023-10-04 04:28:10 -04:00
|
|
|
return strings.Contains(runtime.Version(), "1.21")
|
2017-12-07 16:38:54 -05:00
|
|
|
}
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
|
2024-01-30 05:43:20 -05:00
|
|
|
func isUnix() bool {
|
|
|
|
return runtime.GOOS != "windows"
|
|
|
|
}
|
|
|
|
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
func isCI() bool {
|
|
|
|
return os.Getenv("CI") != ""
|
|
|
|
}
|
|
|
|
|
2020-08-14 06:03:22 -04:00
|
|
|
func buildFlags() []string {
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
return []string{"-buildmode", "exe"}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
func buildTags() string {
|
|
|
|
// To build the extended Hugo SCSS/SASS enabled version, build with
|
|
|
|
// HUGO_BUILD_TAGS=extended mage install etc.
|
2020-10-23 03:03:41 -04:00
|
|
|
// To build without `hugo deploy` for smaller binary, use HUGO_BUILD_TAGS=nodeploy
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
if envtags := os.Getenv("HUGO_BUILD_TAGS"); envtags != "" {
|
|
|
|
return envtags
|
|
|
|
}
|
|
|
|
return "none"
|
|
|
|
}
|
2020-08-14 06:03:22 -04:00
|
|
|
|
2022-03-17 17:03:27 -04:00
|
|
|
func argsToStrings(v ...any) []string {
|
2020-08-14 06:03:22 -04:00
|
|
|
var args []string
|
|
|
|
for _, arg := range v {
|
|
|
|
switch v := arg.(type) {
|
|
|
|
case string:
|
|
|
|
if v != "" {
|
|
|
|
args = append(args, v)
|
|
|
|
}
|
|
|
|
case []string:
|
|
|
|
if v != nil {
|
|
|
|
args = append(args, v...)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
panic("invalid type")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return args
|
|
|
|
}
|