44 lines
949 B
Go
44 lines
949 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
"path"
|
||
|
"path/filepath"
|
||
|
)
|
||
|
|
||
|
func (srv *Server) makeFileName(dir, name string) string {
|
||
|
name, _ = strings.CutSuffix(name, srv.options.WikiExt)
|
||
|
if name == "index" {
|
||
|
name = filepath.Base(dir)
|
||
|
}
|
||
|
if len(name) == 0 || len(name) == 1 {
|
||
|
return strings.ToUpper(name)
|
||
|
}
|
||
|
seps := strings.Split(name, "-")
|
||
|
for i, sep := range seps {
|
||
|
seps[i] = strings.ToUpper(sep[:1]) + sep[1:]
|
||
|
}
|
||
|
|
||
|
return strings.Join(seps, " ")
|
||
|
}
|
||
|
|
||
|
func (srv *Server) makeFileLink(dir, name string) string {
|
||
|
name, _ = strings.CutSuffix(name, srv.options.WikiExt)
|
||
|
if name == "index" {
|
||
|
name = ""
|
||
|
}
|
||
|
return path.Clean(dir + "/" + name)
|
||
|
}
|
||
|
|
||
|
func (srv *Server) wikiFilePath(pth string) string {
|
||
|
if pth == "/" || pth == "" {
|
||
|
return filepath.Clean(srv.options.WikiPath + "/index.pmd")
|
||
|
}
|
||
|
if pth[len(pth)-1] == '/' {
|
||
|
pth += "index"
|
||
|
}
|
||
|
return filepath.Clean(filepath.FromSlash(
|
||
|
srv.options.WikiPath + "/" + pth + srv.options.WikiExt,
|
||
|
))
|
||
|
}
|