Files
libredesk/internal/stringutil/htmlimages_test.go
T
Abhinav Raut 7b69690394 add SEO, localization, and drag reordering to the help center
Public pages were missing most of what a search engine needs. They now serve
a sitemap index at /sitemap.xml plus a robots.txt, and every page carries a
canonical URL, hreflang alternates, an x-default, and JSON-LD. Article pages
also send published and modified times. Search pages and the markdown view
are marked noindex. Requests from bots no longer bump the view counters, so
the insights numbers reflect real readers. Offscreen images in articles are
lazy loaded.

Public page text is now translated per locale instead of always using the
desk language, and pages with more than one translation show a language
switcher.

In the admin, collections and articles can be dragged to reorder, and an
article can be dragged into a different collection. Both save through new
sort order endpoints. Collections can have a lucide icon, picked from a new
icon picker backed by a sprite sheet. The landing page has layout options
for card grid or one per row, cards per row, and which details to show.

The help center list is a data table now, so HelpCenterCard is gone. The
tree page moved into AdminSplitLayout, its actions sit on their own row
below the breadcrumb, and it gained visit site and expand/collapse all.
2026-08-01 10:32:52 +05:30

45 lines
1.2 KiB
Go

package stringutil
import "testing"
func TestDeferOffscreenImages(t *testing.T) {
tests := []struct {
name string
in string
want string
}{
{
name: "first image stays eager",
in: `<p>a</p><img src="1.png"><p>b</p><img src="2.png">`,
want: `<p>a</p><img src="1.png"><p>b</p><img src="2.png" loading="lazy" decoding="async">`,
},
{
name: "self closing tag keeps its slash",
in: `<img src="1.png" /><img src="2.png" />`,
want: `<img src="1.png" /><img src="2.png" loading="lazy" decoding="async" />`,
},
{
name: "existing attributes are not duplicated",
in: `<img src="1.png"><img src="2.png" loading="eager"><img src="3.png" DECODING="sync">`,
want: `<img src="1.png"><img src="2.png" loading="eager" decoding="async"><img src="3.png" DECODING="sync" loading="lazy">`,
},
{
name: "single image is untouched",
in: `<img src="1.png">`,
want: `<img src="1.png">`,
},
{
name: "no images",
in: `<p>nothing here</p>`,
want: `<p>nothing here</p>`,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DeferOffscreenImages(tt.in); got != tt.want {
t.Errorf("got %q, want %q", got, tt.want)
}
})
}
}