@@ -51,21 +51,37 @@ function fixLazyLoadedImages(doc) {
51
51
52
52
<img src='original-size.png'/>
53
53
*/
54
- function imagesAtFullSize ( doc ) {
55
- let exclude_patterns = [
56
- /*
54
+
55
+ const IMAGE_EXCLUDE_PATTERNS = [
56
+ /*
57
57
Exclude Wikipedia links to image file pages
58
58
*/
59
- / w i k i p e d i a \. o r g \/ w i k i \/ [ a - z ] + : / i,
59
+ / w i k i p e d i a \. o r g \/ w i k i \/ [ a - z ] + : / i,
60
60
61
- /*
61
+ /*
62
62
Exclude images embedded in Markdown files
63
63
hosted on github.com.
64
64
See: https://github.com/danburzo/percollate/issues/84
65
65
*/
66
- / g i t h u b \. c o m /
67
- ] ;
66
+ / g i t h u b \. c o m /
67
+ ] ;
68
68
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 : / \/ b l o g g e r .g o o g l e u s e r c o n t e n t .c o m \/ i m g \/ / ,
80
+ replace : url => url . replace ( / \/ ( s \d + ) - h \/ / , '/$1/' )
81
+ }
82
+ ] ;
83
+
84
+ function imagesAtFullSize ( doc ) {
69
85
Array . from ( doc . querySelectorAll ( 'a > img:only-child' ) ) . forEach ( img => {
70
86
let anchor = img . parentNode ;
71
87
@@ -85,9 +101,15 @@ function imagesAtFullSize(doc) {
85
101
// Only replace if the `href` matches an image file
86
102
if (
87
103
isImageURL ( href , doc ) &&
88
- ! exclude_patterns . some ( pattern => pattern . test ( href ) )
104
+ ! IMAGE_EXCLUDE_PATTERNS . some ( pattern => pattern . test ( href ) )
89
105
) {
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 ) ;
91
113
anchor . parentNode . replaceChild ( img , anchor ) ;
92
114
}
93
115
} ) ;
0 commit comments