Files
mindoc/converter/util.go
Minho e1ec6bb788 1、实现富文本编辑器
2、实现文档转换为PDF、MOBI、EPUB格式
2018-01-25 19:18:59 +08:00

48 lines
1016 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//Author:TruthHun
//Email:TruthHun@QQ.COM
//Date:2018-01-21
package converter
import (
"encoding/json"
"io/ioutil"
"strings"
)
//media-type
var MediaType = map[string]string{
".jpeg": "image/jpeg",
".png": "image/png",
".jpg": "image/jpeg",
".gif": "image/gif",
".ico": "image/x-icon",
".bmp": "image/bmp",
".html": "application/xhtml+xml",
".xhtml": "application/xhtml+xml",
".htm": "application/xhtml+xml",
".otf": "application/x-font-opentype",
".ttf": "application/x-font-ttf",
".js": "application/x-javascript",
".ncx": "x-dtbncx+xml",
".txt": "text/plain",
".xml": "text/xml",
".css": "text/css",
}
//根据文件扩展名获取media-type
func GetMediaType(ext string) string {
if mt, ok := MediaType[strings.ToLower(ext)]; ok {
return mt
}
return ""
}
//解析配置文件
func parseConfig(configFile string) (cfg Config, err error) {
var b []byte
if b, err = ioutil.ReadFile(configFile); err == nil {
err = json.Unmarshal(b, &cfg)
}
return
}