Commit 9bc8703 1 parent a90dab5 commit 9bc8703 Copy full SHA for 9bc8703
File tree 2 files changed +36
-4
lines changed
2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -16,18 +16,32 @@ type Book struct {
16
16
}
17
17
18
18
func LoadBook (path string ) (book * Book , err error ) {
19
+ bookIniPath := filepath .Join (path , "book.ini" )
20
+ bookTomlPath := filepath .Join (path , "book.toml" )
21
+
19
22
book = & Book {Root : path }
20
- book .Info , err = LoadConfig (filepath . Join ( path , "book.ini" ) )
23
+ book .Info , err = LoadConfig (bookIniPath )
21
24
if err != nil {
22
- if info , errx := LoadConfig (filepath .Join (path , "book.toml" )); errx != nil {
23
- return nil , err
25
+ if info , errx := LoadConfig (bookTomlPath ); errx != nil {
26
+ if fileExists (bookIniPath ) || fileExists (bookTomlPath ) {
27
+ // 文件存在说明有错误
28
+ return nil , err
29
+ } else {
30
+ // 不存在则生成一个空的
31
+ book .Info = & BookToml {}
32
+ }
24
33
} else {
25
34
book .Info = info
26
35
}
27
36
}
28
37
book .Summary , err = LoadSummary (filepath .Join (path , "SUMMARY.md" ))
29
38
if err != nil {
30
- return nil , err
39
+ if fileExists (filepath .Join (path , "SUMMARY.md" )) {
40
+ return nil , err
41
+ } else {
42
+ err = nil
43
+ }
44
+ book .Summary = & Summary {}
31
45
}
32
46
book .Talks = loadTalks (book .Root )
33
47
return
Original file line number Diff line number Diff line change
1
+ // Copyright 2024 <chaishushan{AT}gmail.com>. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package wabook
6
+
7
+ import "os"
8
+
9
+ func fileExists (path string ) bool {
10
+ fi , err := os .Lstat (path )
11
+ if err != nil {
12
+ return false
13
+ }
14
+ if fi .IsDir () {
15
+ return false
16
+ }
17
+ return true
18
+ }
You can’t perform that action at this time.
0 commit comments