pkg

package
v0.0.0-...-4e021e0 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BLOG_ITEM_KIND_DIR = 1 << iota
	BLOG_ITEM_KIND_MD
	BLOG_ITEM_KIND_OTHER
)

Variables

This section is empty.

Functions

func FilterMap

func FilterMap[T comparable, V any](m map[T]V, f func(T) bool) map[T]V

编写一个泛型函数,用来去除一个map中的不符合要求的函数,返回一个新的map

func FilterSlice

func FilterSlice[T any](s []T, f func(T) bool) []T

编写一个泛型函数,用来去除一个slice中不符合要求的函数,返回修改后的结果,这是一个新的slice

func GenPath

func GenPath(url string, config *Config) string

=== path generate ===

func Md2Html

func Md2Html(md []byte, title string, templatePath, renderCommand string) (html []byte, err error)

use pandoc to convert md to html

func PathMatch

func PathMatch(path string, matcher ...GitIgnorer) bool

=== path match ===

func RenderDir

func RenderDir(path string, hide, private GitIgnorer, blogRouter, blogPath string) (md []byte, err error)

load md

func SimplifyPath

func SimplifyPath(path string) string

=== path process ===

func TransformLinks(oldhtml []byte, config *Config) []byte

Types

type BlogIndex

type BlogIndex struct {
	Path string
	Meta
	File string
}

type BlogIndexer

type BlogIndexer interface {
	// 加入对一个博客内容的索引
	Add(blog *BlogItem) error
	// 删除对一个博客内容的索引
	Delete(blog *BlogItem) error
	// 搜索博客内容
	Search(keyword string, num int) ([]string, error)
	// 把对博客内容建立的索引保存到文件
	Close() error
}

使用bleve 对博客建立索引

func NewBlogIndexer

func NewBlogIndexer(indexPath string) BlogIndexer

type BlogItem

type BlogItem struct {
	// Path 作为唯一标识符
	Path string
	Meta
	Kind int
	File string
	Html string
}

func (*BlogItem) IsDir

func (item *BlogItem) IsDir() bool

func (*BlogItem) IsMd

func (item *BlogItem) IsMd() bool

type BlogLoader

type BlogLoader struct {
	*sync.RWMutex
	BlogPath, BlogRouter        string
	TemplatePath, RenderCommand string
	Hide, Private               GitIgnorer
}

func NewBlogLoader

func NewBlogLoader(config *Config) *BlogLoader

func (*BlogLoader) LoadBlog

func (loader *BlogLoader) LoadBlog(path string) (*BlogItem, error)

func (*BlogLoader) Path2Url

func (loader *BlogLoader) Path2Url(path string) string

func (*BlogLoader) Update

func (loader *BlogLoader) Update(config *Config)

func (*BlogLoader) Url2Path

func (loader *BlogLoader) Url2Path(url string) string

type Cache

type Cache interface {
	Get(key string) (interface{}, bool)
	Set(key string, value interface{})
	Remove(key string)
	RemoveAll()
}

func NewCache

func NewCache(size int) Cache

type Config

type Config struct {
	sync.RWMutex   `yaml:"-" toml:"-" json:"-"`
	PORT           int
	BLOG_ROUTER    string
	API_ROUTER     string
	BLOG_PATH      string
	GEN_PATH       string
	NOT_GEN        bool
	HIDE_PATHS     []string
	PRIVATE_PATHS  []string
	TEMPLATE_PATH  string
	APP_DATA_PATH  string
	SEARCH_NUM     int
	SEARCH_PLUGINS []SearcherPlugin
	RENDER_COMMAND string

	// for visit limit
	RATE_LIMITE_SECOND int
	RATE_LIMITE_MINUTE int
	RATE_LIMITE_HOUR   int
}

func LoadConfig

func LoadConfig(file string) *Config

func (*Config) Update

func (config *Config) Update(path string) bool

if update success, return true, else return false

type GitIgnorer

type GitIgnorer interface {
	AddPatterns(patterns ...string) GitIgnorer
	UpdatePatterns(patterns ...string) GitIgnorer
	Match(path string) bool
}

func NewBlogIgnorer

func NewBlogIgnorer() GitIgnorer

type Meta

type Meta struct {
	Title       string   `yaml:"title"`
	KeyWords    []string `yaml:"keywords"`
	Description string   `yaml:"description"`
}

=== meta data for md ===

func MdMeta

func MdMeta(md []byte) (meta Meta, err error)

type Searcher

type Searcher interface {
	Search(keyword string, num int) ([]string, error)
	Name() string
	Brief() string
}

func NewSearchByContentMatch

func NewSearchByContentMatch(name, brief string, spider fspider.Spider, cache Cache, blogLoader *BlogLoader) Searcher

according to the times of keyword in {content, title, meta}

func NewSearcherByBleve

func NewSearcherByBleve(name, brief string, blogIndexer BlogIndexer) Searcher

searcher according to bleve file index engine

func NewSearcherByKeywork

func NewSearcherByKeywork(name, brief string, spider fspider.Spider, cache Cache, blogLoader *BlogLoader) Searcher

searcher according to search-keyword and keywords in meta

func NewSearcherByPlugin

func NewSearcherByPlugin(plugin SearcherPlugin, loader *BlogLoader, config *Config) Searcher

searcher according to plugin ; this func is not thread-safe

func NewSearcherByTitle

func NewSearcherByTitle(name, brief string, spider fspider.Spider, loader *BlogLoader) Searcher

searcher according to title edit distance

type SearcherPlugin

type SearcherPlugin struct {
	Name    string
	Brief   string
	Type    string
	Command string
	Disable bool
	Url     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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