Authored by 郭成尧

format-webp

@@ -34,9 +34,13 @@ const imgSrcHandle = (imgUrl, params) => { @@ -34,9 +34,13 @@ const imgSrcHandle = (imgUrl, params) => {
34 imgUrl = imgUrl.replace(/\/q\/\d+/g, '/q/' + params.q); 34 imgUrl = imgUrl.replace(/\/q\/\d+/g, '/q/' + params.q);
35 } 35 }
36 36
37 - if (window.supportWebp && !/format\//.test(imgUrl)) { 37 + if (window.supportWebp && !/format\//i.test(query)) {
38 imgUrl += '/format/webp'; 38 imgUrl += '/format/webp';
39 } 39 }
  40 +
  41 + if (window.supportWebp && (/format\/png/i.test(query) || /format\/jpg/i.test(query))) {
  42 + imgUrl = imgUrl.replace(/format\/png/i, 'format/webp').replace(/format\/jpg/i, 'format/webp');
  43 + }
40 } else if (/imageMogr2/.test(query)) { 44 } else if (/imageMogr2/.test(query)) {
41 if (!/\/quality\/\d+/.test(imgUrl)) { 45 if (!/\/quality\/\d+/.test(imgUrl)) {
42 imgUrl += `/quality/${params.q}`; 46 imgUrl += `/quality/${params.q}`;
@@ -47,6 +51,10 @@ const imgSrcHandle = (imgUrl, params) => { @@ -47,6 +51,10 @@ const imgSrcHandle = (imgUrl, params) => {
47 if (window.supportWebp && !/format\//.test(imgUrl)) { 51 if (window.supportWebp && !/format\//.test(imgUrl)) {
48 imgUrl += '/format/webp'; 52 imgUrl += '/format/webp';
49 } 53 }
  54 +
  55 + if (window.supportWebp && (/format\/png/i.test(query) || /format\/jpg/i.test(query))) {
  56 + imgUrl = imgUrl.replace(/format\/png/i, 'format/webp').replace(/format\/jpg/i, 'format/webp');
  57 + }
50 } 58 }
51 return imgUrl; 59 return imgUrl;
52 }; 60 };