From b24cc4d427ebca44624350a61d891779795adb2e Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Tue, 30 Sep 2025 11:09:27 +0200 Subject: [PATCH] setup base entity and change cli to print actions --- README.md | 30 ++++++++++++++++++++++++++++ gemlog/core.go | 39 ++++++++++++++++++++++++++++++++++++ gemlog/db.go | 0 gemlog/write.go | 1 + main.go | 41 ++++++++++++++------------------------ templates/default_post.gmi | 12 +++++++++++ 6 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 gemlog/core.go create mode 100644 gemlog/db.go create mode 100644 gemlog/write.go create mode 100644 templates/default_post.gmi diff --git a/README.md b/README.md index 2e1d470..461581c 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,33 @@ Quick tool to write gemtext posts for my gemlog. => gemini://travisshears.com/gemlog + + +## Entites + +Gemlog +- id, uuid +- title +- slug +- date +- gemtxt +- short? gemtxt < 250 char + + +## Arch + +For DB planning to use couch db + +## Use-cases + +### Create gemlog entry + +Open editor with pre-filled template with frontmatter. Set example date (now), title, slug + +### Delete gemlog entry + +Select from list then delete. + +### Edit gemlog entry + +Select from list then edit. diff --git a/gemlog/core.go b/gemlog/core.go new file mode 100644 index 0000000..d5f7e06 --- /dev/null +++ b/gemlog/core.go @@ -0,0 +1,39 @@ +package gemlog + +import ( + "crypto/rand" + "encoding/hex" + "fmt" + "time" +) + +// GemlogEntry represents a single gemlog post entry +type GemlogEntry struct { + ID string `json:"id"` + Title string `json:"title"` + Slug string `json:"slug"` + Date time.Time `json:"date"` + Gemtxt string `json:"gemtxt"` +} + +// NewUUID generates a new UUID v4 using crypto/rand +func NewUUID() (string, error) { + uuid := make([]byte, 16) + _, err := rand.Read(uuid) + if err != nil { + return "", fmt.Errorf("failed to generate UUID: %w", err) + } + + // Set version (4) and variant bits according to RFC 4122 + uuid[6] = (uuid[6] & 0x0f) | 0x40 // Version 4 + uuid[8] = (uuid[8] & 0x3f) | 0x80 // Variant bits + + // Format as standard UUID string: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx + return fmt.Sprintf("%s-%s-%s-%s-%s", + hex.EncodeToString(uuid[0:4]), + hex.EncodeToString(uuid[4:6]), + hex.EncodeToString(uuid[6:8]), + hex.EncodeToString(uuid[8:10]), + hex.EncodeToString(uuid[10:16]), + ), nil +} diff --git a/gemlog/db.go b/gemlog/db.go new file mode 100644 index 0000000..e69de29 diff --git a/gemlog/write.go b/gemlog/write.go new file mode 100644 index 0000000..83f8232 --- /dev/null +++ b/gemlog/write.go @@ -0,0 +1 @@ +package gemlog diff --git a/main.go b/main.go index 71cef0a..dea2c03 100644 --- a/main.go +++ b/main.go @@ -8,24 +8,18 @@ import ( ) type model struct { - cursor int - choices []string - selected map[int]struct{} + cursor int + actions []string } func initialModel() model { return model{ - choices: []string{"Buy carrots", "Buy celery", "Buy kohlrabi"}, - - // A map which indicates which choices are selected. We're using - // the map like a mathematical set. The keys refer to the indexes - // of the `choices` slice, above. - selected: make(map[int]struct{}), + actions: []string{"Write", "Read", "Edit", "Delete"}, } } func (m model) Init() tea.Cmd { - return tea.SetWindowTitle("Grocery List") + return tea.SetWindowTitle("Gemlog CLI") } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -39,16 +33,16 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.cursor-- } case "down", "j": - if m.cursor < len(m.choices)-1 { + if m.cursor < len(m.actions)-1 { m.cursor++ } - case "enter", " ": - _, ok := m.selected[m.cursor] - if ok { - delete(m.selected, m.cursor) - } else { - m.selected[m.cursor] = struct{}{} - } + // case "enter", " ": + // _, ok := m.selected[m.cursor] + // if ok { + // delete(m.selected, m.cursor) + // } else { + // m.selected[m.cursor] = struct{}{} + // } } } @@ -56,20 +50,15 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { } func (m model) View() string { - s := "What should we buy at the market?\n\n" + s := "Welcome to gemlog cli!\n\nWhat would you like to do?\n\n" - for i, choice := range m.choices { + for i, action := range m.actions { cursor := " " if m.cursor == i { cursor = ">" } - checked := " " - if _, ok := m.selected[i]; ok { - checked = "x" - } - - s += fmt.Sprintf("%s [%s] %s\n", cursor, checked, choice) + s += fmt.Sprintf("%s %s\n", cursor, action) } s += "\nPress q to quit.\n" diff --git a/templates/default_post.gmi b/templates/default_post.gmi new file mode 100644 index 0000000..ddb875b --- /dev/null +++ b/templates/default_post.gmi @@ -0,0 +1,12 @@ +title: todo +date: 2025-12-31 +slug: todo +tags: cat, dog +--- + +Example text + +=> https://travisshears.com example link + +* Example list item 1 +* Example list item 2