feat: Implement foundation layer with domain entities and repository interfaces
- Add complete domain layer: Note, Vault, WikiLink, Tag, Frontmatter, Graph entities - Implement repository interfaces for data access abstraction - Create comprehensive configuration system with YAML and env support - Add CLI entry point with signal handling and graceful shutdown - Fix mermaid diagram syntax in design.md (array notation) - Add CLAUDE.md for development guidance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
78
internal/domain/wikilink.go
Normal file
78
internal/domain/wikilink.go
Normal file
@@ -0,0 +1,78 @@
|
||||
package domain
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type WikiLink struct {
|
||||
target string
|
||||
alias string
|
||||
section string
|
||||
}
|
||||
|
||||
func NewWikiLink(target string, alias string, section string) (*WikiLink, error) {
|
||||
if target == "" {
|
||||
return nil, fmt.Errorf("wikilink target cannot be empty")
|
||||
}
|
||||
|
||||
return &WikiLink{
|
||||
target: target,
|
||||
alias: alias,
|
||||
section: section,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (w *WikiLink) Target() string {
|
||||
return w.target
|
||||
}
|
||||
|
||||
func (w *WikiLink) Alias() string {
|
||||
return w.alias
|
||||
}
|
||||
|
||||
func (w *WikiLink) Section() string {
|
||||
return w.section
|
||||
}
|
||||
|
||||
func (w *WikiLink) IsValid() bool {
|
||||
return w.target != ""
|
||||
}
|
||||
|
||||
func (w *WikiLink) String() string {
|
||||
var parts []string
|
||||
|
||||
if w.alias != "" {
|
||||
return fmt.Sprintf("[[%s|%s]]", w.target, w.alias)
|
||||
}
|
||||
|
||||
if w.section != "" {
|
||||
return fmt.Sprintf("[[%s#%s]]", w.target, w.section)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("[[%s]]", w.target)
|
||||
}
|
||||
|
||||
func ParseWikiLink(linkText string) (*WikiLink, error) {
|
||||
linkText = strings.Trim(linkText, "[]")
|
||||
|
||||
if linkText == "" {
|
||||
return nil, fmt.Errorf("empty wikilink")
|
||||
}
|
||||
|
||||
var target, alias, section string
|
||||
|
||||
if strings.Contains(linkText, "|") {
|
||||
parts := strings.SplitN(linkText, "|", 2)
|
||||
target = strings.TrimSpace(parts[0])
|
||||
alias = strings.TrimSpace(parts[1])
|
||||
} else if strings.Contains(linkText, "#") {
|
||||
parts := strings.SplitN(linkText, "#", 2)
|
||||
target = strings.TrimSpace(parts[0])
|
||||
section = strings.TrimSpace(parts[1])
|
||||
} else {
|
||||
target = strings.TrimSpace(linkText)
|
||||
}
|
||||
|
||||
return NewWikiLink(target, alias, section)
|
||||
}
|
||||
Reference in New Issue
Block a user