Skip to content

Commit

Permalink
Unify regexes matching image URLs, fixes case sensitivity causing som…
Browse files Browse the repository at this point in the history
…e images to not be fetched for EPUB archive (Re: #141)
  • Loading branch information
danburzo committed Mar 7, 2023
1 parent 6315c15 commit 2667b44
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/constants/regex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*
Regex to match URLs pointing to image files in the most common formats.
*/
export const REGEX_IMAGE_URL = /\.(jpe?g|png|svg|gif|bmp|webp|avif|tiff?)$/i;
3 changes: 2 additions & 1 deletion src/enhancements.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { parseSrcset, stringifySrcset } from 'srcset';
import replaceElementType from './replace-element-type.js';
import { REGEX_IMAGE_URL } from './constants/regex.js';

/*
Convert AMP markup to HMTL markup
Expand Down Expand Up @@ -51,7 +52,7 @@ function fixLazyLoadedImages(doc) {
<img src='original-size.png'/>
*/
function imagesAtFullSize(doc) {
let include_pattern = /\.(png|jpg|jpeg|gif|svg|webp|avif|bmp|tiff?)$/i;
let include_pattern = REGEX_IMAGE_URL;
let exclude_patterns = [
/*
Exclude Wikipedia links to image file pages
Expand Down
3 changes: 2 additions & 1 deletion src/remote-resources.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { randomUUID as uuid } from 'node:crypto';
import { parseSrcset, stringifySrcset } from 'srcset';
import { REGEX_IMAGE_URL } from './constants/regex.js';

export default function remoteResources(doc) {
let srcs = new Map();
Expand All @@ -15,7 +16,7 @@ export default function remoteResources(doc) {
} catch (err) {
// no-op, probably due to bad `doc.baseURI`.
}
let match = pathname.match(/\.(gif|jpe?g|bmp|png|svg|webp)$/);
let match = pathname.match(REGEX_IMAGE_URL);
if (!match) {
return src;
}
Expand Down

0 comments on commit 2667b44

Please sign in to comment.