|
|
|
@ -11,19 +11,49 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"github.com/q191201771/naza/pkg/filebatch"
|
|
|
|
|
"github.com/q191201771/naza/pkg/nazalog"
|
|
|
|
|
"os"
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var licenseTmpl = `
|
|
|
|
|
> **本文原始地址:** [https://pengrl.com/p/%s/](https://pengrl.com/p/%s/)
|
|
|
|
|
> **声明:** 本文后续所有修改都会第一时间在原始地址更新。本文欢迎任何形式转载,转载时注明原始出处即可。`
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
dir := parseFlag()
|
|
|
|
|
|
|
|
|
|
linesOfLicense := strings.Split(licenseTmpl, "\n")
|
|
|
|
|
lastLineOfLicense := linesOfLicense[len(linesOfLicense)-1]
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
skipCount int
|
|
|
|
|
modCount int
|
|
|
|
|
)
|
|
|
|
|
err := filebatch.Walk(dir, true, ".md", func(path string, info os.FileInfo, content []byte) []byte {
|
|
|
|
|
lines := bytes.Split(content, []byte{'\n'})
|
|
|
|
|
nazalog.Debug(path, len(lines))
|
|
|
|
|
return nil
|
|
|
|
|
if bytes.Index(lines[len(lines)-1], []byte(lastLineOfLicense)) != -1 {
|
|
|
|
|
skipCount++
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
var abbrlink string
|
|
|
|
|
for _, line := range lines {
|
|
|
|
|
if bytes.Index(line, []byte("abbrlink")) != -1 {
|
|
|
|
|
abbrlink = string(bytes.TrimSpace(bytes.Split(line, []byte{':'})[1]))
|
|
|
|
|
nazalog.Debug(abbrlink)
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modCount++
|
|
|
|
|
license := fmt.Sprintf(licenseTmpl, abbrlink, abbrlink)
|
|
|
|
|
return filebatch.AddTailContent(content, []byte(license))
|
|
|
|
|
})
|
|
|
|
|
nazalog.FatalIfErrorNotNil(err)
|
|
|
|
|
nazalog.Infof("count. mod=%d, skip=%d", modCount, skipCount)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func parseFlag() string {
|
|
|
|
|