loader

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package loader 加载数据内容

仅加载各个模块的自身的数据,并判断格式是否正确。 但是不会对各个模块之间的关联数据进行校验。

Index

Constants

View Source
const (
	ArchiveTypeYear  = "year"
	ArchiveTypeMonth = "month"
)

归档的类型

View Source
const (
	OrderDesc = "desc"
	OrderAsc  = "asc"
)

排序方式

View Source
const (
	StateTop     = "top"   // 置顶
	StateLast    = "last"  // 放在尾部
	StateDraft   = "draft" // 表示为草稿,不会加载此条数据
	StateDefault = ""      // 默认值
)

表示 Post.State 的各类值

View Source
const (
	TagOrderTypeSize    = "size" // 按关联的文章数量排序
	TagOrderTypeDefault = ""     // 默认方式,即文件内容的顺序
)

Variables

This section is empty.

Functions

func Slug added in v1.1.0

func Slug(p string) string

Slug 根据文章路径返回文章的唯一 ID

Types

type Agent added in v1.0.0

type Agent struct {
	Agent    []string `yaml:"agent"`
	Disallow []string `yaml:"disallow,omitempty"`
	Allow    []string `yaml:"allow,omitempty"`
}

Agent 表示 robots.txt 每个代理项的内容

type Archive

type Archive struct {
	Title       string `yaml:"title"` // 存档页的标题
	Keywords    string `yaml:"keywords,omitempty"`
	Description string `yaml:"description,omitempty"`
	Order       string `yaml:"order,omitempty"`  // 排序方式
	Type        string `yaml:"type,omitempty"`   // 存档的分类方式,可以按年或是按月
	Format      string `yaml:"format,omitempty"` // 标题的格式化字符串,被 time.Format 所格式化。
}

Archive 存档页的配置内容

type Author

type Author struct {
	Name   string `yaml:"name"`
	URL    string `yaml:"url,omitempty"`
	Email  string `yaml:"email,omitempty"`
	Avatar string `yaml:"avatar,omitempty"`
}

Author 描述作者信息

type Config

type Config struct {
	Title    string `yaml:"title"`
	Subtitle string `yaml:"subtitle,omitempty"`

	// 标题后缀分隔符,文章页面浏览器标题上会加上此后缀,如果为空,则表示不需要后缀。
	TitleSeparator string `yaml:"titleSeparator,omitempty"`

	URL         string    `yaml:"url"` // 网站根域名,比如 https://example.com/blog
	Language    string    `yaml:"language,omitempty"`
	Uptime      time.Time `yaml:"uptime"`
	Icon        *Icon     `yaml:"icon,omitempty"`
	Author      *Author   `yaml:"author"` // 网站作者,在文章没有指定作者时,也采用此值。
	License     *Link     `yaml:"license"`
	Theme       string    `yaml:"theme"`
	Keywords    string    `yaml:"keywords,omitempty"`    // 所有页面默认情况下的 keywords
	Description string    `yaml:"description,omitempty"` // 所有页面默认情况下的 description
	Menus       []*Link   `yaml:"menus,omitempty"`       // 菜单
	TOC         int       `yaml:"toc,omitempty"`         // 当 headline 的数量大于此值时,生成 TOC
	Index       *Index    `yaml:"index"`                 // 分页设置

	Archive *Archive `yaml:"archive,omitempty"`
	RSS     *RSS     `yaml:"rss,omitempty"`
	Atom    *RSS     `yaml:"atom,omitempty"`
	Sitemap *Sitemap `yaml:"sitemap,omitempty"`
	Robots  []*Agent `yaml:"robots,omitempty"`  // 不为空,表示托管 robots.txt 的生成
	Profile *Profile `yaml:"profile,omitempty"` // 不为空,表示托管 README.md 的生成
}

Config 配置信息,用于从文件中读取

func LoadConfig

func LoadConfig(fs fs.FS, path string) (*Config, error)

LoadConfig 加载配置文件

type FieldError

type FieldError struct {
	File    string
	Field   string
	Message string
	Value   interface{}
}

FieldError 表示配置项内容的错误信息

func (*FieldError) Error

func (err *FieldError) Error() string
type Header struct {
	Level  int
	Indent int
	Text   string
	ID     string
}

Header TOC 的每一项内容

type Highlight added in v1.3.0

type Highlight struct {
	Name  string `yaml:"name"` // 指向的主题名称
	Media string `yaml:"media,omitempty"`
}

Highlight 高亮主题指定

type Icon

type Icon struct {
	URL   string `yaml:"url"`
	Type  string `yaml:"type"` // mime type
	Sizes string `yaml:"sizes"`
}

Icon 表示网站图标,比如 html>head>link.rel="short icon"

type Index added in v1.5.0

type Index struct {
	Title string `yaml:"title"` // 标题格式,可以使用 %d 占位符,表示页码。
	Size  int    `yaml:"size"`  // 每页数量
}

Index 索引页设置

type Link struct {
	URL  string `yaml:"url"`  // 链接地址
	Text string `yaml:"text"` // 链接的文本
}

