Compare commits

...

6 commits
v1.0.0 ... main

9 changed files with 120 additions and 4 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
debug.log
/bin

View file

@ -4,6 +4,29 @@ 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:

View file

@ -0,0 +1,24 @@
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
}

5
build.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
go build -o ./bin/gemlog-cli

View file

@ -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", config.CouchDB.Host, config.CouchDB.Port)
url := fmt.Sprintf("%s:%d/gemlog/_design/gemlog-cli/_view/list?descending=true", 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,6 +123,69 @@ 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)

View file

@ -118,7 +118,7 @@ func (m model) View() string {
return s
}
var enableLogs bool = true
var enableLogs bool = false
func Run(config *gemlog.Config) {
if enableLogs {

View file

@ -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(actions)-1 {
if m.cursor < len(m.entries)-1 {
m.cursor++
}
case "left", "h":

View file

@ -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() {