-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
555 lines (536 loc) · 21.7 KB
/
commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
package main
import (
"fmt"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
)
var (
commandVersion = /* const */ appCommandDescriptor{
command: "version",
description: "print out version info",
usage: "mbgen version",
reqConfig: false,
}
commandHelp = /* const */ appCommandDescriptor{
command: "help",
description: "print out help/usage information",
usage: "mbgen help <command>\n\n" +
"where <command> is one of the following supported commands to print out help/usage information for:\n\n" +
"init, generate, stats, serve, theme, cleanup, version",
reqConfig: false,
optArgCnt: 1,
}
commandInit = /* const */ appCommandDescriptor{
command: "init",
description: "initialize working dir:\n\n" +
" - generate sample " + configFileName + " file\n" +
" - download content samples\n" +
" - install and activate default theme",
usage: "mbgen init\n\n",
reqConfig: false,
}
commandCleanup = /* const */ appCommandDescriptor{
command: "cleanup",
description: "perform a cleanup",
usage: "mbgen cleanup <target>\n\n" +
" - <target> (optional) is one of the following:\n\n" +
" - " + commandCleanupTargetContent + ": deletes all previously generated content (" + contentFileExtension + ") files\n" +
" for which markdown (" + markdownFileExtension + ") content files no longer exist\n\n" +
" - " + commandCleanupTargetThumbs + ": deletes all previously generated thumbnail files\n\n" +
" - " + commandCleanupTargetTags + ": deletes all previously generated tag files\n" +
" that are no longer referenced by any markdown (" + markdownFileExtension + ") content files\n\n" +
" - " + commandCleanupTargetTagIndex + ": deletes the previously generated tag index file\n\n" +
" - " + commandCleanupTargetArchive + ": deletes the previously generated archive files\n\n" +
" - " + commandCleanupTargetSearch + ": deletes all previously generated search files\n\n" +
" - if no <target> is specified, each target is performed based on the following conditions:\n\n" +
" - " + commandCleanupTargetContent + ": always\n\n" +
" - " + commandCleanupTargetTags + ": always\n\n" +
" - " + commandCleanupTargetThumbs + ": if `useThumbs` config option is disabled\n\n" +
" - " + commandCleanupTargetTagIndex + ": if `generateTagIndex` config option is disabled\n\n" +
" - " + commandCleanupTargetArchive + ": if `generateArchive` config option is disabled\n\n" +
" - " + commandCleanupTargetSearch + ": if `enableSearch` config option is disabled\n\n",
reqConfig: true,
optArgCnt: 1,
}
commandGenerate = /* const */ appCommandDescriptor{
command: "generate",
description: "parse content and generate site",
usage: "mbgen generate\n\n" +
"must be run from a working dir containing " + configFileName + " file",
reqConfig: true,
}
commandStats = /* consts */ appCommandDescriptor{
command: "stats",
description: "parse content and print out stats",
usage: "mbgen stats\n\n" +
"must be run from a working dir containing " + configFileName + " file",
reqConfig: true,
}
commandServe = /* const */ appCommandDescriptor{
command: "serve",
description: "start a web server to serve the site",
usage: "mbgen serve [" + commandServeOptionWatchReload + "]\n\n" +
"must be run from a working dir containing " + configFileName + " file and " + deployDirName + " directory with generated assets\n\n" +
" ONE of the following flags can be specified:\n" +
" " + commandServeOptionAdmin + " - to render content admin links\n" +
" " + commandServeOptionWatchReload + " - to automatically regenerate the site and see the changes being reflected in the browser in real-time when you change any of the markdown content (.md) files in the " + markdownPagesDirName + " or " + markdownPostsDirName + " dirs\n",
reqConfig: true,
optArgCnt: 1,
}
commandTheme = /* const */ appCommandDescriptor{
command: "theme",
description: "install/update and/or activate a theme",
reqArgCnt: 2,
usage: "mbgen theme <action> <theme-name>\n\n" +
" - <action> is one of the following:\n\n" +
" - " + commandThemeActionActivate + ": checks if the specified theme is installed,\n" +
" and modifies the " + configFileName + " file to make it active\n\n" +
" - " + commandThemeActionInstall + ": downloads and installs the specified theme if it's not yet installed,\n" +
" and copies all the relevant/missing theme include files into the " + includeDirName + "dir inside the working dir\n\n" +
" - " + commandThemeActionUpdate + ": downloads and installs the required updates for the specified theme (must be already installed),\n" +
" and copies all the relevant/missing theme include files into the " + includeDirName + "dir inside the working dir\n\n" +
" - " + commandThemeActionRefresh + ": copies all the relevant/missing theme include files into the " + includeDirName + "dir inside the working dir\n\n" +
" - " + commandThemeActionDelete + ": deletes all the assets of the specified theme, if it's not being currently in use\n\n" +
" - <theme-name> is the name of a theme to perform the specified action on,\n\n" +
" - the default theme name is: \"" + defaultThemeName + "\", but you can also use the \"" + defaultThemeAlias + "\" alias instead",
reqConfig: true,
}
)
func getSupportedCommands() map[string]tuple2[appCommand, appCommandDescriptor] {
return map[string]tuple2[appCommand, appCommandDescriptor]{
commandVersion.command: {_version, commandVersion},
commandHelp.command: {_help, commandHelp},
commandInit.command: {_init, commandInit},
commandCleanup.command: {_cleanup, commandCleanup},
commandGenerate.command: {_generate, commandGenerate},
commandStats.command: {_stats, commandStats},
commandServe.command: {_serve, commandServe},
commandTheme.command: {_theme, commandTheme},
}
}
func _version(config appConfig, commandArgs ...string) {
println("mbgen " + appVersion)
}
func _help(config appConfig, commandArgs ...string) {
if commandArgs != nil && len(commandArgs) > 0 {
arg := commandArgs[0]
var cmdDescr appCommandDescriptor
if cmd, ok := getSupportedCommands()[arg]; ok {
cmdDescr = cmd.V2
usageHelp := cmdDescr.description + "\n\nusage:\n\n" + cmdDescr.usage
usage(usageHelp, 0)
} else {
sprintln("error: unknown help <command> argument: " + arg)
usage("", 1)
}
} else {
usage("", 0)
}
}
func _init(config appConfig, commandArgs ...string) {
// generate sample config file
if fileExists(configFileName) {
println(" - config file already exists: " + configFileName)
} else {
config = defaultConfig()
config.siteName = "Sample Site Name"
writeConfig(config)
sprintln(" - generated sample config file: " + configFileName)
}
// download content samples
if dirExists(markdownPagesDirName) {
println(" - page content dir already exists: " + markdownPagesDirName)
} else {
createDir(markdownPagesDirName)
err := download(defaultGitHubRepoPageContentSamplesUrl, markdownPagesDirName)
if err != nil {
println(fmt.Sprintf("error downloading page content samples:\n\n" + err.Error()))
} else {
println(" - downloaded page content samples")
}
}
if dirExists(markdownPostsDirName) {
println(" - post content dir already exists: " + markdownPostsDirName)
} else {
createDir(markdownPostsDirName)
err := download(defaultGitHubRepoPostContentSamplesUrl, markdownPostsDirName)
if err != nil {
println(fmt.Sprintf("error downloading post content samples:\n\n" + err.Error()))
} else {
println(" - downloaded post content samples")
}
}
if dirExists(deployDirName) {
println(" - deploy dir already exists: " + deployDirName)
} else {
createDir(deployDirName)
err := download(defaultGitHubRepoDeployDirContentSamplesUrl, deployDirName)
if err != nil {
println(fmt.Sprintf("error downloading deploy dir content samples:\n\n" + err.Error()))
} else {
println(" - downloaded deploy dir content samples")
}
}
// install and activate default theme
_theme(config, "install", defaultThemeName)
_theme(config, "activate", defaultThemeName)
copyThemeIncludes(defaultThemeName)
}
func _cleanup(config appConfig, commandArgs ...string) {
cleanupContent := false
cleanupThumbs := false
cleanupTags := false
cleanupTagIndex := false
cleanupArchive := false
cleanupSearch := false
if commandArgs == nil || len(commandArgs) == 0 {
cleanupContent = true
cleanupTags = true
cleanupThumbs = !config.useThumbs
cleanupArchive = !config.generateArchive
cleanupTagIndex = !config.generateTagIndex
cleanupSearch = !config.enableSearch
} else {
target := commandArgs[0]
switch target {
case commandCleanupTargetContent:
cleanupContent = true
case commandCleanupTargetThumbs:
cleanupThumbs = true
case commandCleanupTargetTags:
cleanupTags = true
case commandCleanupTargetTagIndex:
cleanupTagIndex = true
case commandCleanupTargetArchive:
cleanupArchive = true
case commandCleanupTargetSearch:
cleanupSearch = true
default:
sprintln("error: invalid cleanup command <target> argument: " + target)
usageHelp := "usage:\n\n" + commandCleanup.usage
usage(usageHelp, 1)
}
}
if cleanupContent {
deployPageDirPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, deployPageDirName)
deployPageDirEntries, err := os.ReadDir(deployPageDirPath)
check(err)
if len(deployPageDirEntries) > 0 {
for _, deployPageEntry := range deployPageDirEntries {
deployPageEntryInfo, err := deployPageEntry.Info()
check(err)
if !deployPageEntryInfo.IsDir() {
deployPageEntryFileName := deployPageEntryInfo.Name()
pageId := deployPageEntryFileName[:len(deployPageEntryFileName)-len(filepath.Ext(deployPageEntryFileName))]
markdownPageFilePath := fmt.Sprintf("%s%c%s", markdownPagesDirName, os.PathSeparator, pageId+markdownFileExtension)
if !fileExists(markdownPageFilePath) {
sprintln(" - page markdown file no longer exists: " + markdownPageFilePath)
deployPageFilePath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployPageDirName, os.PathSeparator, deployPageEntryFileName)
deleteFile(deployPageFilePath)
sprintln(" - deleted page content file: " + deployPageFilePath)
}
}
}
}
deployPostDirPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, deployPostDirName)
deployPostDirEntries, err := os.ReadDir(deployPostDirPath)
check(err)
if len(deployPostDirEntries) > 0 {
for _, deployPostEntry := range deployPostDirEntries {
deployPostEntryInfo, err := deployPostEntry.Info()
check(err)
if !deployPostEntryInfo.IsDir() {
deployPostEntryFileName := deployPostEntryInfo.Name()
postId := deployPostEntryFileName[:len(deployPostEntryFileName)-len(filepath.Ext(deployPostEntryFileName))]
markdownPostFilePath := fmt.Sprintf("%s%c%s", markdownPostsDirName, os.PathSeparator, postId+markdownFileExtension)
if !fileExists(markdownPostFilePath) {
sprintln(" - post markdown file no longer exists: " + markdownPostFilePath)
deployPostFilePath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployPostDirName, os.PathSeparator, deployPostEntryFileName)
deleteFile(deployPostFilePath)
sprintln(" - deleted post content file: " + deployPostFilePath)
}
}
}
}
}
if cleanupThumbs {
resLoader := getResourceLoader(config)
parsePages(config, resLoader, deleteImgThumbnails, false)
parsePosts(config, resLoader, deleteImgThumbnails, false)
}
if cleanupTags {
deployTagsDirPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, deployTagsDirName)
deployTagsDirEntries, err := os.ReadDir(deployTagsDirPath)
check(err)
if len(deployTagsDirEntries) > 0 {
posts := parsePosts(config, getResourceLoader(config), nil, false)
var tags []string
for _, post := range posts {
for _, tag := range post.Tags {
t := strings.ToLower(tag)
if !slices.Contains(tags, t) {
tags = append(tags, t)
}
}
}
for _, deployTagDirEntry := range deployTagsDirEntries {
deployTagDirEntryInfo, err := deployTagDirEntry.Info()
check(err)
if deployTagDirEntryInfo.IsDir() {
deployTagDirName := deployTagDirEntryInfo.Name()
if !slices.Contains(tags, deployTagDirName) {
sprintln(" - tag no longer referenced: " + deployTagDirName)
deployTagDirPath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployTagsDirName, os.PathSeparator, deployTagDirName)
deleteIfExists(deployTagDirPath)
sprintln(" - deleted tag dir: " + deployTagDirPath)
}
}
}
}
}
if cleanupTagIndex {
deployTagIndexPath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployTagsDirName, os.PathSeparator, indexPageFileName)
if deleteIfExists(deployTagIndexPath) {
sprintln(" - deleted tag index file: " + deployTagIndexPath)
}
}
if cleanupArchive {
deployArchivePath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, deployArchiveDirName)
if deleteIfExists(deployArchivePath) {
sprintln(" - deleted archive dir: " + deployArchivePath)
}
}
if cleanupSearch {
deploySearchIndexPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, searchIndexFileName)
if deleteIfExists(deploySearchIndexPath) {
sprintln(" - deleted search index file: " + deploySearchIndexPath)
}
deploySearchPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, searchPageFileName)
if deleteIfExists(deploySearchPath) {
sprintln(" - deleted search page file: " + deploySearchPath)
}
}
}
func _generate(config appConfig, commandArgs ...string) {
createDirIfNotExists(deployDirName)
resLoader := getResourceLoader(config)
deployResDirPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, resourcesDirName)
recreateDir(deployResDirPath)
sprintln(" - copying theme resources ...")
themeResourcesDirPath := fmt.Sprintf("%s%c%s", config.theme, os.PathSeparator, resourcesDirName)
deployResourcesDirPath := fmt.Sprintf("%s%c%s", deployDirName, os.PathSeparator, resourcesDirName)
copyDir(themeResourcesDirPath, deployResourcesDirPath)
for _, level := range templateIncludeLevels {
stylesIncludeFilePath := getIncludeFilePath(stylesFileName, level, resLoader.config)
if stylesIncludeFilePath != "" {
copyFile(stylesIncludeFilePath, fmt.Sprintf("%s%c%s", deployResourcesDirPath, os.PathSeparator, fmt.Sprintf(stylesIncludeFileNameFormat, level.String())))
}
}
processAndHandleStats(config, resLoader, false)
}
func _stats(config appConfig, commandArgs ...string) {
resLoader := getResourceLoader(config)
handleStats(process(parsePages(config, resLoader, nil, false),
parsePosts(config, resLoader, nil, false),
resLoader, nil))
}
func _serve(config appConfig, commandArgs ...string) {
resLoader := getResourceLoader(config)
var wChan chan watchReloadData
var admin bool
if commandArgs != nil && len(commandArgs) > 0 {
if len(commandArgs) == 1 {
arg := commandArgs[0]
if arg == commandServeOptionAdmin {
admin = true
} else if arg == commandServeOptionWatchReload {
wChan = make(chan watchReloadData)
go watchDirForChanges(markdownPagesDirName, markdownFileExtension, func(changedFilePath string, deleted bool) {
filePath := strings.Split(changedFilePath, string(os.PathSeparator))
fileName := filePath[len(filePath)-1]
pageId := fileName[:len(fileName)-len(filepath.Ext(fileName))]
pageDeleted := deleted || !fileExists(changedFilePath)
if !pageDeleted {
println(" - [watch] page markdown file added/updated: " + changedFilePath)
processAndHandleStats(config, resLoader, true)
} else {
println(" - [watch] page markdown file deleted: " + changedFilePath)
deployPageFilePath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployPageDirName, os.PathSeparator, pageId+contentFileExtension)
if deleteIfExists(deployPageFilePath) {
sprintln(" - deleted page content file: " + deployPageFilePath)
}
processAndHandleStats(config, resLoader, true)
}
wChan <- watchReloadData{
Type: Page,
Id: pageId,
Deleted: pageDeleted,
}
})
go watchDirForChanges(markdownPostsDirName, markdownFileExtension, func(changedFilePath string, deleted bool) {
filePath := strings.Split(changedFilePath, string(os.PathSeparator))
fileName := filePath[len(filePath)-1]
postId := fileName[:len(fileName)-len(filepath.Ext(fileName))]
postDeleted := deleted || !fileExists(changedFilePath)
if !postDeleted {
println(" - [watch] post markdown file added/updated: " + changedFilePath)
processAndHandleStats(config, resLoader, true)
} else {
println(" - [watch] post markdown file deleted: " + changedFilePath)
deployPostFilePath := fmt.Sprintf("%s%c%s%c%s", deployDirName, os.PathSeparator, deployPostDirName, os.PathSeparator, postId+contentFileExtension)
if deleteIfExists(deployPostFilePath) {
sprintln(" - deleted post content file: " + deployPostFilePath)
}
processAndHandleStats(config, resLoader, true)
}
wChan <- watchReloadData{
Type: Post,
Id: postId,
Deleted: postDeleted,
}
})
} else {
sprintln("error: invalid serve command argument: " + commandArgs[0])
usageHelp := "usage:\n\n" + commandServe.usage
usage(usageHelp, 1)
}
} else {
sprintln("error: invalid number of serve command arguments (max allowed: " + strconv.Itoa(commandServe.optArgCnt) + ")")
usageHelp := "usage:\n\n" + commandServe.usage
usage(usageHelp, 1)
}
}
listenAndServe(fmt.Sprintf("%s:%d", config.serveHost, config.servePort), admin, wChan, config, resLoader)
}
func _theme(config appConfig, commandArgs ...string) {
action := commandArgs[0]
theme := commandArgs[1]
if defaultThemeAlias == theme {
theme = defaultThemeName
}
themeInstalled := false
var themeDir = fmt.Sprintf("%s%c%s", themesDirName, os.PathSeparator, theme)
themeInstalled = dirExists(themeDir)
switch action {
case commandThemeActionActivate:
if !themeInstalled {
sprintln("theme is not installed: " + theme)
} else {
config.theme = themeDir
writeConfig(config)
sprintln(" - " + configFileName + " updated to activate new theme: " + theme)
}
case commandThemeActionInstall:
if themeInstalled {
sprintln("theme is already installed: " + theme)
} else {
sprintln(" - installing theme: " + theme)
themeUrl := fmt.Sprintf("%s/%s", defaultGitHubRepoThemesUrl, theme)
err := download(themeUrl, themeDir)
if err != nil {
println(fmt.Sprintf("error installing theme:\n\n" + err.Error()))
} else {
copyThemeIncludes(theme)
}
}
case commandThemeActionUpdate:
if !themeInstalled {
sprintln("theme is not installed: " + theme)
} else {
println(" - updating theme: " + theme)
themeUrl := fmt.Sprintf("%s/%s", defaultGitHubRepoThemesUrl, theme)
themeDlDir := themeDir + downloadedThemeDirSuffix
deleteIfExists(themeDlDir)
err := download(themeUrl, themeDlDir)
if err != nil {
println(fmt.Sprintf("error updating theme:\n\n" + err.Error()))
} else {
recreateDir(themeDir)
copyDir(themeDlDir, themeDir)
deleteIfExists(themeDlDir)
copyThemeIncludes(theme)
}
}
case commandThemeActionRefresh:
if !themeInstalled {
sprintln("theme is not installed: " + theme)
} else {
println(" - refreshing theme: " + theme)
copyThemeIncludes(theme)
}
case commandThemeActionDelete:
if !themeInstalled {
sprintln("theme is not installed: " + theme)
} else {
if config.theme == themeDir {
sprintln("cannot delete theme being currently in use: " + theme)
} else {
println(" - deleting theme: " + theme)
deleteIfExists(themeDir)
themeDstIncludeDir := fmt.Sprintf("%s%c%s", includeDirName, os.PathSeparator, theme)
deleteIfExists(themeDstIncludeDir)
}
}
default:
sprintln("error: invalid theme command <action> argument: " + action)
usageHelp := "usage:\n\n" + commandTheme.usage
usage(usageHelp, 1)
}
}
func copyThemeIncludes(theme string) {
themeSrcIncludeDir := fmt.Sprintf("%s%c%s%c%s", themesDirName, os.PathSeparator, theme, os.PathSeparator, includeDirName)
if dirExists(themeSrcIncludeDir) {
themeDstIncludeDir := fmt.Sprintf("%s%c%s", includeDirName, os.PathSeparator, theme)
createDirIfNotExists(themeDstIncludeDir)
includeFiles, err := os.ReadDir(themeSrcIncludeDir)
check(err)
if len(includeFiles) > 0 {
for _, includeFile := range includeFiles {
includeFileInfo, err := includeFile.Info()
check(err)
includeFileName := includeFileInfo.Name()
includeFileDstPath := fmt.Sprintf("%s%c%s", themeDstIncludeDir, os.PathSeparator, includeFileName)
if !fileExists(includeFileDstPath) {
includeFileSrcPath := fmt.Sprintf("%s%c%s", themeSrcIncludeDir, os.PathSeparator, includeFileName)
sprintln(
" - copying include file:",
" - src: "+includeFileSrcPath,
" - dst: "+includeFileDstPath,
)
copyFile(includeFileSrcPath, includeFileDstPath)
}
}
}
}
}
func getResourceLoader(config appConfig) resourceLoader {
return resourceLoader{
config: config,
loadTemplate: func(templateFileName string) ([]byte, error) {
templateFilePath := fmt.Sprintf("%s%c%s%c%s",
config.theme, os.PathSeparator, templatesDirName, os.PathSeparator, templateFileName)
return os.ReadFile(templateFilePath)
},
loadInclude: func(includeFileName string, level templateIncludeLevel) ([]byte, error) {
includeFilePath := getIncludeFilePath(includeFileName, level, config)
if includeFilePath != "" {
return os.ReadFile(includeFilePath)
} else {
return nil, nil
}
},
}
}
func handleStats(stats stats) {
sprintln(
"[------- stats --------]\n",
fmt.Sprintf(" - pages: %d", stats.pageCnt),
fmt.Sprintf(" - posts: %d", stats.postCnt),
fmt.Sprintf(" - tags: %d", stats.tagCnt),
fmt.Sprintf(" - files generated: %d\n", stats.genCnt),
"[----------------------]",
)
}