Have got soft and hard deleting
This commit is contained in:
parent
aef3bb6a1e
commit
3ea5823ca0
27 changed files with 588 additions and 55 deletions
|
|
@ -6,3 +6,4 @@ var UserRequiredError = errors.New("user required")
|
|||
var PermissionError = errors.New("permission denied")
|
||||
var NotFoundError = errors.New("not found")
|
||||
var SiteRequiredError = errors.New("site required")
|
||||
var DeleteDebounceError = errors.New("permanent delete too soon, try again in a few seconds")
|
||||
|
|
|
|||
|
|
@ -8,15 +8,36 @@ import (
|
|||
"unicode"
|
||||
)
|
||||
|
||||
const (
|
||||
StatePublished = iota
|
||||
StateDraft
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
ID int64
|
||||
SiteID int64
|
||||
GUID string
|
||||
Title string
|
||||
Body string
|
||||
Slug string
|
||||
CreatedAt time.Time
|
||||
PublishedAt time.Time
|
||||
ID int64 `json:"id"`
|
||||
SiteID int64 `json:"site_id"`
|
||||
State int `json:"state"`
|
||||
GUID string `json:"guid"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
Slug string `json:"slug"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at,omitempty"`
|
||||
DeletedAt time.Time `json:"deleted_at,omitempty"`
|
||||
PublishedAt time.Time `json:"published_at,omitempty"`
|
||||
}
|
||||
|
||||
func (p *Post) NanoSummary() string {
|
||||
if p.Title != "" {
|
||||
return p.Title
|
||||
}
|
||||
firstWords := firstNWords(p.Body, 7, wordForSummary)
|
||||
if firstWords == "" {
|
||||
firstWords = "(no content)"
|
||||
} else if len(firstWords) < len(p.Body) {
|
||||
return firstWords + "..."
|
||||
}
|
||||
return firstWords
|
||||
}
|
||||
|
||||
func (p *Post) BestSlug() string {
|
||||
|
|
@ -46,6 +67,10 @@ func (p *Post) BestSlug() string {
|
|||
return fmt.Sprintf("/%s/%s", datePart, slugPath)
|
||||
}
|
||||
|
||||
func wordForSummary(word string) string {
|
||||
return word
|
||||
}
|
||||
|
||||
func wordForSlug(word string) string {
|
||||
var sb strings.Builder
|
||||
for _, c := range word {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue