Skip to content

Commit

Permalink
BREAKING CHANGE: Use 2x-sized images
Browse files Browse the repository at this point in the history
* Previous version was 1.2.0
* Uses the 2x sized image by default
  • Loading branch information
theusaf committed Sep 1, 2022
1 parent 2bbd034 commit 6ab5183
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,20 @@ async function updateWiki() {
.catch(() => null),
baseImageSize = sizeOf(baseImage),
largeImageSize = largeImage ? sizeOf(largeImage) : null,
imageTitle = comicData.img.match(/(?<=\/comics\/).*?(?=\.[a-z]+$)/)[0];
imageTitle =
comicData.img.match(/(?<=\/comics\/).*?(?=\.[a-z]+$)/)[0] + largeImage
? "_2x"
: "";

createNewExplanation({
date,
image: baseImage,
image: largeImage ?? baseImage,
comicData,
imageTitle,
imageExtension,
baseImageSize,
largeImageSize,
is2x: (largeImage ?? baseImage) === largeImage,
});
} catch (err) {
console.error(
Expand All @@ -184,6 +188,7 @@ async function createNewExplanation(info) {
date,
baseImageSize,
largeImageSize,
is2x,
} = info,
{ safe_title: comicTitle, alt, num: comicNum } = comicData,
imagePath = path.join(TMP_PATH, `${imageTitle}.${imageExtension}`);
Expand All @@ -202,9 +207,13 @@ async function createNewExplanation(info) {
imagePath,
stripIndent`
== Summary ==
Large size can be found at ${
comicData.img.match(/.*?(?=\.[a-z]+$)/)[0]
}_2x.${imageExtension}
${
is2x
? `Small size can be found at ${
comicData.img.match(/.*?(?=\.[a-z]+$)/)[0]
}.${imageExtension}`
: ""
}
== Licensing ==
{{XKCD file}}
Expand All @@ -215,8 +224,6 @@ async function createNewExplanation(info) {
log("[INFO] - Creating redirects");

// If the comic title is a number underneath the current comic number, do not create this redirect
// TODO: Theoretically, this issue could allow Randall to edit non-comic pages using the title of
// his comics... A better solution should be created
if (!/^\d+$/.test(comicTitle) || +comicTitle > comicNum) {
await bot.edit(
comicTitle,
Expand All @@ -237,9 +244,8 @@ async function createNewExplanation(info) {
// create main page
log("[INFO] - Creating main page");
// Note 2022-02-03
// Since both the 'standard' and '2x' size seem to be the same size,
// For legacy explainxkcd sake, divide size by 2
let sizeString = "";
// If both the 'standard' and '2x' size seem to be the same size
let sizeString = `${baseImageSize.width}x${baseImageSize.height}px`;
if (
largeImageSize &&
baseImageSize.width === largeImageSize.width &&
Expand All @@ -260,7 +266,8 @@ async function createNewExplanation(info) {
sizeString === ""
? `| image = ${imageTitle}.${imageExtension}`
: `| image = ${imageTitle}.${imageExtension}
| imagesize = ${sizeString}`
| imagesize = ${sizeString}
| noexpand = true`
}
| titletext = ${alt.replace(/\n/g, "<br>")}
}}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "explainxkcdbot",
"version": "1.2.0",
"version": "2.0.0",
"description": "a bot for explainxkcd",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 6ab5183

Please sign in to comment.