Only set 'url' if permalink in metadata and remove duplicate confirm msg
authorColin Seymour <lildood@gmail.com>
Thu, 11 Jan 2018 16:42:49 +0000 (16:42 +0000)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 28 Jan 2018 10:24:31 +0000 (11:24 +0100)
The current behaviour addes a `url` attribute to the frontmatter of all posts imported from Jeklly and assumes the desired permalink structure is /:year/:month/:day/:title/. This may be the case for most peeps, but poses a problem for those that don't use this permalink structure as the `url` attribute takes precedence over the `permalink` attribute in the site-wide configuration meaning it can't be overruled.

This changes the behaviour to only set the `url` attribute if the `permalink` attribute is set in the Jekyll frontmatter.

The duplication of the confirmation message is also removed.

Tests have been updated to reflect this change in behaviour.

Fixes #1887

commands/import_jekyll.go
commands/import_jekyll_test.go

index 327bf6095b9e045973cb5be59186500eea18e9c4..8c9c4d093d83d4b585e8a319e2f12ef415cc2692 100644 (file)
@@ -144,11 +144,6 @@ func importFromJekyll(cmd *cobra.Command, args []string) error {
                "$ git clone https://github.com/spf13/herring-cove.git " + args[1] + "/themes/herring-cove")
        jww.FEEDBACK.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")
 
-       jww.FEEDBACK.Println("Congratulations!", fileCount, "post(s) imported!")
-       jww.FEEDBACK.Println("Now, start Hugo by yourself:\n" +
-               "$ git clone https://github.com/spf13/herring-cove.git " + args[1] + "/themes/herring-cove")
-       jww.FEEDBACK.Println("$ cd " + args[1] + "\n$ hugo server --theme=herring-cove")
-
        return nil
 }
 
@@ -478,8 +473,6 @@ func convertJekyllPost(s *hugolib.Site, path, relPath, targetDir string, draft b
 }
 
 func convertJekyllMetaData(m interface{}, postName string, postDate time.Time, draft bool) (interface{}, error) {
-       url := postDate.Format("/2006/01/02/") + postName + "/"
-
        metadata, err := cast.ToStringMapE(m)
        if err != nil {
                return nil, err
@@ -497,7 +490,7 @@ func convertJekyllMetaData(m interface{}, postName string, postDate time.Time, d
                        delete(metadata, key)
                case "permalink":
                        if str, ok := value.(string); ok {
-                               url = str
+                               metadata["url"] = str
                        }
                        delete(metadata, key)
                case "category":
@@ -526,7 +519,6 @@ func convertJekyllMetaData(m interface{}, postName string, postDate time.Time, d
 
        }
 
-       metadata["url"] = url
        metadata["date"] = postDate.Format(time.RFC3339)
 
        return metadata, nil
index 90a05c01cac2ed49c5971bf9063b844844cb150e..cb22e9cd79db19c1e0660dd57da00ccfeaddca14 100644 (file)
@@ -51,9 +51,9 @@ func TestConvertJekyllMetadata(t *testing.T) {
                expect   string
        }{
                {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false,
-                       `{"date":"2015-10-01T00:00:00Z","url":"/2015/10/01/testPost/"}`},
+                       `{"date":"2015-10-01T00:00:00Z"}`},
                {map[interface{}]interface{}{}, "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), true,
-                       `{"date":"2015-10-01T00:00:00Z","draft":true,"url":"/2015/10/01/testPost/"}`},
+                       `{"date":"2015-10-01T00:00:00Z","draft":true}`},
                {map[interface{}]interface{}{"Permalink": "/permalink.html", "layout": "post"},
                        "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false,
                        `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`},
@@ -62,13 +62,13 @@ func TestConvertJekyllMetadata(t *testing.T) {
                        `{"date":"2015-10-01T00:00:00Z","url":"/permalink.html"}`},
                {map[interface{}]interface{}{"category": nil, "permalink": 123},
                        "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false,
-                       `{"date":"2015-10-01T00:00:00Z","url":"/2015/10/01/testPost/"}`},
+                       `{"date":"2015-10-01T00:00:00Z"}`},
                {map[interface{}]interface{}{"Excerpt_Separator": "sep"},
                        "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false,
-                       `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep","url":"/2015/10/01/testPost/"}`},
+                       `{"date":"2015-10-01T00:00:00Z","excerpt_separator":"sep"}`},
                {map[interface{}]interface{}{"category": "book", "layout": "post", "Others": "Goods", "Date": "2015-10-01 12:13:11"},
                        "testPost", time.Date(2015, 10, 1, 0, 0, 0, 0, time.UTC), false,
-                       `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z","url":"/2015/10/01/testPost/"}`},
+                       `{"Others":"Goods","categories":["book"],"date":"2015-10-01T12:13:11Z"}`},
        }
 
        for _, data := range testDataList {