~nbsp/cassini

f1be17e90368fe41dcff7968a3fc142b2869a2ac — Sol Fisher Romanoff 2 years ago c287d7c
Add option to show list on index page

Fixes: https://todo.sr.ht/~sfr/cassini/4
2 files changed, 14 insertions(+), 0 deletions(-)

M README.md
M main.go
M README.md => README.md +3 -0
@@ 33,6 33,9 @@ user2 gemini://example.net/~user2
user3 gemini://example.com/welcome.gmi
```

the index file can optionally contain the keyword `{{ list }}`, which will be 
substituted for a list of all members in the list.

## linking

- `gemini://example.org/next/<user>` to go to to the next capsule in the ring

M main.go => main.go +11 -0
@@ 2,6 2,7 @@ package main

import (
	"bufio"
	"bytes"
	"crypto/tls"
	"fmt"
	"io"


@@ 161,6 162,16 @@ func serveRing(conn io.ReadWriteCloser, capsules [][]string) {
			log.Fatal("error while loading index file: ", err)
		}

		// if contains {{ list }}, replace it with the list
		if bytes.Contains(content, []byte("{{ list }}")) {
			log.Println("inserting ring member list")
			var links string
			for _, capsule := range capsules {
				links += fmt.Sprintf("=> %s %s\n", capsule[1], capsule[0])
			}
			content = bytes.Replace(content, []byte("{{ list }}"), []byte(links), -1)
		}

		response(conn, 20, "text/gemini; lang=en; charset=utf-8")
		_, err = conn.Write(content)
		if err != nil {