wp-go/internal/plugins/posts.go

33 lines
946 B
Go
Raw Normal View History

2023-01-12 12:42:16 +00:00
package plugins
import (
"fmt"
"github.com/fthvgb1/wp-go/internal/pkg/models"
2023-01-12 12:42:16 +00:00
"github.com/gin-gonic/gin"
)
func NewPostPlugin(ctx *gin.Context, scene int) *Plugin[models.Posts] {
2023-01-12 12:42:16 +00:00
p := NewPlugin[models.Posts](nil, -1, nil, scene, ctx)
p.Push(Digest)
return p
}
func ApplyPlugin(p *Plugin[models.Posts], post *models.Posts) {
p.post = post
p.Next()
p.index = -1
}
func PasswordProjectTitle(post *models.Posts) {
2023-02-06 14:56:36 +00:00
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
2023-01-12 12:42:16 +00:00
}
func PasswdProjectContent(post *models.Posts) {
2023-02-06 14:56:36 +00:00
format := `
2023-01-12 12:42:16 +00:00
<form action="/login" class="post-password-form" method="post">
<p>此内容受密码保护如需查阅请在下列字段中输入您的密码</p>
<p><label for="pwbox-%d">密码 <input name="post_password" id="pwbox-%d" type="password" size="20"></label> <input type="submit" name="Submit" value="提交"></p>
</form>`
2023-02-06 14:56:36 +00:00
post.PostContent = fmt.Sprintf(format, post.Id, post.Id)
2023-01-12 12:42:16 +00:00
}