Skip to content

Commit

Permalink
feat: enhance image loading and sanitization
Browse files Browse the repository at this point in the history
- Standardized image loading to lazy for consistency in modal previews
- Expanded allowed attributes for sanitization to support additional image properties
- Introduced an exclusive filter to exclude specific images by class during sanitization
  • Loading branch information
ccbikai committed Aug 10, 2024
1 parent 270fac7 commit c6fe474
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/telegram/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function getImages($, item, { staticProxy, id, index, title }) {
<img src="${staticProxy + url}" alt="${title}" loading="${index > 15 ? 'eager' : 'lazy'}" />
</button>
<button class="image-preview-button modal" id="${popoverId}" popovertarget="${popoverId}" popovertargetaction="hide" popover>
<img class="modal-img" src="${staticProxy + url}" alt="${title}" loading="${index > 15 ? 'eager' : 'lazy'}" />
<img class="modal-img" src="${staticProxy + url}" alt="${title}" loading="lazy" />
</button>
`
})?.get()
Expand Down
6 changes: 5 additions & 1 deletion src/pages/rss.xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ export async function GET(Astro) {
content: sanitizeHtml(item.content, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'video', 'audio']),
allowedAttributes: {
...sanitizeHtml.defaults.allowedAttributes,
video: ['src', 'width', 'height', 'poster'],
audio: ['src', 'controls'],
img: ['src', 'width', 'height', 'loading'],
img: ['src', 'srcset', 'alt', 'title', 'width', 'height', 'loading', 'class'],
},
exclusiveFilter(frame) {
return frame.tag === 'img' && frame.attribs?.class?.includes('modal-img')
},
}),
})),
Expand Down

0 comments on commit c6fe474

Please sign in to comment.