mirror of
https://github.com/miniflux/v2.git
synced 2025-08-11 17:51:01 +00:00
refactor(misc): fix a handful of TODO
This commit is contained in:
parent
06cbf1b3b3
commit
485baf9654
9 changed files with 18 additions and 27 deletions
|
@ -18,11 +18,6 @@ type atom03Adapter struct {
|
||||||
atomFeed *atom03Feed
|
atomFeed *atom03Feed
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO No need for a constructor, as it's only used in this package
|
|
||||||
func NewAtom03Adapter(atomFeed *atom03Feed) *atom03Adapter {
|
|
||||||
return &atom03Adapter{atomFeed}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *atom03Adapter) buildFeed(baseURL string) *model.Feed {
|
func (a *atom03Adapter) buildFeed(baseURL string) *model.Feed {
|
||||||
feed := new(model.Feed)
|
feed := new(model.Feed)
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,15 @@ import (
|
||||||
"miniflux.app/v2/internal/urllib"
|
"miniflux.app/v2/internal/urllib"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Atom10Adapter struct {
|
type atom10Adapter struct {
|
||||||
atomFeed *atom10Feed
|
atomFeed *atom10Feed
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAtom10Adapter(atomFeed *atom10Feed) *Atom10Adapter {
|
func NewAtom10Adapter(atomFeed *atom10Feed) *atom10Adapter {
|
||||||
return &Atom10Adapter{atomFeed}
|
return &atom10Adapter{atomFeed}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
|
func (a *atom10Adapter) BuildFeed(baseURL string) *model.Feed {
|
||||||
feed := new(model.Feed)
|
feed := new(model.Feed)
|
||||||
|
|
||||||
// Populate the feed URL.
|
// Populate the feed URL.
|
||||||
|
@ -72,7 +72,7 @@ func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
|
||||||
return feed
|
return feed
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Atom10Adapter) populateEntries(siteURL string) model.Entries {
|
func (a *atom10Adapter) populateEntries(siteURL string) model.Entries {
|
||||||
entries := make(model.Entries, 0, len(a.atomFeed.Entries))
|
entries := make(model.Entries, 0, len(a.atomFeed.Entries))
|
||||||
|
|
||||||
for _, atomEntry := range a.atomFeed.Entries {
|
for _, atomEntry := range a.atomFeed.Entries {
|
||||||
|
|
|
@ -19,12 +19,14 @@ func Parse(baseURL string, r io.ReadSeeker, version string) (*model.Feed, error)
|
||||||
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
||||||
return nil, fmt.Errorf("atom: unable to parse Atom 0.3 feed: %w", err)
|
return nil, fmt.Errorf("atom: unable to parse Atom 0.3 feed: %w", err)
|
||||||
}
|
}
|
||||||
return NewAtom03Adapter(atomFeed).buildFeed(baseURL), nil
|
adapter := &atom03Adapter{atomFeed}
|
||||||
|
return adapter.buildFeed(baseURL), nil
|
||||||
default:
|
default:
|
||||||
atomFeed := new(atom10Feed)
|
atomFeed := new(atom10Feed)
|
||||||
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
|
||||||
return nil, fmt.Errorf("atom: unable to parse Atom 1.0 feed: %w", err)
|
return nil, fmt.Errorf("atom: unable to parse Atom 1.0 feed: %w", err)
|
||||||
}
|
}
|
||||||
return NewAtom10Adapter(atomFeed).BuildFeed(baseURL), nil
|
adapter := &atom10Adapter{atomFeed}
|
||||||
|
return adapter.BuildFeed(baseURL), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,6 @@ type opmlDocument struct {
|
||||||
Outlines opmlOutlineCollection `xml:"body>outline"`
|
Outlines opmlOutlineCollection `xml:"body>outline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove as this is only used in the opml package
|
|
||||||
func NewOPMLDocument() *opmlDocument {
|
|
||||||
return &opmlDocument{}
|
|
||||||
}
|
|
||||||
|
|
||||||
type opmlHeader struct {
|
type opmlHeader struct {
|
||||||
Title string `xml:"title,omitempty"`
|
Title string `xml:"title,omitempty"`
|
||||||
DateCreated string `xml:"dateCreated,omitempty"`
|
DateCreated string `xml:"dateCreated,omitempty"`
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// parse reads an OPML file and returns a SubcriptionList.
|
// parse reads an OPML file and returns a SubcriptionList.
|
||||||
func parse(data io.Reader) (subcriptionList, error) {
|
func parse(data io.Reader) (subcriptionList, error) {
|
||||||
opmlDocument := NewOPMLDocument()
|
opmlDocument := &opmlDocument{}
|
||||||
decoder := xml.NewDecoder(data)
|
decoder := xml.NewDecoder(data)
|
||||||
decoder.Entity = xml.HTMLEntity
|
decoder.Entity = xml.HTMLEntity
|
||||||
decoder.Strict = false
|
decoder.Strict = false
|
||||||
|
|
|
@ -32,7 +32,7 @@ func serialize(subscriptions subcriptionList) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertSubscriptionsToOPML(subscriptions subcriptionList) *opmlDocument {
|
func convertSubscriptionsToOPML(subscriptions subcriptionList) *opmlDocument {
|
||||||
opmlDocument := NewOPMLDocument()
|
opmlDocument := &opmlDocument{}
|
||||||
opmlDocument.Version = "2.0"
|
opmlDocument.Version = "2.0"
|
||||||
opmlDocument.Header.Title = "Miniflux"
|
opmlDocument.Header.Title = "Miniflux"
|
||||||
opmlDocument.Header.DateCreated = time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST")
|
opmlDocument.Header.DateCreated = time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST")
|
||||||
|
|
|
@ -197,13 +197,6 @@ type SanitizerOptions struct {
|
||||||
OpenLinksInNewTab bool
|
OpenLinksInNewTab bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: replace with SanitizeHTML, as it's only used in tests.
|
|
||||||
func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
|
|
||||||
return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
|
|
||||||
OpenLinksInNewTab: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) string {
|
func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) string {
|
||||||
var tagStack []string
|
var tagStack []string
|
||||||
var parentTag string
|
var parentTag string
|
||||||
|
|
|
@ -13,6 +13,12 @@ import (
|
||||||
"miniflux.app/v2/internal/config"
|
"miniflux.app/v2/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
|
||||||
|
return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
|
||||||
|
OpenLinksInNewTab: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkSanitize(b *testing.B) {
|
func BenchmarkSanitize(b *testing.B) {
|
||||||
var testCases = map[string][]string{
|
var testCases = map[string][]string{
|
||||||
"miniflux_github.html": {"https://github.com/miniflux/v2", ""},
|
"miniflux_github.html": {"https://github.com/miniflux/v2", ""},
|
||||||
|
|
|
@ -88,7 +88,7 @@ func filterValidXMLChar(r rune) rune {
|
||||||
|
|
||||||
// This function is copied from encoding/xml's procInst and adapted for []bytes instead of string
|
// This function is copied from encoding/xml's procInst and adapted for []bytes instead of string
|
||||||
func getEncoding(b []byte) string {
|
func getEncoding(b []byte) string {
|
||||||
// TODO: this parsing is somewhat lame and not exact.
|
// This parsing is somewhat lame and not exact.
|
||||||
// It works for all actual cases, though.
|
// It works for all actual cases, though.
|
||||||
idx := bytes.Index(b, []byte("encoding="))
|
idx := bytes.Index(b, []byte("encoding="))
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue