@@ -34,10 +34,60 @@ var siteFs embed.FS
3434var themeFs embed.FS
3535
3636// CreateTheme creates a theme skeleton.
37- func CreateTheme (createpath string , sourceFs afero.Fs ) error {
37+ func CreateTheme (createpath string , sourceFs afero.Fs , format string ) error {
3838 if exists , _ := helpers .Exists (createpath , sourceFs ); exists {
3939 return errors .New (createpath + " already exists" )
4040 }
41+
42+ format = strings .ToLower (format )
43+
44+ siteConfig := map [string ]any {
45+ "baseURL" : "https://example.org/" ,
46+ "languageCode" : "en-US" ,
47+ "title" : "My New Hugo Site" ,
48+ "menus" : map [string ]any {
49+ "main" : []any {
50+ map [string ]any {
51+ "name" : "Home" ,
52+ "pageRef" : "/" ,
53+ "weight" : 10 ,
54+ },
55+ map [string ]any {
56+ "name" : "Posts" ,
57+ "pageRef" : "/posts" ,
58+ "weight" : 20 ,
59+ },
60+ map [string ]any {
61+ "name" : "Tags" ,
62+ "pageRef" : "/tags" ,
63+ "weight" : 30 ,
64+ },
65+ },
66+ },
67+ "module" : map [string ]any {
68+ "hugoVersion" : map [string ]any {
69+ "extended" : false ,
70+ "min" : "0.116.0" ,
71+ },
72+ },
73+ }
74+
75+ err := createSiteConfig (sourceFs , createpath , siteConfig , format )
76+ if err != nil {
77+ return err
78+ }
79+
80+ defaultArchetype := map [string ]any {
81+ "title" : "{{ replace .File.ContentBaseName \" -\" \" \" | title }}" ,
82+ "date" : "{{ .Date }}" ,
83+ "draft" : true ,
84+ }
85+
86+ err = createDefaultArchetype (sourceFs , createpath , defaultArchetype , format )
87+ if err != nil {
88+ return err
89+ }
90+
4191 return copyFiles (createpath , sourceFs , themeFs )
4292}
4393
@@ -71,12 +121,24 @@ func CreateSite(createpath string, sourceFs afero.Fs, force bool, format string)
71121 }
72122 }
73123
74- err := newSiteCreateConfig (sourceFs , createpath , format )
124+ siteConfig := map [string ]any {
125+ "baseURL" : "https://example.org/" ,
126+ "title" : "My New Hugo Site" ,
127+ "languageCode" : "en-us" ,
128+ }
129+
130+ err := createSiteConfig (sourceFs , createpath , siteConfig , format )
75131 if err != nil {
76132 return err
77133 }
78134
79- err = newSiteCreateArchetype (sourceFs , createpath , format )
135+ defaultArchetype := map [string ]any {
136+ "title" : "{{ replace .File.ContentBaseName \" -\" \" \" | title }}" ,
137+ "date" : "{{ .Date }}" ,
138+ "draft" : true ,
139+ }
140+
141+ err = createDefaultArchetype (sourceFs , createpath , defaultArchetype , format )
80142 if err != nil {
81143 return err
82144 }
@@ -99,13 +161,7 @@ func copyFiles(createpath string, sourceFs afero.Fs, skeleton embed.FS) error {
99161 })
100162}
101163
102- func newSiteCreateConfig (fs afero.Fs , createpath string , format string ) (err error ) {
103- in := map [string ]string {
104- "baseURL" : "https://example.org/" ,
105- "title" : "My New Hugo Site" ,
106- "languageCode" : "en-us" ,
107- }
108-
164+ func createSiteConfig (fs afero.Fs , createpath string , in map [string ]any , format string ) (err error ) {
109165 var buf bytes.Buffer
110166 err = parser .InterfaceToConfig (in , metadecoders .FormatFromString (format ), & buf )
111167 if err != nil {
@@ -115,13 +171,7 @@ func newSiteCreateConfig(fs afero.Fs, createpath string, format string) (err err
115171 return helpers .WriteToDisk (filepath .Join (createpath , "hugo." + format ), & buf , fs )
116172}
117173
118- func newSiteCreateArchetype (fs afero.Fs , createpath string , format string ) (err error ) {
119- in := map [string ]any {
120- "title" : "{{ replace .File.ContentBaseName \" -\" \" \" | title }}" ,
121- "date" : "{{ .Date }}" ,
122- "draft" : true ,
123- }
124-
174+ func createDefaultArchetype (fs afero.Fs , createpath string , in map [string ]any , format string ) (err error ) {
125175 var buf bytes.Buffer
126176 err = parser .InterfaceToFrontMatter (in , metadecoders .FormatFromString (format ), & buf )
127177 if err != nil {
0 commit comments