7
7
"os"
8
8
"os/exec"
9
9
"path"
10
+ "runtime"
10
11
"strings"
11
12
"time"
12
13
@@ -164,17 +165,25 @@ func (g Generator) setupHugo(outputDirPath string) (*string, error) {
164
165
return nil , fmt .Errorf ("hugo not found, install it from https://gohugo.io/: %s" , err )
165
166
}
166
167
168
+ // Create output directory
169
+ err = os .MkdirAll (outputDirPath , 0700 )
170
+ if err != nil {
171
+ log .Fatal ().
172
+ Err (err ).
173
+ Str ("outputDirPath" , outputDirPath ).
174
+ Msg ("error creating output directory" )
175
+ return nil , fmt .Errorf ("error creating output directory '%s': %s" , outputDirPath , err )
176
+ }
177
+
167
178
commands := []string {
168
179
"git version" ,
169
180
"hugo version" ,
170
- fmt .Sprintf ("mkdir -p %s" , outputDirPath ),
171
181
// Use YAML file as it is easier to edit it afterward than TOML
172
182
fmt .Sprintf ("cd %s && hugo new site %s --format yaml" , outputDirPath , siteName ),
173
183
fmt .Sprintf ("cd %s && git clone https://github.com/adityatelange/hugo-PaperMod themes/PaperMod --depth=1" ,
174
184
path .Join (outputDirPath , siteName )),
175
- fmt .Sprintf ("cd %s && rm -rf themes/PaperMod/.git themes/PaperMod/.github" , path .Join (outputDirPath , siteName )),
176
185
// Set theme to PaperMod
177
- fmt .Sprintf (`echo " theme: 'PaperMod'" >> %s/hugo.yaml` , path .Join (outputDirPath , siteName )),
186
+ fmt .Sprintf (`echo theme: 'PaperMod'>> %s/hugo.yaml` , path .Join (outputDirPath , siteName )),
178
187
// Verify that the site is set up correctly
179
188
fmt .Sprintf ("cd %s && hugo" , path .Join (outputDirPath , siteName )),
180
189
}
@@ -184,7 +193,16 @@ func (g Generator) setupHugo(outputDirPath string) (*string, error) {
184
193
Int ("totalSteps" , len (commands )).
185
194
Str ("cmd" , command ).
186
195
Msg ("Running Hugo setup command" )
187
- output , err := exec .Command ("bash" , "-c" , command ).Output ()
196
+ var (
197
+ output []byte
198
+ err error
199
+ )
200
+ if runtime .GOOS == "windows" {
201
+ output , err = exec .Command ("cmd" , "/C" , command ).Output ()
202
+ } else {
203
+ // mac & Linux
204
+ output , err = exec .Command ("bash" , "-c" , command ).Output ()
205
+ }
188
206
if err != nil {
189
207
log .Error ().
190
208
Err (err ).
@@ -196,6 +214,22 @@ func (g Generator) setupHugo(outputDirPath string) (*string, error) {
196
214
log .Debug ().Msgf ("Hugo setup output: %s" , output )
197
215
}
198
216
217
+ // Delete .git directory
218
+ deleteDirs := []string {
219
+ path .Join (outputDirPath , siteName , ".git" ),
220
+ path .Join (outputDirPath , siteName , "themes/PaperMod/.git" ),
221
+ }
222
+ for _ , dir := range deleteDirs {
223
+ err := os .RemoveAll (dir )
224
+ if err != nil {
225
+ log .Error ().
226
+ Err (err ).
227
+ Str ("dir" , dir ).
228
+ Msg ("error removing directory" )
229
+ return nil , fmt .Errorf ("error removing directory '%s': %s" , dir , err )
230
+ }
231
+ }
232
+
199
233
siteDir := path .Join (outputDirPath , siteName )
200
234
log .Info ().
201
235
Str ("location" , siteDir ).
0 commit comments