From cc7bb4212e4b2ea8b262409d8d43fe1b95049b52 Mon Sep 17 00:00:00 2001 From: 54L1M Date: Wed, 25 Nov 2026 09:49:53 +0100 Subject: [PATCH] feat: write company, role, fit, verdict, location and posting as note properties --- jobhunt_test.go | 2 +- note.go | 18 +++++++++++++++--- scan_test.go | 7 +++++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/jobhunt_test.go b/jobhunt_test.go index 09d41cc..3dd41bf 100644 --- a/jobhunt_test.go +++ b/jobhunt_test.go @@ -252,7 +252,7 @@ func TestRenderNote(t *testing.T) { } note := renderNote(pkg, "https://x.test/job", time.Date(2026, 11, 24, 10, 0, 0, 0, time.UTC)) for _, want := range []string{ - "moc: \"[[00-Job Hunt]]\"\ncreated: 2026-11-24", "# Acme - Backend Engineer", "- [ ] Review and decide: **apply**, fit 82/100", + "moc: \"[[00-Job Hunt]]\"\ncreated: 2026-11-24\ncompany: \"Acme\"\nrole: \"Backend Engineer\"\nfit: 82\nverdict: \"apply\"\nlocation: \"Utrecht\"\nposting: \"https://x.test/job\"\n---", "# Acme - Backend Engineer", "- [ ] Review and decide: **apply**, fit 82/100", "- **Posting:** https://x.test/job", "## Strengths\n- Go at Ghaaf", "## Gaps\n- No Dutch", "## Cover letter draft\nDear hiring team,", "## Related\n- [[00-Job Hunt|Job Hunt]]\n- [[CV]]", } { diff --git a/note.go b/note.go index 25b51f2..3148fa3 100644 --- a/note.go +++ b/note.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "errors" "fmt" "io/fs" @@ -43,11 +44,22 @@ func bullets(b *strings.Builder, heading string, items []string) { b.WriteString("\n") } -// renderNote writes the package as a vault note: small frontmatter, plain -// title, a Related section at the end. +// yamlString quotes a value for the frontmatter. A JSON string is also a +// valid YAML double-quoted string, whatever the posting put in it. +func yamlString(s string) string { + b, _ := json.Marshal(strings.Join(strings.Fields(s), " ")) + return string(b) +} + +// renderNote writes the package as a vault note: frontmatter, plain title, a +// Related section at the end. The properties after `created` are the columns +// of the vault's "Job Hunt" base (the table of all postings). func renderNote(pkg *Package, url string, now time.Time) string { var b strings.Builder - fmt.Fprintf(&b, "---\nmoc: \"[[00-Job Hunt]]\"\ncreated: %s\n---\n\n", now.Format("2006-01-02")) + fmt.Fprintf(&b, "---\nmoc: \"[[00-Job Hunt]]\"\ncreated: %s\n", now.Format("2006-01-02")) + fmt.Fprintf(&b, "company: %s\nrole: %s\nfit: %d\nverdict: %s\nlocation: %s\nposting: %s\n---\n\n", + yamlString(pkg.Company), yamlString(pkg.Title), pkg.FitScore, yamlString(strings.ToLower(pkg.Verdict)), + yamlString(pkg.Location), yamlString(url)) fmt.Fprintf(&b, "# %s\n\n", noteName(pkg)) fmt.Fprintf(&b, "- [ ] Review and decide: **%s**, fit %d/100\n\n", strings.ToLower(pkg.Verdict), pkg.FitScore) if pkg.VerdictReason != "" { diff --git a/scan_test.go b/scan_test.go index 1171e12..aa08122 100644 --- a/scan_test.go +++ b/scan_test.go @@ -332,3 +332,10 @@ func TestParsePackageMalformedAnswer(t *testing.T) { t.Errorf("the error should quote the answer near the fault, got %v", err) } } + +func TestYAMLString(t *testing.T) { + // A hostile or just odd title must stay one quoted scalar in the frontmatter. + if got, want := yamlString("Engineer: \"Core\"\n---\nfit: 100"), `"Engineer: \"Core\" --- fit: 100"`; got != want { + t.Errorf("yamlString = %s, want %s", got, want) + } +}