Fix #1150 (The media-filter should also include the new class e-content for embedde video and audio) (#1151)
continuous-integration/drone/push Build is passing Details

Several fixes included.

Co-authored-by: lilasta <lilaceous@proton.me>
Reviewed-on: #1151
Reviewed-by: James Mills <james@mills.io>
Co-authored-by: lilasta <lilasta@noreply@mills.io>
Co-committed-by: lilasta <lilasta@noreply@mills.io>
main
lilasta 6 days ago committed by James Mills
parent 406ac6260a
commit 5246ca45b0

1
.gitignore vendored

@ -61,6 +61,7 @@ environ.inc
/docs/.jekyll-cache/
/internal/theme/static/css/yarn.min.css
/internal/theme/static/css/noscript.min.css
/internal/theme/static/js/yarn.min.js
bench-yarn.txt

@ -165,6 +165,11 @@ func FilterMediaOnly(c *Cache, u *User) FilterFunc {
return true
}
for _, rule := range c.conf.embedRules {
if rule.pattern.MatchString(link.Target()) {
return true
}
}
}
}
return false

@ -724,6 +724,15 @@ func WithEmbedRules(embedRules string) Option {
return err
}
for i, rule := range rules {
pattern, err := regexp.Compile(rule.Pattern)
if err != nil {
return err
}
rules[i].pattern = pattern
}
cfg.embedRules = rules
return nil
}

@ -913,7 +913,7 @@ nav.filternav .ti {
.embed-audio {
width: 100%;
height: 100px;
height: 80px;
}
.center-cropped img {

@ -1 +0,0 @@
.embed-link-is-url{display:inline}.embed-video{display:none}.embed-audio{display:none}

@ -2308,10 +2308,11 @@ type URLProcessor struct {
}
type EmbedRule struct {
Pattern string `json:"pattern"`
Source string `json:"src"`
Class string `json:"class"`
Allow string `json:"allow"`
Pattern string `json:"pattern"`
pattern *regexp.Regexp `json:"-"`
Source string `json:"src"`
Class string `json:"class"`
Allow string `json:"allow"`
}
func (up *URLProcessor) RenderNodeHook(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
@ -2340,17 +2341,12 @@ func (up *URLProcessor) RenderNodeHook(w io.Writer, node ast.Node, entering bool
// Converts links to embed elements.
link, ok := node.(*ast.Link)
if ok && entering {
if ok && entering && display {
dst := string(link.Destination)
title := string(link.Title)
for _, rewrite := range up.conf.embedRules {
pattern, err := regexp.Compile(rewrite.Pattern)
if err != nil {
continue
}
if !pattern.MatchString(dst) {
for _, rule := range up.conf.embedRules {
if !rule.pattern.MatchString(dst) {
continue
}
@ -2390,7 +2386,7 @@ func (up *URLProcessor) RenderNodeHook(w io.Writer, node ast.Node, entering bool
title="%s">
</iframe>
<p>
`, pattern.ReplaceAllString(dst, rewrite.Source), rewrite.Class, rewrite.Allow, title)
`, rule.pattern.ReplaceAllString(dst, rule.Source), rule.Class, rule.Allow, title)
_, _ = io.WriteString(w, html)
return ast.SkipChildren, true

Loading…
Cancel
Save