54 lines
842 B
Go
54 lines
842 B
Go
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]
|
|
}
|