Add DefaultLang config variable to set text/gemini lang parameter. Overridable via .molly file.
This commit is contained in:
parent
7fb5ca052b
commit
3e80488f92
2 changed files with 10 additions and 0 deletions
|
@ -12,6 +12,7 @@ type Config struct {
|
||||||
DocBase string
|
DocBase string
|
||||||
HomeDocBase string
|
HomeDocBase string
|
||||||
GeminiExt string
|
GeminiExt string
|
||||||
|
DefaultLang string
|
||||||
LogPath string
|
LogPath string
|
||||||
TempRedirects map[string]string
|
TempRedirects map[string]string
|
||||||
PermRedirects map[string]string
|
PermRedirects map[string]string
|
||||||
|
@ -21,6 +22,7 @@ type Config struct {
|
||||||
|
|
||||||
type MollyFile struct {
|
type MollyFile struct {
|
||||||
GeminiExt string
|
GeminiExt string
|
||||||
|
DefaultLang string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfig(filename string) (Config, error) {
|
func getConfig(filename string) (Config, error) {
|
||||||
|
@ -35,6 +37,7 @@ func getConfig(filename string) (Config, error) {
|
||||||
config.DocBase = "/var/gemini/"
|
config.DocBase = "/var/gemini/"
|
||||||
config.HomeDocBase = "users"
|
config.HomeDocBase = "users"
|
||||||
config.GeminiExt = "gmi"
|
config.GeminiExt = "gmi"
|
||||||
|
config.DefaultLang = ""
|
||||||
config.LogPath = "molly.log"
|
config.LogPath = "molly.log"
|
||||||
config.TempRedirects = make(map[string]string)
|
config.TempRedirects = make(map[string]string)
|
||||||
config.PermRedirects = make(map[string]string)
|
config.PermRedirects = make(map[string]string)
|
||||||
|
|
|
@ -256,6 +256,9 @@ func parseMollyFiles(path string, info os.FileInfo, config *Config) {
|
||||||
if mollyFile.GeminiExt != "" {
|
if mollyFile.GeminiExt != "" {
|
||||||
config.GeminiExt = mollyFile.GeminiExt
|
config.GeminiExt = mollyFile.GeminiExt
|
||||||
}
|
}
|
||||||
|
if mollyFile.DefaultLang != "" {
|
||||||
|
config.DefaultLang = mollyFile.DefaultLang
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -328,6 +331,10 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config) {
|
||||||
} else {
|
} else {
|
||||||
mimeType = mime.TypeByExtension(ext)
|
mimeType = mime.TypeByExtension(ext)
|
||||||
}
|
}
|
||||||
|
// Add lang parameter
|
||||||
|
if mimeType == "text/gemini" && config.DefaultLang != "" {
|
||||||
|
mimeType += "; lang=" + config.DefaultLang
|
||||||
|
}
|
||||||
// Set a generic MIME type if the extension wasn't recognised
|
// Set a generic MIME type if the extension wasn't recognised
|
||||||
if mimeType == "" {
|
if mimeType == "" {
|
||||||
mimeType = "application/octet-stream"
|
mimeType = "application/octet-stream"
|
||||||
|
|
Loading…
Reference in a new issue