Browse Source

Resolves #37: Implement a gemini compatible output

v0.6.0-dev
bacardi55 10 months ago
parent
commit
455d028e48
  1. 25
      README.md
  2. BIN
      docs/images/gtl_gemini_screenshot.png
  3. BIN
      docs/images/gtl_gemini_screenshot_browser.png
  4. BIN
      docs/images/gtl_gemini_screenshot_gtl.png
  5. 4
      gtl.go
  6. 50
      ui/gemini.go
  7. 2
      ui/utils.go

25
README.md

@ -132,6 +132,21 @@ subscribed_data = "path/to/sub/file"
Screenshot of the CLI below.
### Use gtl gemini mode
You can use gtl to generate a valid text/gemini output that could then be place in a capsule and read via a gemini browser:
```bash
~/bin/gtl --config ~/.config/gtl/test.gtl.toml --mode gemini --limit 55
```
You can see an example used here:
gemini://tinylogs.gmi.bacardi55.io
Or see a screenshot below.
Funny thing, the format is compatible with the tinylog RFC, so you can subscribe to it via gtl (there is a screenshot of this below too).
## Configuration
### Default configuration file
@ -152,7 +167,7 @@ log_file = "/dev/null"
# Maximum number of entries showed in cli mode. If --limit is used, it will overide this setting.
# Will be ignored in tui mode.
cli_limit = 10
# Mode: either cli or tui
# Mode: either cli, tui or gemini
mode = "tui"
# If false, standard ascii characters will be used.
tui_status_emoji = false
@ -213,3 +228,11 @@ Subscription management usage:
![Gtl CLI screenshot](docs/images/gtl_screenshot.png)
### Gemini mode
![Gtl Gemini output screenshot](docs/images/gtl_gmi_screenshot.png)
![Gtl Gemini output in a browser screenshot](docs/images/gtl_gmi_screenshot_browser.png)
![Gtl Gemini output in gtl screenshot](docs/images/gtl_gmi_screenshot_gtl.png)

BIN
docs/images/gtl_gemini_screenshot.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

BIN
docs/images/gtl_gemini_screenshot_browser.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

BIN
docs/images/gtl_gemini_screenshot_gtl.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 KiB

4
gtl.go

@ -75,9 +75,9 @@ func main() {
// Display stream and quit.
var gtlUI ui.TlUI
if modeArg == "tui" || modeArg == "cli" {
if modeArg == "tui" || modeArg == "cli" || modeArg == "gemini" {
gtlUI.Mode = modeArg
} else if Data.Config.Mode == "tui" || Data.Config.Mode == "cli" {
} else if Data.Config.Mode == "tui" || Data.Config.Mode == "cli" || Data.Config.Mode == "gemini" {
gtlUI.Mode = Data.Config.Mode
} else {
fmt.Printf("Unknown mode, fallback on TUI.")

50
ui/gemini.go

@ -0,0 +1,50 @@
package ui
import (
"fmt"
"strconv"
"strings"
"time"
"git.bacardi55.io/bacardi55/gtl/core"
)
func displayStreamGemini(data *core.TlData, limit int) error {
e := data.RefreshFeeds()
if e != nil {
return fmt.Errorf("Couldn't refresh feeds")
}
stream := data.Stream
var max int
max = len(stream.Items) - 1
if limit > 0 && limit < max {
max = limit
}
output := "# Tinylog timeline generated by gtl\n"
output += "author: @gtl\n"
output += "last refresh: " + time.Now().Format(data.Config.Date_format)
output += "\n=> https://codeberg.org/bacardi55/gemini-tinylog-rfc Tinylog RFC"
output += "\ncurrently agregating " + strconv.Itoa(len(data.Feeds)) + " tinylogs\n\n"
for i := 0; i < max; i++ {
output += "## "
output += stream.Items[i].Published.Format(data.Config.Date_format)
output += "\n### author: "
output += stream.Items[i].Author
output += "\n" + stream.Items[i].Content + "\n\n"
}
output += "=> https://github.com/bacardi55/gtl gtl\n\n"
var authors []string
for _, f := range data.Feeds {
authors = append(authors, f.DisplayName)
}
output += "Agregated tinylogs: " + strings.Join(authors, ", ")
fmt.Println(output)
return nil
}

2
ui/utils.go

@ -19,6 +19,8 @@ func (Ui *TlUI) Run(data *core.TlData, limit int) error {
return displayStreamCli(data, limit)
} else if Ui.Mode == "tui" {
return displayStreamTui(data)
} else if Ui.Mode == "gemini" {
return displayStreamGemini(data, limit)
} else {
return fmt.Errorf("Unknown mode.")
}

Loading…
Cancel
Save