Skip to content

Commit 9ab0784

Browse files
committed
imagesAtFullSize: account for blogspot.com URLs that look like images but are actually HTML files with an <img> tag
1 parent eb3efdc commit 9ab0784

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/enhancements.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,37 @@ function fixLazyLoadedImages(doc) {
5151
5252
<img src='original-size.png'/>
5353
*/
54-
function imagesAtFullSize(doc) {
55-
let exclude_patterns = [
56-
/*
54+
55+
const IMAGE_EXCLUDE_PATTERNS = [
56+
/*
5757
Exclude Wikipedia links to image file pages
5858
*/
59-
/wikipedia\.org\/wiki\/[a-z]+:/i,
59+
/wikipedia\.org\/wiki\/[a-z]+:/i,
6060

61-
/*
61+
/*
6262
Exclude images embedded in Markdown files
6363
hosted on github.com.
6464
See: https://github.com/danburzo/percollate/issues/84
6565
*/
66-
/github\.com/
67-
];
66+
/github\.com/
67+
];
6868

69+
/*
70+
Some image URLs can be used but must be adjusted
71+
*/
72+
const IMAGE_URL_MAPPERS = [
73+
/*
74+
Some Blogger images use a /s1600-h/ segment
75+
that loads an HTML file with an <img> element,
76+
while /s1600/ loads the image itself.
77+
*/
78+
{
79+
matcher: /\/blogger.googleusercontent.com\/img\//,
80+
replace: url => url.replace(/\/(s\d+)-h\//, '/$1/')
81+
}
82+
];
83+
84+
function imagesAtFullSize(doc) {
6985
Array.from(doc.querySelectorAll('a > img:only-child')).forEach(img => {
7086
let anchor = img.parentNode;
7187

@@ -85,9 +101,15 @@ function imagesAtFullSize(doc) {
85101
// Only replace if the `href` matches an image file
86102
if (
87103
isImageURL(href, doc) &&
88-
!exclude_patterns.some(pattern => pattern.test(href))
104+
!IMAGE_EXCLUDE_PATTERNS.some(pattern => pattern.test(href))
89105
) {
90-
img.setAttribute('src', anchor.href);
106+
href = anchor.href;
107+
IMAGE_URL_MAPPERS.forEach(it => {
108+
if (it.matcher.test(href)) {
109+
href = it.replace(href);
110+
}
111+
});
112+
img.setAttribute('src', href);
91113
anchor.parentNode.replaceChild(img, anchor);
92114
}
93115
});

0 commit comments

Comments
 (0)