add_blog_license: change license content

pull/2/head
q191201771 5 years ago
parent a5bda8646a
commit d300e839ca

@ -26,7 +26,6 @@ LDFlags=" \
cd ${ROOT_DIR}/demo/add_blog_license && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/add_blog_license &&
cd ${ROOT_DIR}/demo/add_go_license && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/add_go_license &&
cd ${ROOT_DIR}/demo/taskpool && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/taskpool &&
cd ${ROOT_DIR}/demo/samefile && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/samefile &&
cd ${ROOT_DIR}/demo/slicebytepool && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/slicebytepool &&
cd ${ROOT_DIR}/demo/myapp && go build -ldflags "$LDFlags" -o ${ROOT_DIR}/bin/myapp &&
ls -lrt ${ROOT_DIR}/bin &&

@ -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))

Loading…
Cancel
Save