From a588e6e573358429cfe337e51a79e7ead7876c24 Mon Sep 17 00:00:00 2001 From: Arnas Udovicius Date: Tue, 30 Aug 2022 20:14:05 +0300 Subject: [PATCH] ndex file not in category list; index file redirects to category --- README.md | 3 +++ main.go | 3 +++ templates/category.gmi | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cba0f22..869b639 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,6 @@ __DONE__ * migrate to gRPC * routing, not found * template engine +* all other languages under sgs +* index file redirects to category +* index file displayed as intro to category diff --git a/main.go b/main.go index 1840143..11deff8 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,9 @@ func process(_ context.Context, w gemini.ResponseWriter, r *gemini.Request) { renderSearch(lang, w, r, client) case regexp.MustCompile(`^/(sgs|en)/f/?$`).MatchString(r.URL.Path): renderAllFiles(lang, w, client) + case regexp.MustCompile(`^/(sgs|en)/f/([\p{L}\d_+.]+/)+[\d\w]+/index.gmi$`).MatchString(r.URL.Path): + urlParts := strings.Split(r.URL.Path, "/") + w.WriteHeader(gemini.StatusPermanentRedirect, strings.Join(urlParts[:(len(urlParts)-2)], "/")) case regexp.MustCompile(`^/(sgs|en)/f/([\p{L}\d_+.]+/)+[\d\w]+/[\p{L}\d_+.]+.gmi$`).MatchString(r.URL.Path): renderFile(lang, w, r, client) case regexp.MustCompile(`^/(sgs|en)/f/[\p{L}\d_+.]+(/[\p{L}\d_+.]+)*/?$`).MatchString(r.URL.Path): diff --git a/templates/category.gmi b/templates/category.gmi index 34c4e93..fdfbdb1 100644 --- a/templates/category.gmi +++ b/templates/category.gmi @@ -6,7 +6,7 @@ 🌙 {{ indexFile.File.Created}} {{ indexFile.File.Copyright }}{% endif %} -{% for file in tree.RootFiles %}{{ text_url(lang, file) }} +{% for file in tree.RootFiles %}{% if file.Name != "index.md" %}{{ text_url(lang, file) }}{% endif %} {% endfor %} {% if tree.Categories %}### {% if lang == "sgs" %}Kateguorėjės{% else %}Categories{% endif %} {% for cat, count in tree.Categories %}{{ category_url(lang, tree.Path|add:"/"|add:cat, cat, count) }}