Exemple #1
0
func printHugoVersion() {
	if hugolib.BuildDate == "" {
		setBuildDate() // set the build date from executable's mdate
	} else {
		formatBuildDate() // format the compile time
	}
	if hugolib.CommitHash == "" {
		fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", helpers.HugoVersion(), hugolib.BuildDate)
	} else {
		fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
	}
}
Exemple #2
0
func init() {
	hugoInfo = &HugoInfo{
		Version:    helpers.HugoVersion(),
		CommitHash: CommitHash,
		BuildDate:  BuildDate,
		Generator:  template.HTML(fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, helpers.HugoVersion())),
	}
}
Exemple #3
0
	jww "github.com/spf13/jwalterweatherman"
)

var genmandir string
var genmanCmd = &cobra.Command{
	Use:   "man",
	Short: "Generate man pages for the Hugo CLI",
	Long: `This command automatically generates up-to-date man pages of Hugo's
command-line interface.  By default, it creates the man page files
in the "man" directory under the current directory.`,

	Run: func(cmd *cobra.Command, args []string) {
		header := &cobra.GenManHeader{
			Section: "1",
			Manual:  "Hugo Manual",
			Source:  fmt.Sprintf("Hugo %s", helpers.HugoVersion()),
		}
		if !strings.HasSuffix(genmandir, helpers.FilePathSeparator) {
			genmandir += helpers.FilePathSeparator
		}
		if found, _ := helpers.Exists(genmandir, hugofs.OsFs); !found {
			jww.FEEDBACK.Println("Directory", genmandir, "does not exist, creating...")
			hugofs.OsFs.MkdirAll(genmandir, 0777)
		}
		cmd.Root().DisableAutoGenTag = true

		jww.FEEDBACK.Println("Generating Hugo man pages in", genmandir, "...")
		cmd.Root().GenManTree(header, genmandir)

		jww.FEEDBACK.Println("Done.")
	},
Exemple #4
0
	"github.com/spf13/hugo/helpers"
	"github.com/spf13/hugo/hugolib"
)

var versionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version number of Hugo",
	Long:  `All software has versions. This is Hugo's.`,
	RunE: func(cmd *cobra.Command, args []string) error {
		if hugolib.BuildDate == "" {
			setBuildDate() // set the build date from executable's mdate
		} else {
			formatBuildDate() // format the compile time
		}
		if hugolib.CommitHash == "" {
			fmt.Printf("Hugo Static Site Generator v%s BuildDate: %s\n", helpers.HugoVersion(), hugolib.BuildDate)
		} else {
			fmt.Printf("Hugo Static Site Generator v%s-%s BuildDate: %s\n", helpers.HugoVersion(), strings.ToUpper(hugolib.CommitHash), hugolib.BuildDate)
		}

		return nil
	},
}

// setBuildDate checks the ModTime of the Hugo executable and returns it as a
// formatted string.  This assumes that the executable name is Hugo, if it does
// not exist, an empty string will be returned.  This is only called if the
// hugolib.BuildDate wasn't set during compile time.
//
// osext is used for cross-platform.
func setBuildDate() {
// 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.

package transform

import (
	"bytes"
	"fmt"
	"regexp"

	"github.com/spf13/hugo/helpers"
)

var metaTagsCheck = regexp.MustCompile(`(?i)<meta\s+name=['|"]?generator['|"]?`)
var hugoGeneratorTag = fmt.Sprintf(`<meta name="generator" content="Hugo %s" />`, helpers.HugoVersion())

func HugoGeneratorInject(ct contentTransformer) {
	if metaTagsCheck.Match(ct.Content()) {
		ct.Write(ct.Content())
		return
	}

	head := "<head>"
	replace := []byte(fmt.Sprintf("%s\n\t%s", head, hugoGeneratorTag))
	newcontent := bytes.Replace(ct.Content(), []byte(head), replace, 1)

	if len(newcontent) == len(ct.Content()) {
		head := "<HEAD>"
		replace := []byte(fmt.Sprintf("%s\n\t%s", head, hugoGeneratorTag))
		newcontent = bytes.Replace(ct.Content(), []byte(head), replace, 1)