Add DefaultEncoding option to config/.molly files. Closes #19.
This commit is contained in:
parent
f05bab2b73
commit
a41898b012
3 changed files with 13 additions and 1 deletions
|
@ -229,6 +229,8 @@ examples of the appropriate syntax.
|
||||||
will be used instead of one inferred from the filename extension.
|
will be used instead of one inferred from the filename extension.
|
||||||
* `DefaultLang`: If this option is set, it will be served as the
|
* `DefaultLang`: If this option is set, it will be served as the
|
||||||
`lang` parameter of the MIME type for all `text/gemini` content.
|
`lang` parameter of the MIME type for all `text/gemini` content.
|
||||||
|
* `DefaultEncoding`: If this option is set, it will be served as the
|
||||||
|
`charset` parameter of the MIME type for all `text/gemini` content.
|
||||||
|
|
||||||
### Directory listings
|
### Directory listings
|
||||||
|
|
||||||
|
@ -369,6 +371,7 @@ other settings in `.molly` files will be ignored:
|
||||||
|
|
||||||
* `CertificateZones`
|
* `CertificateZones`
|
||||||
* `DefaultLang`
|
* `DefaultLang`
|
||||||
|
* `DefaultEncoding`
|
||||||
* `DirectorySort`
|
* `DirectorySort`
|
||||||
* `DirectoryReverse`
|
* `DirectoryReverse`
|
||||||
* `DirectoryTitles`
|
* `DirectoryTitles`
|
||||||
|
|
|
@ -18,6 +18,7 @@ type Config struct {
|
||||||
HomeDocBase string
|
HomeDocBase string
|
||||||
GeminiExt string
|
GeminiExt string
|
||||||
DefaultLang string
|
DefaultLang string
|
||||||
|
DefaultEncoding string
|
||||||
AccessLog string
|
AccessLog string
|
||||||
ErrorLog string
|
ErrorLog string
|
||||||
ReadMollyFiles bool
|
ReadMollyFiles bool
|
||||||
|
@ -39,6 +40,7 @@ type MollyFile struct {
|
||||||
MimeOverrides map[string]string
|
MimeOverrides map[string]string
|
||||||
CertificateZones map[string][]string
|
CertificateZones map[string][]string
|
||||||
DefaultLang string
|
DefaultLang string
|
||||||
|
DefaultEncoding string
|
||||||
DirectorySort string
|
DirectorySort string
|
||||||
DirectoryReverse bool
|
DirectoryReverse bool
|
||||||
DirectoryTitles bool
|
DirectoryTitles bool
|
||||||
|
@ -57,6 +59,7 @@ func getConfig(filename string) (Config, error) {
|
||||||
config.HomeDocBase = "users"
|
config.HomeDocBase = "users"
|
||||||
config.GeminiExt = "gmi"
|
config.GeminiExt = "gmi"
|
||||||
config.DefaultLang = ""
|
config.DefaultLang = ""
|
||||||
|
config.DefaultEncoding = ""
|
||||||
config.AccessLog = "access.log"
|
config.AccessLog = "access.log"
|
||||||
config.ErrorLog = "error.log"
|
config.ErrorLog = "error.log"
|
||||||
config.TempRedirects = make(map[string]string)
|
config.TempRedirects = make(map[string]string)
|
||||||
|
@ -139,6 +142,7 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
|
||||||
var mollyFile MollyFile
|
var mollyFile MollyFile
|
||||||
mollyFile.GeminiExt = config.GeminiExt
|
mollyFile.GeminiExt = config.GeminiExt
|
||||||
mollyFile.DefaultLang = config.DefaultLang
|
mollyFile.DefaultLang = config.DefaultLang
|
||||||
|
mollyFile.DefaultEncoding = config.DefaultEncoding
|
||||||
mollyFile.DirectorySort = config.DirectorySort
|
mollyFile.DirectorySort = config.DirectorySort
|
||||||
mollyFile.DirectoryReverse = config.DirectoryReverse
|
mollyFile.DirectoryReverse = config.DirectoryReverse
|
||||||
mollyFile.DirectoryTitles = config.DirectoryTitles
|
mollyFile.DirectoryTitles = config.DirectoryTitles
|
||||||
|
@ -176,6 +180,7 @@ func parseMollyFiles(path string, config *Config, errorLog *log.Logger) {
|
||||||
// Overwrite main Config using MollyFile
|
// Overwrite main Config using MollyFile
|
||||||
config.GeminiExt = mollyFile.GeminiExt
|
config.GeminiExt = mollyFile.GeminiExt
|
||||||
config.DefaultLang = mollyFile.DefaultLang
|
config.DefaultLang = mollyFile.DefaultLang
|
||||||
|
config.DefaultEncoding = mollyFile.DefaultEncoding
|
||||||
config.DirectorySort = mollyFile.DirectorySort
|
config.DirectorySort = mollyFile.DirectorySort
|
||||||
config.DirectoryReverse = mollyFile.DirectoryReverse
|
config.DirectoryReverse = mollyFile.DirectoryReverse
|
||||||
config.DirectoryTitles = mollyFile.DirectoryTitles
|
config.DirectoryTitles = mollyFile.DirectoryTitles
|
||||||
|
|
|
@ -254,8 +254,12 @@ func serveFile(path string, log *LogEntry, conn net.Conn, config Config, errorLo
|
||||||
if mimeType == "" {
|
if mimeType == "" {
|
||||||
mimeType = "application/octet-stream"
|
mimeType = "application/octet-stream"
|
||||||
}
|
}
|
||||||
|
// Add charset parameter
|
||||||
|
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultEncoding != "" {
|
||||||
|
mimeType += "; charset=" + config.DefaultEncoding
|
||||||
|
}
|
||||||
// Add lang parameter
|
// Add lang parameter
|
||||||
if mimeType == "text/gemini" && config.DefaultLang != "" {
|
if strings.HasPrefix(mimeType,"text/gemini") && config.DefaultLang != "" {
|
||||||
mimeType += "; lang=" + config.DefaultLang
|
mimeType += "; lang=" + config.DefaultLang
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue