|
|
|
@ -12,15 +12,21 @@ import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"github.com/q191201771/naza/pkg/filebatch"
|
|
|
|
|
"github.com/q191201771/naza/pkg/nazalog"
|
|
|
|
|
"os"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
//var licenseTmpl = `
|
|
|
|
|
//> **本文原始地址:** [https://pengrl.com/p/%s/](https://pengrl.com/p/%s/)
|
|
|
|
|
//> **声明:** 本文后续所有修改都会第一时间在原始地址更新。本文欢迎任何形式转载,转载时注明原始出处即可。`
|
|
|
|
|
|
|
|
|
|
var licenseTmpl = `
|
|
|
|
|
> **本文原始地址:** [https://pengrl.com/p/%s/](https://pengrl.com/p/%s/)
|
|
|
|
|
> **声明:** 本文后续所有修改都会第一时间在原始地址更新。本文欢迎任何形式转载,转载时注明原始出处即可。`
|
|
|
|
|
> **原文链接:** [https://pengrl.com/p/%s/](https://pengrl.com/p/%s/)
|
|
|
|
|
> **原文出处:** [yoko blog](https://pengrl.com) (https://pengrl.com)
|
|
|
|
|
> **原文作者:** yoko
|
|
|
|
|
> **版权声明:** 本文欢迎任何形式转载,转载时完整保留本声明信息(包含原文链接、原文出处、原文作者、版权声明)即可。本文后续所有修改都会第一时间在原始地址更新。`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
dir := parseFlag()
|
|
|
|
@ -38,12 +44,31 @@ func main() {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
lines := bytes.Split(content, []byte{'\n'})
|
|
|
|
|
if bytes.Index(lines[len(lines)-1], []byte("声明")) != -1 ||
|
|
|
|
|
bytes.Index(lines[len(lines)-2], []byte("声明")) != -1 {
|
|
|
|
|
|
|
|
|
|
//if bytes.Index(lines[len(lines)-1], []byte("声明")) != -1 {
|
|
|
|
|
// res, err := filebatch.DeleteLines(content, filebatch.LineRange{From: -2, To: -1})
|
|
|
|
|
// nazalog.Debugf("%s -2", info.Name())
|
|
|
|
|
// nazalog.FatalIfErrorNotNil(err)
|
|
|
|
|
// return res
|
|
|
|
|
//}
|
|
|
|
|
//if bytes.Index(lines[len(lines)-2], []byte("声明")) != -1 {
|
|
|
|
|
// res, err := filebatch.DeleteLines(content, filebatch.LineRange{From: -3, To: -1})
|
|
|
|
|
// nazalog.Debugf("%s -3", info.Name())
|
|
|
|
|
// nazalog.FatalIfErrorNotNil(err)
|
|
|
|
|
// return res
|
|
|
|
|
//}
|
|
|
|
|
//nazalog.Warnf("%s", info.Name())
|
|
|
|
|
//return content
|
|
|
|
|
|
|
|
|
|
// 已添加过声明,不用再添加了
|
|
|
|
|
if bytes.Index(lines[len(lines)-1], []byte("版权声明")) != -1 ||
|
|
|
|
|
bytes.Index(lines[len(lines)-2], []byte("版权声明")) != -1 {
|
|
|
|
|
skipCount++
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取该文章的url的地址
|
|
|
|
|
var abbrlink string
|
|
|
|
|
for _, line := range lines {
|
|
|
|
|
if bytes.Index(line, []byte("abbrlink")) != -1 {
|
|
|
|
@ -53,6 +78,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 构造好license信息,并添加在文章末尾
|
|
|
|
|
modCount++
|
|
|
|
|
license := fmt.Sprintf(licenseTmpl, abbrlink, abbrlink)
|
|
|
|
|
return filebatch.AddTailContent(content, []byte(license))
|
|
|
|
|