Support @subdir in /new to specify subdirectory path

This commit is contained in:
Levi Neely 2026-04-08 13:20:59 +02:00
parent 6f8db9e050
commit 29c69397da
1 changed files with 12 additions and 4 deletions

View File

@ -566,7 +566,7 @@ func (s *server) dispatchWrite(f *fid, tag uint16) *plan9.Fcall {
// Handle writes to /new
if f.path == "/new" {
// Parse: 'Title' ==signature tag1,tag2,...
// Parse: 'Title' ==signature tag1,tag2 @subdir
if !strings.HasPrefix(input, "'") {
return errorFcall(fc, "title must be single-quoted")
}
@ -584,19 +584,27 @@ func (s *server) dispatchWrite(f *fid, tag uint16) *plan9.Fcall {
remainder := strings.TrimSpace(input[closeQuote+2:])
var signature string
var tags []string
var subdir string
if remainder != "" {
if strings.HasPrefix(remainder, "==") {
spaceIdx := strings.Index(remainder, " ")
if spaceIdx == -1 {
signature = remainder[2:]
remainder = ""
} else {
signature = remainder[2:spaceIdx]
remainder = strings.TrimSpace(remainder[spaceIdx+1:])
}
}
if remainder != "" && !strings.HasPrefix(remainder, "==") {
// Extract @subdir if present
if atIdx := strings.LastIndex(remainder, "@"); atIdx != -1 {
subdir = strings.TrimSpace(remainder[atIdx+1:])
remainder = strings.TrimSpace(remainder[:atIdx])
}
if remainder != "" {
tagPattern := regexp.MustCompile(`^([\p{Ll}\p{Nd}]+,)*[\p{Ll}\p{Nd}]+$`)
if !tagPattern.MatchString(remainder) {
return errorFcall(fc, "tags must be comma-delimited lowercase unicode words (no spaces)")
@ -608,7 +616,7 @@ func (s *server) dispatchWrite(f *fid, tag uint16) *plan9.Fcall {
identifier := time.Now().Format("20060102T150405")
fm := metadata.NewFrontMatter(title, signature, tags, identifier)
fileName := metadata.BuildFilename(fm, ".md")
path := filepath.Join(s.denoteDir, fileName)
path := filepath.Join(s.denoteDir, subdir, fileName)
meta := &metadata.Metadata{
Identifier: identifier,
Signature: signature,