diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 221498a..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,21 +0,0 @@ -image: golang:latest - -stages: - - validate - - build - -fmt: - stage: validate - script: - - gofmt -l -s -e . - - exit $(gofmt -l -s -e . | wc -l) - -vet: - stage: validate - script: - - go vet -composites=false ./... - -test: - stage: validate - script: - - go test -race -v ./... diff --git a/CHANGELOG b/CHANGELOG index 9c174e5..3e4e65e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ -1.0.3: -- Migrate to code.rocketnine.space +1.0.4: +- Add option ConvertImages (thanks to @f) 1.0.3: - Add hostname option diff --git a/README.md b/README.md index f48f34e..10f0bc3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # gmitohtml -[![GoDoc](https://code.rocketnine.space/tslocum/godoc-static/-/raw/master/badge.svg)](https://docs.rocketnine.space/code.rocketnine.space/tslocum/gmitohtml/pkg/gmitohtml) +[![GoDoc](https://code.rocketnine.space/tslocum/godoc-static/raw/branch/master/badge.svg)](https://docs.rocketnine.space/code.rocketnine.space/tslocum/gmitohtml/pkg/gmitohtml) [![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space) [Gemini](https://gemini.circumlunar.space) to [HTML](https://en.wikipedia.org/wiki/HTML) diff --git a/go.mod b/go.mod index 52d97e1..48ba759 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module code.rocketnine.space/tslocum/gmitohtml go 1.15 -require gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8 +require code.rocketnine.space/tslocum/ez v0.0.0-20210506054357-569018bd037a diff --git a/go.sum b/go.sum index 94c3e6c..5dc9ead 100644 --- a/go.sum +++ b/go.sum @@ -1,4 +1,6 @@ +code.rocketnine.space/tslocum/ez v0.0.0-20210506054357-569018bd037a h1:Ug5hgK5sM7bdK1gEl/pNLYTtBpFUxCvSCGYkEbUqdmw= +code.rocketnine.space/tslocum/ez v0.0.0-20210506054357-569018bd037a/go.mod h1:SQrM+bQ4eZdyAVTxuF2BNnyAnojHP6Kcmm2vMszoFWw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8 h1:tH9C0MON9YI3/KuD+u5+tQrQQ8px0MrcJ/avzeALw7o= -gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= diff --git a/main.go b/main.go index 191a634..b6af08a 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "os/exec" "runtime" + "code.rocketnine.space/tslocum/ez" "code.rocketnine.space/tslocum/gmitohtml/pkg/gmitohtml" ) @@ -46,8 +47,10 @@ func main() { // TODO option to include response header in page flag.Parse() - defaultConfig := gmitohtml.DefaultConfigPath() - if configFile == "" { + defaultConfig, err := ez.DefaultConfigPath("gmitohtml") + if err != nil { + log.Fatal(err) + } else if configFile == "" { configFile = defaultConfig } @@ -58,7 +61,7 @@ func main() { } if configExists || configFile != defaultConfig { - err := gmitohtml.ReadConfig(configFile) + err := ez.Deserialize(gmitohtml.Config, configFile) if err != nil { log.Fatalf("failed to read configuration file at %s: %v\nSee CONFIGURATION.md for information on configuring gmitohtml", configFile, err) } @@ -90,7 +93,7 @@ func main() { gmitohtml.SetOnBookmarksChanged(func() { gmitohtml.Config.Bookmarks = gmitohtml.GetBookmarks() - err := gmitohtml.SaveConfig(configFile) + err := ez.Serialize(gmitohtml.Config, configFile) if err != nil { log.Fatal(err) } diff --git a/pkg/gmitohtml/config.go b/pkg/gmitohtml/config.go index b4dace8..ba91482 100644 --- a/pkg/gmitohtml/config.go +++ b/pkg/gmitohtml/config.go @@ -2,80 +2,26 @@ package gmitohtml import ( "crypto/tls" - "errors" - "fmt" - "io/ioutil" - "os" - "path" - - "gopkg.in/yaml.v3" ) -type certConfig struct { +type CertConfig struct { Cert string Key string cert tls.Certificate } -type appConfig struct { +type AppConfig struct { Bookmarks map[string]string // Convert image links to images instead of normal links ConvertImages bool - Certs map[string]*certConfig + Certs map[string]*CertConfig } -var Config = &appConfig{ +var Config = &AppConfig{ Bookmarks: make(map[string]string), - ConvertImages: false, - - Certs: make(map[string]*certConfig), -} - -func DefaultConfigPath() string { - homedir, err := os.UserHomeDir() - if err == nil && homedir != "" { - return path.Join(homedir, ".config", "gmitohtml", "config.yaml") - } - return "" -} - -func ReadConfig(configPath string) error { - if configPath == "" { - return errors.New("file unspecified") - } - - configData, err := ioutil.ReadFile(configPath) - if err != nil { - return err - } - - var newConfig *appConfig - err = yaml.Unmarshal(configData, &newConfig) - if err != nil { - return err - } - Config = newConfig - - return nil -} - -func SaveConfig(configPath string) error { - Config.Bookmarks = GetBookmarks() - - out, err := yaml.Marshal(Config) - if err != nil { - return fmt.Errorf("failed to marshal configuration: %s", err) - } - - os.MkdirAll(path.Dir(configPath), 0755) // Ignore error - - err = ioutil.WriteFile(configPath, out, 0644) - if err != nil { - return fmt.Errorf("failed to save configuration to %s: %s", configPath, err) - } - return nil + Certs: make(map[string]*CertConfig), } diff --git a/pkg/gmitohtml/convert.go b/pkg/gmitohtml/convert.go index fcaf208..6f4c53a 100644 --- a/pkg/gmitohtml/convert.go +++ b/pkg/gmitohtml/convert.go @@ -142,9 +142,9 @@ func Convert(page []byte, u string) []byte { // If link ends with gif/png/jpg, add a image instead of a link if isImage && Config.ConvertImages { - result = append(result, []byte("\""")...) + result = append(result, []byte("\""+title+"\"")...) } else { - result = append(result, []byte("" + title + "
")...) + result = append(result, []byte(""+title+"
")...) } continue