1
0
Fork 0
mirror of https://git.sr.ht/~yotam/shavit synced 2024-06-01 21:16:03 +02:00

Add custom index file name

This commit is contained in:
Yotam Nachum 2019-12-06 22:32:44 +02:00
parent 77b27a02f2
commit 177da57e0a
2 changed files with 16 additions and 5 deletions

View File

@ -59,9 +59,11 @@ func (h Handler) getFilePath(rawURL string) (string, error) {
return itemPath, nil
}
indexPath := filepath.Join(itemPath, "index.gmi")
if isFile(indexPath) {
return indexPath, nil
for _, indexFile := range h.cfg.IndexFiles {
indexPath := filepath.Join(itemPath, indexFile)
if isFile(indexPath) {
return indexPath, nil
}
}
return "", gemini.Error{Err: fmt.Errorf("file not found"), Status: gemini.StatusNotFound}

View File

@ -33,9 +33,14 @@ func getFlags() (Flags, error) {
// Config holds the main configuration data for the server
type Config struct {
// can be relative or absolute path
SourceDir string `toml:"source"`
TLSCert string `toml:"tls_certificate"`
TLSKey string `toml:"tls_key"`
// default to ["index.gmi"]
IndexFiles []string `toml:"index_files"`
TLSCert string `toml:"tls_certificate"`
TLSKey string `toml:"tls_key"`
}
func getConfig(path string) (Config, error) {
@ -55,5 +60,9 @@ func getConfig(path string) (Config, error) {
return cfg, fmt.Errorf("failed to get absolute source dir: %v", err)
}
if len(cfg.IndexFiles) == 0 {
cfg.IndexFiles = []string{"index.gmi"}
}
return cfg, nil
}