Generate frontmatter for new files not yet on disk
When reading body of a newly created note that hasn't been saved, generate YAML frontmatter from the note's metadata instead of returning empty string.
This commit is contained in:
parent
6dcb57db45
commit
6f8db9e050
|
|
@ -1025,13 +1025,16 @@ func (s *server) getFileContent(path string) string {
|
|||
|
||||
// readBody reads the file content, normalizing frontmatter tags if needed.
|
||||
// Malformed tags are fixed in place and the file is renamed if necessary.
|
||||
// For new files not yet on disk, generates frontmatter from metadata.
|
||||
func (s *server) readBody(note *metadata.Metadata) string {
|
||||
if note.Path == "" {
|
||||
return ""
|
||||
}
|
||||
data, err := os.ReadFile(note.Path)
|
||||
if err != nil {
|
||||
return ""
|
||||
// File doesn't exist yet - generate frontmatter from metadata
|
||||
fm := metadata.NewFrontMatter(note.Title, note.Signature, note.Tags, note.Identifier)
|
||||
return string(frontmatter.Marshal(fm, metadata.FileTypeMdYaml))
|
||||
}
|
||||
ext := filepath.Ext(note.Path)
|
||||
fm, fileType, _ := frontmatter.Unmarshal(data, ext)
|
||||
|
|
|
|||
Loading…
Reference in New Issue