mdfile

package
v1.1.1-0...-647775e Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package mdfile 是用来解析处理 markdown 文件的包

Index

Constants

This section is empty.

Variables

View Source
var Model = new()

Model 博客内容的实例

Functions

This section is empty.

Types

type Article

type Article struct {
	// 文章的标题
	Title string

	// 作者姓名
	Author string

	// 创建时间
	CreatedAt time.Time `toml:"created_at"`

	// 最后更新时间
	UpdatedAt time.Time `toml:"updated_at"`

	// 标签
	Tags []string

	// 所属分类的名称
	Category string

	// 头部图片 URL 地址
	HeadImg string `toml:"head_img"`

	// 作者的个人主页
	HomePage string `toml:"home_page"`

	// 简短的描述
	Description string

	// 文章主题内容, markdown
	Body string

	// 文章在服务器上的文件路由
	Path string
}

Article 文章内容

type Articles

type Articles []Article

Articles 文章列表

func (Articles) Len

func (a Articles) Len() int

Len

func (Articles) Less

func (a Articles) Less(i, j int) bool

Less 进行排序比较, 第一排序是 UpdatedAt , 第二排序是 CreatedAt, 第三排序是 Title

func (Articles) Swap

func (a Articles) Swap(i, j int)

Swap 实现的 sort 接口

type Categories

type Categories []Category

Categories 是文章分类的切片(数组)

type Category

type Category struct {
	// 分类的名称,用来做头部菜单的文本
	Title string

	// 分类下文章的数量
	Number int

	// 分类的文件目录, 当 OutLink 为 true 时,这里应该是一个外链,
	// 否则是 markdown 文档保存的子目录
	Path string

	// 分类的描述
	Description string

	// 当是一个外联时,就不会再去获取对应的 markdown 文档
	OutLink bool `toml:"out_link"`

	// 是否是激活状态
	Active bool
}

Category 文章分类

type List

type List interface {
	CategoriesAll() Categories
	TagsAll() Tags
	ArticlesAll() Articles
	ArticleByPath(string) (Article, error)
	ArticlesByCategory(string) Articles
	ArticlesByTag(string) Articles
	Reload()
}

List 博客列表

type ListMap

type ListMap struct {
	Articles   Articles
	Categories []Category
	Tags       Tags
}

ListMap 将博客保存在 map 中,

func (*ListMap) ArticleByPath

func (list *ListMap) ArticleByPath(path string) (Article, error)

ArticleByPath 根据文章的 Path 查询指定的文章

func (*ListMap) ArticlesAll

func (list *ListMap) ArticlesAll() Articles

ArticlesAll 获取所有文章的列表

func (*ListMap) ArticlesByCategory

func (list *ListMap) ArticlesByCategory(name string) Articles

ArticlesByCategory 根据分类获取博客列表

func (*ListMap) ArticlesByTag

func (list *ListMap) ArticlesByTag(title string) Articles

ArticlesByTag 根据标签获取博客列表

func (*ListMap) CategoriesAll

func (list *ListMap) CategoriesAll() Categories

CategoriesAll 获取所有的分类列表

func (*ListMap) Reload

func (list *ListMap) Reload()

Reload 重新加载文档

func (*ListMap) TagsAll

func (list *ListMap) TagsAll() Tags

TagsAll 获取所有标签

type Tag

type Tag struct {
	// 标签名称
	Title string

	// 标签下文章的数量
	Number int

	// 是否是选中的
	Active bool
}

Tag 标签

type Tags

type Tags []Tag

Tags 标签

func (Tags) Len

func (tags Tags) Len() int

Len 实现 Sort 的接口

func (Tags) Less

func (tags Tags) Less(i, j int) bool

Less 实现的 Sort 接口, 按照标签数量排序

func (Tags) Swap

func (tags Tags) Swap(i, j int)

Swap 实现的 Sort 接口

Jump to

Keyboard shortcuts

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