draft shits
This commit is contained in:
53
internal/note/note.go
Normal file
53
internal/note/note.go
Normal file
@ -0,0 +1,53 @@
|
||||
package note
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
ID string
|
||||
Path string
|
||||
Title string
|
||||
Content string
|
||||
// HTMLContent string
|
||||
ModTime time.Time
|
||||
// Directly in Note
|
||||
Tags []string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Published bool
|
||||
}
|
||||
|
||||
func NewNote() *Note {
|
||||
return &Note{}
|
||||
}
|
||||
|
||||
// ExtractTitle return the first level heading content ('# title')
|
||||
func ExtractTitle(mkd string) string {
|
||||
if mkd == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(mkd, "# ") {
|
||||
return ""
|
||||
}
|
||||
|
||||
var title string
|
||||
for _, c := range strings.TrimLeft(mkd, "# ") {
|
||||
if strings.Contains("*~", string(c)) {
|
||||
continue
|
||||
}
|
||||
if string(c) == "\n" {
|
||||
break
|
||||
}
|
||||
title = title + string(c)
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
func GenerateNoteID(path string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(path)))[:10]
|
||||
}
|
||||
Reference in New Issue
Block a user