[commands/new.go] Update theme.toml etc.

- Add copyright years and author to the top of the file

- Write the current year from time.Now() to LICENSE.md

- Correct comment regarding `os.MkdirAll(p, 0777)`

- In createConfig(), split the `map[string]string` definition into
  multiple lines to facilitate future expansion.  Also add a trailing
  slash to sample "baseurl" definition.

- Update theme.toml template to match that listed at
  https://github.com/spf13/hugoThemes/blob/master/README.md#themetoml

  See #883 for an equivalent `struct` implementation
This commit is contained in:
Anthony Fok 2015-02-08 08:11:04 -07:00
parent 87975e04eb
commit d10e05f2e3

View file

@ -1,3 +1,5 @@
// Copyright © 2014-2015 Steve Francia <spf@spf13.com>.
//
// Licensed under the Simple Public License, Version 2.0 (the "License"); // Licensed under the Simple Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
// You may obtain a copy of the License at // You may obtain a copy of the License at
@ -16,6 +18,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/hugo/create" "github.com/spf13/hugo/create"
@ -72,7 +75,7 @@ as you see fit.
Run: NewTheme, Run: NewTheme,
} }
//NewContent adds new content to a Hugo site. // NewContent adds new content to a Hugo site.
func NewContent(cmd *cobra.Command, args []string) { func NewContent(cmd *cobra.Command, args []string) {
InitializeConfig() InitializeConfig()
@ -135,7 +138,7 @@ func NewSite(cmd *cobra.Command, args []string) {
createConfig(createpath, configFormat) createConfig(createpath, configFormat)
} }
//NewTheme creates a new Hugo theme. // NewTheme creates a new Hugo theme.
func NewTheme(cmd *cobra.Command, args []string) { func NewTheme(cmd *cobra.Command, args []string) {
InitializeConfig() InitializeConfig()
@ -169,7 +172,7 @@ func NewTheme(cmd *cobra.Command, args []string) {
by := []byte(`The MIT License (MIT) by := []byte(`The MIT License (MIT)
Copyright (c) 2014 YOUR_NAME_HERE Copyright (c) ` + time.Now().Format("2006") + ` YOUR_NAME_HERE
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in
@ -200,7 +203,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
func mkdir(x ...string) { func mkdir(x ...string) {
p := filepath.Join(x...) p := filepath.Join(x...)
err := os.MkdirAll(p, 0777) // rwx, rw, r err := os.MkdirAll(p, 0777) // before umask
if err != nil { if err != nil {
jww.FATAL.Fatalln(err) jww.FATAL.Fatalln(err)
} }
@ -217,19 +220,24 @@ func touchFile(x ...string) {
func createThemeMD(inpath string) (err error) { func createThemeMD(inpath string) (err error) {
in := map[string]interface{}{ by := []byte(`name = "` + strings.Title(helpers.MakeTitle(filepath.Base(inpath))) + `"
"name": helpers.MakeTitle(filepath.Base(inpath)), license = "MIT"
"license": "MIT", licenselink = "https://github.com/.../.../LICENSE.md"
"source_repo": "", description = ""
"author": "", homepage = "http://siteforthistheme.com/"
"description": "", tags = ["", ""]
"tags": []string{"", ""}, features = ["", ""]
}
by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune("toml")) [author]
if err != nil { name = ""
return err homepage = ""
}
# If porting an existing theme
[original]
name = ""
homepage = ""
repo = ""
`)
err = helpers.WriteToDisk(filepath.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs) err = helpers.WriteToDisk(filepath.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs)
if err != nil { if err != nil {
@ -240,7 +248,11 @@ func createThemeMD(inpath string) (err error) {
} }
func createConfig(inpath string, kind string) (err error) { func createConfig(inpath string, kind string) (err error) {
in := map[string]string{"baseurl": "http://yourSiteHere", "title": "my new hugo site", "languageCode": "en-us"} in := map[string]string{
"baseurl": "http://yourSiteHere/",
"title": "My New Hugo Site",
"languageCode": "en-us",
}
kind = parser.FormatSanitize(kind) kind = parser.FormatSanitize(kind)
by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind)) by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind))