[commands/new.go] Update theme.toml etc.
authorAnthony Fok <foka@debian.org>
Sun, 8 Feb 2015 15:11:04 +0000 (08:11 -0700)
committerAnthony Fok <foka@debian.org>
Fri, 13 Feb 2015 22:00:17 +0000 (15:00 -0700)
- 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

commands/new.go

index cc0a6394134edd3e26df5d96efe8823e1057a3bf..781351e46382c5764b37a2dbe1c3eb074c51d490 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright © 2014-2015 Steve Francia <spf@spf13.com>.
+//
 // 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 obtain a copy of the License at
@@ -16,6 +18,7 @@ import (
        "os"
        "path/filepath"
        "strings"
+       "time"
 
        "github.com/spf13/cobra"
        "github.com/spf13/hugo/create"
@@ -72,7 +75,7 @@ as you see fit.
        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) {
        InitializeConfig()
 
@@ -135,7 +138,7 @@ func NewSite(cmd *cobra.Command, args []string) {
        createConfig(createpath, configFormat)
 }
 
-//NewTheme creates a new Hugo theme.
+// NewTheme creates a new Hugo theme.
 func NewTheme(cmd *cobra.Command, args []string) {
        InitializeConfig()
 
@@ -169,7 +172,7 @@ func NewTheme(cmd *cobra.Command, args []string) {
 
        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
 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) {
        p := filepath.Join(x...)
 
-       err := os.MkdirAll(p, 0777) // rwx, rw, r
+       err := os.MkdirAll(p, 0777) // before umask
        if err != nil {
                jww.FATAL.Fatalln(err)
        }
@@ -217,19 +220,24 @@ func touchFile(x ...string) {
 
 func createThemeMD(inpath string) (err error) {
 
-       in := map[string]interface{}{
-               "name":        helpers.MakeTitle(filepath.Base(inpath)),
-               "license":     "MIT",
-               "source_repo": "",
-               "author":      "",
-               "description": "",
-               "tags":        []string{"", ""},
-       }
-
-       by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune("toml"))
-       if err != nil {
-               return err
-       }
+       by := []byte(`name = "` + strings.Title(helpers.MakeTitle(filepath.Base(inpath))) + `"
+license = "MIT"
+licenselink = "https://github.com/.../.../LICENSE.md"
+description = ""
+homepage = "http://siteforthistheme.com/"
+tags = ["", ""]
+features = ["", ""]
+
+[author]
+  name = ""
+  homepage = ""
+
+# If porting an existing theme
+[original]
+  name = ""
+  homepage = ""
+  repo = ""
+`)
 
        err = helpers.WriteToDisk(filepath.Join(inpath, "theme.toml"), bytes.NewReader(by), hugofs.SourceFs)
        if err != nil {
@@ -240,7 +248,11 @@ func createThemeMD(inpath 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)
 
        by, err := parser.InterfaceToConfig(in, parser.FormatToLeadRune(kind))