chore: add api

This commit is contained in:
deepzz0
2021-04-27 23:46:43 +08:00
parent a39e3aac3b
commit 4749b1e681
7 changed files with 469 additions and 74 deletions

View File

@@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"path"
"regexp"
"time"
)
@@ -102,3 +103,27 @@ var monthToDays = map[time.Month]int{
func isLeapYear(year int) bool {
return year%4 == 0 && (year%100 != 0 || year%400 == 0)
}
var regexpImg = regexp.MustCompile(`data-src="(.*?)"`)
// PickFirstImage 获取第一张图片
func PickFirstImage(html string) string {
sli := regexpImg.FindAllStringSubmatch(html, 1)
if len(sli) > 0 && len(sli[0]) > 1 {
return sli[0][1]
}
return ""
}
var (
regexpBrackets = regexp.MustCompile(`<[\S\s]+?>`)
regexpEnter = regexp.MustCompile(`\s+`)
)
// IgnoreHtmlTag 去掉 html tag
func IgnoreHtmlTag(src string) string {
// 去除所有尖括号内的HTML代码
src = regexpBrackets.ReplaceAllString(src, "")
// 去除换行符
return regexpEnter.ReplaceAllString(src, "")
}

View File

@@ -1,7 +1,9 @@
// Package tools provides ...
package tools
import "regexp"
import (
"regexp"
)
var regexpEmail = regexp.MustCompile(`^(\w)+([\.\-]\w+)*@(\w)+((\.\w+)+)$`)