update at 2020-07-20 22:01:12 by ehlxr

master^2
ehlxr 2020-07-20 22:01:12 +08:00
parent 61ff5e9e8e
commit 904fac5d08
1 changed files with 16 additions and 8 deletions

View File

@ -137,7 +137,7 @@ func genDesc(path string) ([]byte, error) {
// 按行读取文件 // 按行读取文件
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
var identifier int var flag, ln int
output := make([]byte, 0) output := make([]byte, 0)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
@ -147,16 +147,24 @@ func genDesc(path string) ([]byte, error) {
break break
} }
if identifier < 2 && line == "---" { if flag < 2 && line == "---" {
identifier++ flag++
continue continue
} }
if identifier == 2 && line != "" { f := flag == 2 && line != ""
if f && ln > 0 {
output = append(output, []byte("\n")...)
// hello-friend 需要两个换行才能换行
output = append(output, []byte("\n")...)
output = append(output, []byte("\n")...)
}
if f {
ln++
line = strings.ReplaceAll(line, "'", "")
output = append(output, line...) output = append(output, line...)
output = append(output, []byte("\n")...)
output = append(output, []byte("\n")...)
output = append(output, []byte("\n")...)
} }
} }
@ -190,7 +198,7 @@ func genNew(path string, des string) ([]byte, error) {
if identifier == 2 && line == "---" { if identifier == 2 && line == "---" {
identifier++ identifier++
output = append(output, fmt.Sprintf("description: \"%s\"", des)...) output = append(output, fmt.Sprintf("description: '%s'", des)...)
output = append(output, []byte("\n")...) output = append(output, []byte("\n")...)
} }