Documentation
¶
Overview ¶
Package hooks 定义内核派发给插件的动作与过滤器:名字与数据结构。
这是内核与插件之间的公开契约,插件 SDK(sdk/go)里有一份同形的类型。 改字段就是改接口:只能加,不能改名或删;要大改就起一个新名字。
本包不依赖任何模块:发出动作的内容、评论、账号模块与接收它们的插件模块都引用它, 它自己不能反过来引用任何一方。
Index ¶
Constants ¶
View Source
const ( // PostPublished 是文章或页面发布(含定时发布到点),数据为 Post。 PostPublished = "post.published" // PostUpdated 是文章或页面被保存(任何状态),数据为 Post。 PostUpdated = "post.updated" // PostTrashed 是文章或页面移入回收站,数据为 Post。 PostTrashed = "post.trashed" // PostDeleted 是文章或页面被彻底删除,数据为 Post。 PostDeleted = "post.deleted" // CommentCreated 是收到新评论(含待审与判为垃圾的),数据为 Comment。 CommentCreated = "comment.created" // CommentApproved 是评论通过审核,数据为 Comment。 CommentApproved = "comment.approved" // UserRegistered 是新建了用户(前台注册或后台创建),数据为 User。 UserRegistered = "user.registered" )
动作:事情发生之后异步通知,插件改变不了已经发生的事。
View Source
const ( // CommentJudge 在新评论入库前决定它的状态,值为 CommentJudgement。 CommentJudge = "comment.judge" // ContentRender 在文章与页面正文输出到前台之前改写它,值为 RenderedContent。结果会再净化一遍。 ContentRender = "content.render" )
过滤器:把数据交给插件改一遍再用,同步执行、有时限,超时或出错就用原值。
View Source
const ( // SlotHead 在 </head> 之前:插件的样式表与 meta 标签。 SlotHead = "head" SlotFooter = "footer" // SlotContentBefore 在文章与页面的正文之前。 SlotContentBefore = "content.before" // SlotContentAfter 在文章与页面的正文之后。 SlotContentAfter = "content.after" // SlotCommentsAfter 在评论区之后。 SlotCommentsAfter = "comments.after" )
前台插槽:主题在页面的固定位置调 {{ .Slot "名字" }},插件往里放东西。
View Source
const PostsPrefix = "/posts/"
PostsPrefix 是文章详情页的路径前缀;页面直接挂在站点根下。
Variables ¶
View Source
var Slots = []string{SlotHead, SlotContentBefore, SlotContentAfter, SlotCommentsAfter, SlotFooter}
Slots 是全部插槽,按在页面里出现的先后排。
Functions ¶
Types ¶
type Comment ¶
type Comment struct {
ID int64 `json:"id"`
ParentID *int64 `json:"parentId,omitempty"`
Post PostRef `json:"post"`
Author CommentAuthor `json:"author"`
// Content 是评论原文(纯文本)。
Content string `json:"content"`
Status string `json:"status"`
IP string `json:"ip"`
UserAgent string `json:"userAgent"`
CreatedAt time.Time `json:"createdAt"`
}
Comment 是评论动作的数据。
type CommentAuthor ¶
type CommentAuthor struct {
Name string `json:"name"`
Email string `json:"email"`
URL string `json:"url"`
// UserID 是已登录评论者的账号;访客为 nil。
UserID *int64 `json:"userId,omitempty"`
}
CommentAuthor 是评论者。邮箱与 IP 只给被授予了「读取站点内容」的插件(反垃圾离不开它们)。
type CommentJudgement ¶
type CommentJudgement struct {
// Comment 是待判定的评论,此时还没入库,ID 为零。
Comment Comment `json:"comment"`
Status string `json:"status"`
// Reason 是插件给出的理由,写进日志,便于站长复查。
Reason string `json:"reason,omitempty"`
}
CommentJudgement 是 comment.judge 过滤器的值:插件读评论、改 Status。
Status 只认 approved、pending、spam;改成别的值会被忽略。内核自己的频率限制与蜜罐 判为垃圾的评论,插件改不回来。
type Page ¶
type Page struct {
// Kind 是页面种类:index、post、page、category、tag、archive、search、author、posts、404 等。
Kind string `json:"kind"`
// Path 是请求路径。
Path string `json:"path"`
Title string `json:"title"`
// Post 在文章与页面上是当前内容,其余为 nil。
Post *PostRef `json:"post,omitempty"`
}
Page 是插槽、小组件与短代码收到的当前页面。
type Post ¶
type Post struct {
ID int64 `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Slug string `json:"slug"`
// Path 是前台路径,拼上站点地址就是完整链接。
Path string `json:"path"`
Status string `json:"status"`
AuthorID int64 `json:"authorId"`
// PublishedAt 是发布时间;从没发布过时为 nil。
PublishedAt *time.Time `json:"publishedAt,omitempty"`
}
Post 是文章或页面动作的数据。
type PostRef ¶
type PostRef struct {
ID int64 `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Path string `json:"path"`
}
PostRef 是评论等数据里引用的文章或页面。
type RenderedContent ¶
RenderedContent 是 content.render 过滤器的值:插件改 HTML。
Click to show internal directories.
Click to hide internal directories.