Link 描述链接的内容

type Post

type Post struct {
	Title    string    `yaml:"title"`
	Created  time.Time `yaml:"created"`           // 创建时间
	Modified time.Time `yaml:"modified"`          // 修改时间
	Summary  string    `yaml:"summary,omitempty"` // 摘要,同时也作为 meta.description 的内容

	// 关联的标签列表
	//
	// 标签名为各个标签的 slug 值,可以保证其唯一。
	Tags []string `yaml:"tags"`

	// State 表示文章的状态,有以下四种值:
	// - top 表示文章被置顶;
	// - last 表示文章会被放置在最后;
	// - draft 表示这是一篇草稿;
	// - 空值 按默认的方式进行处理。
	State string `yaml:"state,omitempty"`

	// 封面地址,可以为空。
	Image string `yaml:"image,omitempty"`

	// 自定义 JSON-LD 数据
	//
	// 不需要包含 <script> 标签,只需要返回 JSON 格式数据好可。
	// 如果为空,则支自己生成 BlogPosting 类型的数据。
	JSONLD string `yaml:"jsonld,omitempty"`

	// 以下内容不存在时,则会使用全局的默认选项
	Authors  []*Author `yaml:"author,omitempty"`
	License  *Link     `yaml:"license,omitempty"`
	Template string    `yaml:"template,omitempty"`
	Language string    `yaml:"language,omitempty"`
	Keywords string    `yaml:"keywords,omitempty"`

	Content string   `yaml:"-"` // markdown 内容
	Slug    string   `yaml:"-"`
	TOC     []Header `yaml:"-"`
}

Post 表示文章的信息

func LoadPosts

func LoadPosts(f fs.FS) ([]*Post, error)

LoadPosts 加载所有的文章

type Profile added in v1.1.0

type Profile struct {
	// 以下字段提供了类似于以下格式的 markdown 内容:
	//  ### Title
	//
	//  post1
	//  post2
	//  post3
	//
	//  ##### Footer
	//
	// Title 和 Footer 的前缀 # 是固定的,不需要用户给字,即使用户给了,也会被删除。
	Title  string `yaml:"title"`
	Footer string `yaml:"footer"` // 页脚
	Size   int    `yaml:"size"`   // 显示最近添加的文章条数
}

Profile 用于生成 github.com/profile 中的 README.md 内容

type RSS

type RSS struct {
	Title string `yaml:"title,omitempty"`
	Size  int    `yaml:"size"` // 显示数量
}

RSS RSS 和 Atom 相关的配置项

type Sitemap

type Sitemap struct {
	Title string `yaml:"title"`

	Priority   float64 `yaml:"priority"`            // 默认的优先级
	Changefreq string  `yaml:"changefreq"`          // 默认的更新频率
	EnableTag  bool    `yaml:"enableTag,omitempty"` // 是否将标签相关的页面写入 sitemap

	// 文章可以指定一个专门的值
	PostPriority   float64 `yaml:"postPriority"`
	PostChangefreq string  `yaml:"postChangefreq"`
}

Sitemap sitemap 相关的配置

type Tag

type Tag struct {
	Title   string `yaml:"title"`
	Content string `yaml:"content"` // 对该标签的详细描述
	Slug    string `yaml:"slug"`    // 唯一名称
}

Tag 描述标签信息

type Tags

type Tags struct {
	Title       string `yaml:"title"` // 存档页的标题
	Keywords    string `yaml:"keywords,omitempty"`
	Description string `yaml:"description,omitempty"`
	Order       string `yaml:"order,omitempty"` // 排序方式
	OrderType   string `yaml:"orderType,omitempty"`
	Tags        []*Tag `yaml:"tags,omitempty"`
}

Tags 标签页的数据

func LoadTags

func LoadTags(fs fs.FS, path string) (*Tags, error)

LoadTags 加载标签列表

type Theme

type Theme struct {
	ID          string    `yaml:"-"`
	URL         string    `yaml:"url"`
	Description string    `yaml:"description,omitempty"`
	Authors     []*Author `yaml:"authors,omitempty"`
	Screenshots []string  `yaml:"screenshots,omitempty"`

	Templates []string `yaml:"templates,omitempty"`

	// 指定高亮的主题名称
	//
	// 名称值可以从 https://pkg.go.dev/github.com/alecthomas/chroma@v0.8.2/styles 获取
	Highlights []*Highlight `yaml:"highlights,omitempty"`

	// 部分可选内容的模板,如果为空,则其输出相应的 xml 文件时不会为其添加 xsl 文件。
	// 模板名称为相对于当前主题目录的文件路径。
	Sitemap string `yaml:"sitemap,omitempty"`
	RSS     string `yaml:"rss,omitempty"`
	Atom    string `yaml:"atom,omitempty"`
}

Theme 主题

func LoadTheme

func LoadTheme(fs fs.FS, id string) (*Theme, error)

LoadTheme 加载指定主题

Jump to

Keyboard shortcuts

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