aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-05 00:00:23 +0700
committerShulhan <ms@kilabit.info>2026-02-05 03:40:34 +0700
commitaba22ce712d13b0b99b56a860f57c9142d9440e3 (patch)
tree33a9bcddd4b8fafa4cbb1b31696de13ccbdd1b63
parentb447e8991270ddf634761c7a6b7daf411211f2a5 (diff)
downloadciigo-aba22ce712d13b0b99b56a860f57c9142d9440e3.tar.xz
all: redirect request for .adoc or .md to the HTML file
During serve, onGet method, if the node does not exist and the request path end with .adoc or .md, redirect the client to the .html location with status 303 (StatusSeeOther).
-rw-r--r--server.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/server.go b/server.go
index ccb0dc5..483b7d1 100644
--- a/server.go
+++ b/server.go
@@ -179,7 +179,7 @@ func (ciigo *Ciigo) onSearch(epr *libhttp.EndpointRequest) (resBody []byte, err
// If yes, it will auto convert the adoc and return the new content of HTML
// files.
func (ciigo *Ciigo) onGet(
- node *memfs.Node, _ http.ResponseWriter, req *http.Request,
+ node *memfs.Node, w http.ResponseWriter, req *http.Request,
) (out *memfs.Node, statusCode int) {
var (
logp = `onGet`
@@ -187,7 +187,15 @@ func (ciigo *Ciigo) onGet(
)
if node == nil {
+ // File does not exist.
file = req.URL.Path
+ ext := path.Ext(file)
+ if ext == `.adoc` || ext == `.md` {
+ // Redirect to .html.
+ file = strings.TrimSuffix(file, ext) + `.html`
+ http.Redirect(w, req, file, http.StatusSeeOther)
+ return nil, http.StatusSeeOther
+ }
} else {
if node.IsDir() {
file = path.Join(node.Path, `index.html`)