diff --git a/.gitignore b/.gitignore index bf5e268..b14c548 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ debug.log -/bin diff --git a/README.md b/README.md index 80352bb..060133d 100644 --- a/README.md +++ b/README.md @@ -4,29 +4,6 @@ Quick tool to write gemtext posts for my gemlog. => gemini://travisshears.com/gemlog -## Install - -Build and link. Remember to setup config file as well. - -```shell -$ go build -o bin/gemlog -$ ln -s /Users/xxxxxxxx/_projects/gemlog-cli/bin/gemlog-cli ~/bin/gemlog -``` - -## Config setup - -This app relys on a config file at `~/.config/gemlog-cli/config.yml` - -With the following format: - -```yaml -couchdb: - host: http://myhost - port: 1234 - user: gemlog-cli - password: xxxxxxxxxxxxxxxxxxxxxxxxxxx -``` - ## Dev To run command locally: diff --git a/bruno/Gemlog/Get Gemlog By Slug.bru b/bruno/Gemlog/Get Gemlog By Slug.bru deleted file mode 100644 index f02e8a2..0000000 --- a/bruno/Gemlog/Get Gemlog By Slug.bru +++ /dev/null @@ -1,24 +0,0 @@ -meta { - name: Get Gemlog By Slug - type: http - seq: 6 -} - -get { - url: http://eisenhorn:5023/gemlog/_design/capsule/_view/post_by_slug?key="hello-from-gemlog-cli" - body: json - auth: basic -} - -params:query { - key: "hello-from-gemlog-cli" -} - -auth:basic { - username: gemlog-cli - password: {{pw}} -} - -settings { - encodeUrl: true -} diff --git a/build.sh b/build.sh deleted file mode 100755 index 5ad72f6..0000000 --- a/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -set -e - -go build -o ./bin/gemlog-cli diff --git a/gemlog/db.go b/gemlog/db.go index 3d7ed0f..e3b0efa 100644 --- a/gemlog/db.go +++ b/gemlog/db.go @@ -17,7 +17,7 @@ func genBasicAuthHeader(user, password string) string { } func ListGemLogs(config *Config) ([]GemlogListEntry, error) { - url := fmt.Sprintf("%s:%d/gemlog/_design/gemlog-cli/_view/list?descending=true", config.CouchDB.Host, config.CouchDB.Port) + url := fmt.Sprintf("%s:%d/gemlog/_design/gemlog-cli/_view/list", config.CouchDB.Host, config.CouchDB.Port) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) @@ -123,69 +123,6 @@ func ReadGemlogEntry(config *Config, id string) (GemlogEntry, error) { }, nil } -func ReadGemlogEntryBySlug(config *Config, slug string) (GemlogEntry, error) { - url := fmt.Sprintf("%s:%d/gemlog/_design/capsule/_view/post_by_slug?key=\"%s\"", config.CouchDB.Host, config.CouchDB.Port, slug) - req, err := http.NewRequest("GET", url, nil) - if err != nil { - return GemlogEntry{}, fmt.Errorf("failed to create request: %w", err) - } - - req.Header.Add("authorization", genBasicAuthHeader(config.CouchDB.User, config.CouchDB.Password)) - req.Header.Add("content-type", "application/json") - - res, err := http.DefaultClient.Do(req) - if err != nil { - return GemlogEntry{}, fmt.Errorf("failed to send request: %w", err) - } - defer res.Body.Close() - - body, err := io.ReadAll(res.Body) - if err != nil { - return GemlogEntry{}, fmt.Errorf("failed to read response body: %w", err) - } - - if res.StatusCode < 200 || res.StatusCode >= 300 { - return GemlogEntry{}, fmt.Errorf("unexpected status code %d: %s", res.StatusCode, string(body)) - } - - // Decode CouchDB view response - var viewResponse struct { - TotalRows int `json:"total_rows"` - Offset int `json:"offset"` - Rows []struct { - ID string `json:"id"` - Key string `json:"key"` - Value struct { - ID string `json:"_id"` - Rev string `json:"_rev"` - Title string `json:"title"` - Slug string `json:"slug"` - Date time.Time `json:"date"` - Gemtxt string `json:"gemtxt"` - } `json:"value"` - } `json:"rows"` - } - - if err := json.Unmarshal(body, &viewResponse); err != nil { - return GemlogEntry{}, fmt.Errorf("failed to parse response: %w", err) - } - - // Check if we got any results - if len(viewResponse.Rows) == 0 { - return GemlogEntry{}, fmt.Errorf("no document found with slug: %s", slug) - } - - // Extract the first (and should be only) result - doc := viewResponse.Rows[0].Value - - return GemlogEntry{ - Title: doc.Title, - Slug: doc.Slug, - Date: doc.Date, - Gemtxt: doc.Gemtxt, - }, nil -} - func DeleteGemlogEntry(config *Config, id string, rev string) error { url := fmt.Sprintf("%s:%d/gemlog/%s?rev=%s", config.CouchDB.Host, config.CouchDB.Port, id, rev) req, err := http.NewRequest("DELETE", url, nil) diff --git a/internal/ui/app.go b/internal/ui/app.go index a52c1a8..f3fce1c 100644 --- a/internal/ui/app.go +++ b/internal/ui/app.go @@ -118,7 +118,7 @@ func (m model) View() string { return s } -var enableLogs bool = false +var enableLogs bool = true func Run(config *gemlog.Config) { if enableLogs { diff --git a/internal/config/config.go b/internal/ui/config/config.go similarity index 100% rename from internal/config/config.go rename to internal/ui/config/config.go diff --git a/internal/ui/entryList.go b/internal/ui/entryList.go index 0331cab..5be6dfc 100644 --- a/internal/ui/entryList.go +++ b/internal/ui/entryList.go @@ -39,7 +39,7 @@ func (m EntryListPageModel) Update(msg tea.Msg, active bool, ctx *context) (Entr m.cursor-- } case "down", "j": - if m.cursor < len(m.entries)-1 { + if m.cursor < len(actions)-1 { m.cursor++ } case "left", "h": diff --git a/main.go b/main.go index 7de4196..3c1c08a 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - config "git.travisshears.com/travisshears/gemlog-cli/internal/config" ui "git.travisshears.com/travisshears/gemlog-cli/internal/ui" + config "git.travisshears.com/travisshears/gemlog-cli/internal/ui/config" ) func main() {