utils

package
v1.0.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AdminCheck

func AdminCheck(token string) bool

func AdminEncrypt

func AdminEncrypt() string

AdminEncrypt 内部实现逻辑很简单只需要比对加密后的串是否一致 加密方式sha256

func CheckArticleOK

func CheckArticleOK(fileData []byte) bool

校验上传的文章字节流是否合法 合法即包含需要的yaml front信息 且信息内的title和name不为空

func CheckDate

func CheckDate(date string) bool

CheckDate 校验时间字符串合法性

func CheckDatePlus

func CheckDatePlus(date string) bool

func CheckUpdateTime

func CheckUpdateTime(createTime string) (updateTime string, flag bool)

CheckUpdateTime 检查上传日期和md内部的创建日期 当上传日期大于创建日期时才使用此日期作为更新日期

func Conetent2Abs

func Conetent2Abs(abs, content string) string

Conetent2Abs 截取正文内容作为博客摘要

func GerDateYear

func GerDateYear() string

GerDateYear 获取年 "2006"

func GetDate

func GetDate() string

GetDate 获取日期 年月日 "2006-01-02"

func GetDate2

func GetDate2() string

GetDate2 获取年月 "2006-01"

func GetDatePlus

func GetDatePlus() string

GetDatePlus 获取准确时间 "2006-01-02 15:04:05"

func GetDateTime

func GetDateTime() string

GetDateTime 获取准确时间的int 用于前端解析

func GetSortMessage

func GetSortMessage() string

GetSortMessage 留言使用id user date排序 默认id

func GetSortPost

func GetSortPost(sortBy string, reverse bool) string

GetSortPost 获取post的排序标准

func ParseAbs

func ParseAbs(fileRaw []byte) []byte

解析摘要 传入为去除meta的文本 三级解析器 生成摘要信息

func ParseMd

func ParseMd(fileRaw []byte) []byte

解析md源文件 一级解析器 生成不带meta的md字节

Types

type MdData

type MdData struct {
	Meta     Meta
	Abstract string
	Body     string
}

func GenMdData

func GenMdData(fileData []byte) (MdData, error)

生成md文件的格式化结构体

type Meta

type Meta struct {
	Name       string
	ID         int
	Title      string
	Date       string
	DatePlus   string
	Tags       []string
	Categories []string
}

func ParseYamlFront

func ParseYamlFront(fileRaw []byte) (Meta, error)

解析出yaml front 使用yaml front解析yaml头部信息

func ReformatMeta

func ReformatMeta(meta Meta) Meta

重新格式化meta信息 可能出现时间不合法等情况 id不存在等情况

type YamlData

type YamlData struct {
	Name       string   `yaml:"name"`
	ID         int      `yaml:"id"`
	Title      string   `yaml:"title"`
	DatePlus   string   `yaml:"date"`
	Tags       []string `yaml:"tags"`
	Categories []string `yaml:"categories"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL