summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--repo.go11
-rw-r--r--templates/repo_home.gmi2
-rw-r--r--templates/repo_home.gophermap4
3 files changed, 15 insertions, 2 deletions
diff --git a/repo.go b/repo.go
index 72291b6..938bcc9 100644
--- a/repo.go
+++ b/repo.go
@@ -211,10 +211,19 @@ type Readme struct {
RawContents string
}
-func (r Readme) EscapedContents() string {
+func (r Readme) GeminiEscapedContents() string {
return strings.ReplaceAll(r.RawContents, "\n```", "\n ```")
}
+func (r Readme) GopherEscapedContents(selector, host, port string) string {
+ trailer := "\t"+selector+"\t"+host+"\t"+port+"\r\n"
+ lines := strings.Split(r.RawContents, "\n")
+ for i := range lines {
+ lines[i] = "i"+strings.TrimRight(strings.ReplaceAll(lines[i], "\t", " "), "\r\n") + trailer
+ }
+ return strings.Join(lines, "")
+}
+
func (r *Repository) Readme(ctx context.Context, ref string) (*Readme, error) {
dir, err := r.Tree(ctx, ref, "")
if err != nil {
diff --git a/templates/repo_home.gmi b/templates/repo_home.gmi
index a2af514..9d62f3c 100644
--- a/templates/repo_home.gmi
+++ b/templates/repo_home.gmi
@@ -22,7 +22,7 @@
## {{.Filename}}
```{{.Filename}} contents
-{{.EscapedContents}}
+{{.GeminiEscapedContents}}
```
{{ end -}}
{{ end }}
diff --git a/templates/repo_home.gophermap b/templates/repo_home.gophermap
index 17f06f7..2ab17c2 100644
--- a/templates/repo_home.gophermap
+++ b/templates/repo_home.gophermap
@@ -17,4 +17,8 @@ i {{.Selector}} {{.Host}} {{.Port}}
i(no commits to show) {{$.Selector}} {{$.Host}} {{$.Port}}
{{ end -}}
{{ end -}}
+i {{.Selector}} {{.Host}} {{.Port}}
+{{ with .Repo.Readme .Ctx "HEAD" -}}
+{{ .GopherEscapedContents $.Selector $.Host $.Port }}
+{{ end -}}
.