Compare commits
No commits in common. "58e868de808d40b9dcf17f6b885a76fb4b65fc8c" and "c19094ca90dabcda98974f1037e8449a0524530f" have entirely different histories.
58e868de80
...
c19094ca90
5 changed files with 4 additions and 55 deletions
52
formatter.go
52
formatter.go
|
@ -1,69 +1,21 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/n0x1m/md2gmi/mdproc"
|
|
||||||
"github.com/n0x1m/md2gmi/pipe"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func source(r io.Reader) pipe.Source {
|
|
||||||
return func() chan pipe.StreamItem {
|
|
||||||
data := make(chan pipe.StreamItem)
|
|
||||||
s := bufio.NewScanner(r)
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
i := 0
|
|
||||||
|
|
||||||
for s.Scan() {
|
|
||||||
data <- pipe.NewItem(i, s.Bytes())
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
close(data)
|
|
||||||
}()
|
|
||||||
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func sink(w *bytes.Buffer) pipe.Sink {
|
|
||||||
return func(dest chan pipe.StreamItem) {
|
|
||||||
for b := range dest {
|
|
||||||
_, err := fmt.Fprintf(w, string(b.Payload()))
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (fileContent *FileContent) FormatContent() string {
|
func (fileContent *FileContent) FormatContent() string {
|
||||||
content := fileContent.Content
|
content := fileContent.Content
|
||||||
badChars := make(map[string]string)
|
badChars := make(map[string]string)
|
||||||
badChars["ā"] = "ā"
|
badChars["'"] = "'"
|
||||||
badChars["ē"] = "ē"
|
|
||||||
badChars["ī"] = "ī"
|
|
||||||
badChars["ō"] = "ō"
|
|
||||||
badChars["ū"] = "ū"
|
|
||||||
for k, v := range badChars {
|
for k, v := range badChars {
|
||||||
content = strings.ReplaceAll(content, k, v)
|
content = strings.ReplaceAll(content, k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
var writer bytes.Buffer
|
return content
|
||||||
s := pipe.New()
|
|
||||||
s.Use(mdproc.Preprocessor())
|
|
||||||
s.Use(mdproc.FormatLinks)
|
|
||||||
s.Handle(source(strings.NewReader(content)), sink(&writer))
|
|
||||||
|
|
||||||
return writer.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (file *TreeFile) CategoriesAsUrl() string {
|
func (file *TreeFile) CategoriesAsUrl() string {
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -5,7 +5,6 @@ go 1.18
|
||||||
require (
|
require (
|
||||||
git.sr.ht/~adnano/go-gemini v0.2.3
|
git.sr.ht/~adnano/go-gemini v0.2.3
|
||||||
github.com/flosch/pongo2/v6 v6.0.0
|
github.com/flosch/pongo2/v6 v6.0.0
|
||||||
github.com/n0x1m/md2gmi v1.0.0
|
|
||||||
google.golang.org/grpc v1.48.0
|
google.golang.org/grpc v1.48.0
|
||||||
google.golang.org/protobuf v1.28.1
|
google.golang.org/protobuf v1.28.1
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -51,8 +51,6 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/n0x1m/md2gmi v1.0.0 h1:T4FTIjojSutOvyh7okIO7N59sk7KD9XyQMx35JX5jjA=
|
|
||||||
github.com/n0x1m/md2gmi v1.0.0/go.mod h1:q5iY7/I5QlC5bUrqmkXVA2FR2HOB9+PmqDhpCNHF/vc=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% import "macros.tpl" category_url, tag_url, text_url, logo %}
|
{% import "macros.tpl" category_url, tag_url, text_url, logo %}
|
||||||
# {{ logo() }} Arna alkierios :: {{ path }}
|
# {{ logo() }} Arna alkierios :: {{ path }}
|
||||||
|
|
||||||
{% if indexFile %}{{ indexFile.FormatContent()|safe }}
|
{% if indexFile %}{{ indexFile.FormatContent() }}
|
||||||
|
|
||||||
🌙 {{ indexFile.File.Created}}
|
🌙 {{ indexFile.File.Created}}
|
||||||
{{ indexFile.File.Copyright }}{% endif %}
|
{{ indexFile.File.Copyright }}{% endif %}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{% import "macros.tpl" category_url, tag_url, text_url, logo %}
|
{% import "macros.tpl" category_url, tag_url, text_url, logo %}
|
||||||
# {{ logo() }} Arna alkierios :: {{ file.File.Description }}
|
# {{ logo() }} Arna alkierios :: {{ file.File.Description }}
|
||||||
|
|
||||||
{{ file.FormatContent()|safe }}
|
{{ file.FormatContent() }}
|
||||||
|
|
||||||
🌙 {{ file.File.Created}}
|
🌙 {{ file.File.Created}}
|
||||||
{{ file.File.Copyright }}
|
{{ file.File.Copyright }}
|
||||||
|
|
Loading…
Add table
Reference in a new issue