mirror of
https://code.rocketnine.space/tslocum/gmitohtml.git
synced 2024-11-27 13:58:15 +01:00
Document ConvertImages option
This commit is contained in:
parent
8e8eef57e2
commit
6c7b8ec1d3
8 changed files with 22 additions and 92 deletions
|
@ -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 ./...
|
|
|
@ -1,5 +1,5 @@
|
||||||
1.0.3:
|
1.0.4:
|
||||||
- Migrate to code.rocketnine.space
|
- Add option ConvertImages (thanks to @f)
|
||||||
|
|
||||||
1.0.3:
|
1.0.3:
|
||||||
- Add hostname option
|
- Add hostname option
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# gmitohtml
|
# 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)
|
[![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)
|
[Gemini](https://gemini.circumlunar.space) to [HTML](https://en.wikipedia.org/wiki/HTML)
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -2,4 +2,4 @@ module code.rocketnine.space/tslocum/gmitohtml
|
||||||
|
|
||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8
|
require code.rocketnine.space/tslocum/ez v0.0.0-20210506054357-569018bd037a
|
||||||
|
|
6
go.sum
6
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
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.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210105161348-2e78108cf5f8/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
|
11
main.go
11
main.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"code.rocketnine.space/tslocum/ez"
|
||||||
"code.rocketnine.space/tslocum/gmitohtml/pkg/gmitohtml"
|
"code.rocketnine.space/tslocum/gmitohtml/pkg/gmitohtml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,8 +47,10 @@ func main() {
|
||||||
// TODO option to include response header in page
|
// TODO option to include response header in page
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
defaultConfig := gmitohtml.DefaultConfigPath()
|
defaultConfig, err := ez.DefaultConfigPath("gmitohtml")
|
||||||
if configFile == "" {
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else if configFile == "" {
|
||||||
configFile = defaultConfig
|
configFile = defaultConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +61,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if configExists || configFile != defaultConfig {
|
if configExists || configFile != defaultConfig {
|
||||||
err := gmitohtml.ReadConfig(configFile)
|
err := ez.Deserialize(gmitohtml.Config, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to read configuration file at %s: %v\nSee CONFIGURATION.md for information on configuring gmitohtml", configFile, err)
|
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.SetOnBookmarksChanged(func() {
|
||||||
gmitohtml.Config.Bookmarks = gmitohtml.GetBookmarks()
|
gmitohtml.Config.Bookmarks = gmitohtml.GetBookmarks()
|
||||||
|
|
||||||
err := gmitohtml.SaveConfig(configFile)
|
err := ez.Serialize(gmitohtml.Config, configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,80 +2,26 @@ package gmitohtml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type certConfig struct {
|
type CertConfig struct {
|
||||||
Cert string
|
Cert string
|
||||||
Key string
|
Key string
|
||||||
|
|
||||||
cert tls.Certificate
|
cert tls.Certificate
|
||||||
}
|
}
|
||||||
|
|
||||||
type appConfig struct {
|
type AppConfig struct {
|
||||||
Bookmarks map[string]string
|
Bookmarks map[string]string
|
||||||
|
|
||||||
// Convert image links to images instead of normal links
|
// Convert image links to images instead of normal links
|
||||||
ConvertImages bool
|
ConvertImages bool
|
||||||
|
|
||||||
Certs map[string]*certConfig
|
Certs map[string]*CertConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config = &appConfig{
|
var Config = &AppConfig{
|
||||||
Bookmarks: make(map[string]string),
|
Bookmarks: make(map[string]string),
|
||||||
|
|
||||||
ConvertImages: false,
|
Certs: make(map[string]*CertConfig),
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 link ends with gif/png/jpg, add a image instead of a link
|
||||||
if isImage && Config.ConvertImages {
|
if isImage && Config.ConvertImages {
|
||||||
result = append(result, []byte("<img src=\"" + uri + "\" alt=\"" + title + "\">")...)
|
result = append(result, []byte("<img src=\""+uri+"\" alt=\""+title+"\">")...)
|
||||||
} else {
|
} else {
|
||||||
result = append(result, []byte("<a href=\"" + uri + "\">" + title + "</a><br>")...)
|
result = append(result, []byte("<a href=\""+uri+"\">"+title+"</a><br>")...)
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue