2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2014-05-02 01:06:01 -04:00
|
|
|
//
|
2015-11-23 22:16:36 -05:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
2014-05-02 01:06:01 -04:00
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2015-11-23 22:16:36 -05:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2014-05-02 01:06:01 -04:00
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-04-09 19:36:03 -04:00
|
|
|
// Package create provides functions to create new content.
|
2014-05-02 01:06:01 -04:00
|
|
|
package create
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2021-10-13 02:12:06 -04:00
|
|
|
"fmt"
|
2018-09-19 01:48:17 -04:00
|
|
|
"io"
|
2014-05-02 01:06:01 -04:00
|
|
|
"os"
|
2014-11-06 10:51:14 -05:00
|
|
|
"path/filepath"
|
2018-09-19 01:48:17 -04:00
|
|
|
"strings"
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs/glob"
|
|
|
|
|
2021-06-18 04:27:27 -04:00
|
|
|
"github.com/gohugoio/hugo/common/paths"
|
|
|
|
|
2020-12-02 07:23:25 -05:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
|
2020-12-18 12:20:12 -05:00
|
|
|
"github.com/gohugoio/hugo/common/hexec"
|
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
|
|
|
"github.com/gohugoio/hugo/hugofs/files"
|
|
|
|
|
2018-09-19 01:48:17 -04:00
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
|
|
|
"github.com/gohugoio/hugo/hugolib"
|
2018-09-19 01:48:17 -04:00
|
|
|
"github.com/spf13/afero"
|
2014-05-02 01:06:01 -04:00
|
|
|
)
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
const (
|
|
|
|
// DefaultArchetypeTemplateTemplate is the template used in 'hugo new site'
|
|
|
|
// and the template we use as a fall back.
|
|
|
|
DefaultArchetypeTemplateTemplate = `---
|
|
|
|
title: "{{ replace .Name "-" " " | title }}"
|
|
|
|
date: {{ .Date }}
|
|
|
|
draft: true
|
|
|
|
---
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
`
|
|
|
|
)
|
2017-06-18 13:39:42 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
// NewContent creates a new content file in h (or a full bundle if the archetype is a directory)
|
|
|
|
// in targetPath.
|
|
|
|
func NewContent(h *hugolib.HugoSites, kind, targetPath string) error {
|
2021-10-19 02:08:21 -04:00
|
|
|
if h.BaseFs.Content.Dirs == nil {
|
|
|
|
return errors.New("no existing content directory configured for this project")
|
|
|
|
}
|
2021-10-17 05:54:55 -04:00
|
|
|
unlock, err := h.BaseFs.LockBuild()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("failed to acquire a build lock: %s", err)
|
|
|
|
}
|
|
|
|
defer unlock()
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
cf := hugolib.NewContentFactory(h)
|
2017-06-22 14:30:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
if kind == "" {
|
|
|
|
kind = cf.SectionFromFilename(targetPath)
|
|
|
|
}
|
2017-06-22 14:30:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
b := &contentBuilder{
|
|
|
|
archeTypeFs: h.PathSpec.BaseFs.Archetypes.Fs,
|
|
|
|
sourceFs: h.PathSpec.Fs.Source,
|
|
|
|
ps: h.PathSpec,
|
|
|
|
h: h,
|
|
|
|
cf: cf,
|
2017-06-18 13:39:42 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
kind: kind,
|
|
|
|
targetPath: targetPath,
|
2017-06-18 13:39:42 -04:00
|
|
|
}
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
ext := paths.Ext(targetPath)
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
b.setArcheTypeFilenameToUse(ext)
|
2018-10-26 03:41:24 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
if b.isDir {
|
|
|
|
return b.buildDir()
|
2014-05-02 01:06:01 -04:00
|
|
|
}
|
2016-03-17 14:30:33 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
if ext == "" {
|
|
|
|
return errors.Errorf("failed to resolve %q to a archetype template", targetPath)
|
2018-03-21 12:21:46 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
return b.buildFile()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type contentBuilder struct {
|
|
|
|
archeTypeFs afero.Fs
|
|
|
|
sourceFs afero.Fs
|
|
|
|
|
|
|
|
ps *helpers.PathSpec
|
|
|
|
h *hugolib.HugoSites
|
|
|
|
cf hugolib.ContentFactory
|
2016-03-17 14:30:33 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
// Builder state
|
|
|
|
archetypeFilename string
|
|
|
|
targetPath string
|
|
|
|
kind string
|
|
|
|
isDir bool
|
|
|
|
dirMap archetypeMap
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *contentBuilder) buildDir() error {
|
|
|
|
// Split the dir into content files and the rest.
|
|
|
|
if err := b.mapArcheTypeDir(); err != nil {
|
2014-05-02 01:06:01 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
var contentTargetFilenames []string
|
|
|
|
var baseDir string
|
2016-03-17 14:30:33 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
for _, fi := range b.dirMap.contentFiles {
|
|
|
|
targetFilename := filepath.Join(b.targetPath, strings.TrimPrefix(fi.Meta().Path, b.archetypeFilename))
|
|
|
|
abs, err := b.cf.CreateContentPlaceHolder(targetFilename)
|
2020-12-18 12:20:12 -05:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-13 02:12:06 -04:00
|
|
|
if baseDir == "" {
|
|
|
|
baseDir = strings.TrimSuffix(abs, targetFilename)
|
|
|
|
}
|
2016-03-17 14:30:33 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
contentTargetFilenames = append(contentTargetFilenames, abs)
|
2016-03-17 14:30:33 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
var contentInclusionFilter *glob.FilenameFilter
|
|
|
|
if !b.dirMap.siteUsed {
|
|
|
|
// We don't need to build everything.
|
|
|
|
contentInclusionFilter = glob.NewFilenameFilterForInclusionFunc(func(filename string) bool {
|
|
|
|
for _, cn := range contentTargetFilenames {
|
|
|
|
if strings.HasPrefix(cn, filename) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
2016-03-17 14:30:33 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
}
|
|
|
|
|
2021-10-17 05:54:55 -04:00
|
|
|
if err := b.h.Build(hugolib.BuildCfg{NoBuildLock: true, SkipRender: true, ContentInclusionFilter: contentInclusionFilter}); err != nil {
|
2021-10-13 02:12:06 -04:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, filename := range contentTargetFilenames {
|
|
|
|
if err := b.applyArcheType(filename, b.dirMap.contentFiles[i].Meta().Path); err != nil {
|
|
|
|
return err
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
// Copy the rest as is.
|
|
|
|
for _, f := range b.dirMap.otherFiles {
|
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
|
|
|
meta := f.Meta()
|
2021-07-13 05:41:02 -04:00
|
|
|
filename := meta.Path
|
2021-10-13 02:12:06 -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
|
|
|
in, err := meta.Open()
|
2018-09-19 01:48:17 -04:00
|
|
|
if err != nil {
|
2018-10-26 03:41:24 -04:00
|
|
|
return errors.Wrap(err, "failed to open non-content file")
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
targetFilename := filepath.Join(baseDir, b.targetPath, strings.TrimPrefix(filename, b.archetypeFilename))
|
2018-09-19 01:48:17 -04:00
|
|
|
targetDir := filepath.Dir(targetFilename)
|
2021-10-13 02:12:06 -04:00
|
|
|
|
|
|
|
if err := b.sourceFs.MkdirAll(targetDir, 0o777); err != nil && !os.IsExist(err) {
|
|
|
|
return errors.Wrapf(err, "failed to create target directory for %q", targetDir)
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
out, err := b.sourceFs.Create(targetFilename)
|
2019-03-24 05:11:16 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
|
|
|
_, err = io.Copy(out, in)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
in.Close()
|
|
|
|
out.Close()
|
|
|
|
}
|
2021-10-13 02:12:06 -04:00
|
|
|
return nil
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (b *contentBuilder) buildFile() error {
|
|
|
|
contentPlaceholderAbsFilename, err := b.cf.CreateContentPlaceHolder(b.targetPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
usesSite, err := b.usesSiteVar(b.archetypeFilename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
var contentInclusionFilter *glob.FilenameFilter
|
|
|
|
if !usesSite {
|
|
|
|
// We don't need to build everything.
|
|
|
|
contentInclusionFilter = glob.NewFilenameFilterForInclusionFunc(func(filename string) bool {
|
|
|
|
return strings.HasPrefix(contentPlaceholderAbsFilename, filename)
|
|
|
|
})
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-17 05:54:55 -04:00
|
|
|
if err := b.h.Build(hugolib.BuildCfg{NoBuildLock: true, SkipRender: true, ContentInclusionFilter: contentInclusionFilter}); err != nil {
|
2021-10-13 02:12:06 -04:00
|
|
|
return err
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
if err := b.applyArcheType(contentPlaceholderAbsFilename, b.archetypeFilename); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
b.h.Log.Infof("Content %q created", contentPlaceholderAbsFilename)
|
|
|
|
|
|
|
|
return b.openInEditorIfConfigured(contentPlaceholderAbsFilename)
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (b *contentBuilder) setArcheTypeFilenameToUse(ext string) {
|
|
|
|
var pathsToCheck []string
|
|
|
|
|
|
|
|
if b.kind != "" {
|
|
|
|
pathsToCheck = append(pathsToCheck, b.kind+ext)
|
|
|
|
}
|
|
|
|
pathsToCheck = append(pathsToCheck, "default"+ext, "default")
|
|
|
|
|
|
|
|
for _, p := range pathsToCheck {
|
|
|
|
fi, err := b.archeTypeFs.Stat(p)
|
|
|
|
if err == nil {
|
|
|
|
b.archetypeFilename = p
|
|
|
|
b.isDir = fi.IsDir()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (b *contentBuilder) applyArcheType(contentFilename, archetypeFilename string) error {
|
|
|
|
p := b.h.GetContentPage(contentFilename)
|
|
|
|
if p == nil {
|
|
|
|
panic(fmt.Sprintf("[BUG] no Page found for %q", contentFilename))
|
|
|
|
}
|
|
|
|
|
|
|
|
f, err := b.sourceFs.Create(contentFilename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
if archetypeFilename == "" {
|
|
|
|
return b.cf.AppplyArchetypeTemplate(f, p, b.kind, DefaultArchetypeTemplateTemplate)
|
|
|
|
}
|
|
|
|
|
|
|
|
return b.cf.AppplyArchetypeFilename(f, p, b.kind, archetypeFilename)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *contentBuilder) mapArcheTypeDir() error {
|
2018-09-19 01:48:17 -04:00
|
|
|
var m archetypeMap
|
|
|
|
|
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
|
|
|
walkFn := func(path string, fi hugofs.FileMetaInfo, err error) error {
|
2018-09-19 01:48:17 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if fi.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
fil := fi.(hugofs.FileMetaInfo)
|
2018-09-19 01:48:17 -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
|
|
|
if files.IsContentFile(path) {
|
2018-09-19 01:48:17 -04:00
|
|
|
m.contentFiles = append(m.contentFiles, fil)
|
|
|
|
if !m.siteUsed {
|
2021-10-13 02:12:06 -04:00
|
|
|
m.siteUsed, err = b.usesSiteVar(path)
|
2018-09-19 01:48:17 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
m.otherFiles = append(m.otherFiles, fil)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
walkCfg := hugofs.WalkwayConfig{
|
|
|
|
WalkFn: walkFn,
|
2021-10-13 02:12:06 -04:00
|
|
|
Fs: b.archeTypeFs,
|
|
|
|
Root: b.archetypeFilename,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
w := hugofs.NewWalkway(walkCfg)
|
|
|
|
|
|
|
|
if err := w.Walk(); err != nil {
|
2021-10-13 02:12:06 -04:00
|
|
|
return errors.Wrapf(err, "failed to walk archetype dir %q", b.archetypeFilename)
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
b.dirMap = m
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
return nil
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (b *contentBuilder) openInEditorIfConfigured(filename string) error {
|
|
|
|
editor := b.h.Cfg.GetString("newContentEditor")
|
|
|
|
if editor == "" {
|
|
|
|
return nil
|
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
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
b.h.Log.Infof("Editing %q with %q ...\n", filename, editor)
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
cmd, err := hexec.SafeCommand(editor, filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
cmd.Stdin = os.Stdin
|
|
|
|
cmd.Stdout = os.Stdout
|
|
|
|
cmd.Stderr = os.Stderr
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
return cmd.Run()
|
|
|
|
}
|
2018-09-19 01:48:17 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
func (b *contentBuilder) usesSiteVar(filename string) (bool, error) {
|
|
|
|
if filename == "" {
|
|
|
|
return false, nil
|
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
|
|
|
}
|
2021-10-13 02:12:06 -04:00
|
|
|
bb, err := afero.ReadFile(b.archeTypeFs, filename)
|
|
|
|
if err != nil {
|
|
|
|
return false, errors.Wrap(err, "failed to open archetype file")
|
2018-09-19 01:48:17 -04:00
|
|
|
}
|
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
return bytes.Contains(bb, []byte(".Site")) || bytes.Contains(bb, []byte("site.")), nil
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
}
|
2014-05-02 01:06:01 -04:00
|
|
|
|
2021-10-13 02:12:06 -04:00
|
|
|
type archetypeMap struct {
|
|
|
|
// These needs to be parsed and executed as Go templates.
|
|
|
|
contentFiles []hugofs.FileMetaInfo
|
|
|
|
// These are just copied to destination.
|
|
|
|
otherFiles []hugofs.FileMetaInfo
|
|
|
|
// If the templates needs a fully built site. This can potentially be
|
|
|
|
// expensive, so only do when needed.
|
|
|
|
siteUsed bool
|
2014-05-02 01:06:01 -04:00
|
|
|
}
|