- New 'Import Obsidian' action on site settings page - Upload a zip file of an Obsidian vault to import all notes as posts - Markdown notes imported with title from filename, published date from file timestamp, and body with front-matter stripped - Images and other attachments saved as Upload records - New obsimport service handles zip traversal and import logic - Unit tests for front-matter stripping Co-authored-by: Shelley <shelley@exe.dev> Co-authored-by: exe.dev user <exedev@kernel-leviathan.exe.xyz> Reviewed-on: #8
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package obsimport
|
|
|
|
import "testing"
|
|
|
|
func TestStripFrontMatter(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
}{
|
|
{
|
|
name: "no front matter",
|
|
input: "Hello world\nThis is a note",
|
|
want: "Hello world\nThis is a note",
|
|
},
|
|
{
|
|
name: "with front matter",
|
|
input: "---\ntitle: Test\ntags: [a, b]\n---\nHello world\nThis is a note\n",
|
|
want: "Hello world\nThis is a note\n",
|
|
},
|
|
{
|
|
name: "only front matter",
|
|
input: "---\ntitle: Test\n---\n",
|
|
want: "",
|
|
},
|
|
{
|
|
name: "unclosed front matter",
|
|
input: "---\ntitle: Test\nno closing delimiter",
|
|
want: "---\ntitle: Test\nno closing delimiter",
|
|
},
|
|
{
|
|
name: "empty string",
|
|
input: "",
|
|
want: "",
|
|
},
|
|
{
|
|
name: "front matter with leading newlines stripped",
|
|
input: "---\nkey: val\n---\n\n\nBody here\n",
|
|
want: "Body here\n",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := stripFrontMatter(tt.input)
|
|
if got != tt.want {
|
|
t.Errorf("stripFrontMatter() = %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|