Skip to content

Commit

Permalink
Merge pull request #306 from EvanNotFound/dev
Browse files Browse the repository at this point in the history
Bump version to v2.5.3
  • Loading branch information
EvanNotFound authored Nov 17, 2023
2 parents 9fca526 + bcc135b commit ccba8d4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 173 deletions.
91 changes: 0 additions & 91 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hexo-theme-redefine",
"version": "2.5.2",
"version": "2.5.3",
"private": false,
"description": "Redefine your writing in Hexo Theme Redefine.",
"scripts": {
Expand Down Expand Up @@ -36,7 +36,6 @@
"tailwindcss": "^3.3.3"
},
"dependencies": {
"axios": "^1.6.1",
"postcss": "^8.4.28"
}
}
146 changes: 66 additions & 80 deletions scripts/events/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,30 @@
*/
const { version } = require("../../package.json");
const https = require("https");
const axios = require("axios");

hexo.on("ready", async () => {
const timeout = 5000; // 5 seconds
const packageName = "hexo-theme-redefine";
const timeout = 3000;

async function checkNpmPackage() {
try {
const response = await axios.get(
`https://registry.npmjs.org/${packageName}`,
{ timeout: timeout },
);
const jsonData = response.data;
async function fetchRedefineInfo() {
return new Promise((resolve, reject) => {
https
.get(
`https://redefine-version.ohevan.com/api/info`,
{ timeout: timeout },
(response) => {
let data = "";
response.on("data", (chunk) => {
data += chunk;
});
response.on("end", () => {
const jsonData = JSON.parse(data);

// hexo.log.info(
// `\n===================================================================\n ______ __ __ ______ __ __ ______ \r\n \/\\__ _\/\\ \\_\\ \\\/\\ ___\\\/\\ \"-.\/ \\\/\\ ___\\ \r\n \\\/_\/\\ \\\\ \\ __ \\ \\ __\\\\ \\ \\-.\/\\ \\ \\ __\\ \r\n \\ \\_\\\\ \\_\\ \\_\\ \\_____\\ \\_\\ \\ \\_\\ \\_____\\ \r\n \\\/_\/ \\\/_\/\\\/_\/\\\/_____\/\\\/_\/ \\\/_\/\\\/_____\/ \r\n \r\n ______ ______ _____ ______ ______ __ __ __ ______ \r\n\/\\ == \\\/\\ ___\\\/\\ __-.\/\\ ___\\\/\\ ___\/\\ \\\/\\ \"-.\\ \\\/\\ ___\\ \r\n\\ \\ __<\\ \\ __\\\\ \\ \\\/\\ \\ \\ __\\\\ \\ __\\ \\ \\ \\ \\-. \\ \\ __\\ \r\n \\ \\_\\ \\_\\ \\_____\\ \\____-\\ \\_____\\ \\_\\ \\ \\_\\ \\_\\\\\"\\_\\ \\_____\\ \r\n \\\/_\/ \/_\/\\\/_____\/\\\/____\/ \\\/_____\/\\\/_\/ \\\/_\/\\\/_\/ \\\/_\/\\\/_____\/\r\n \r\n Github: https:\/\/github.com\/EvanNotFound\/hexo-theme-redefine\n current version v${version}, the latest version is v${jsonData["dist-tags"].latest}\n===================================================================`,
// );
// hexo.log.info(
// `\n===================================================================\n ______ __ __ ______ __ __ ______ \r\n \/\\__ _\/\\ \\_\\ \\\/\\ ___\\\/\\ \"-.\/ \\\/\\ ___\\ \r\n \\\/_\/\\ \\\\ \\ __ \\ \\ __\\\\ \\ \\-.\/\\ \\ \\ __\\ \r\n \\ \\_\\\\ \\_\\ \\_\\ \\_____\\ \\_\\ \\ \\_\\ \\_____\\ \r\n \\\/_\/ \\\/_\/\\\/_\/\\\/_____\/\\\/_\/ \\\/_\/\\\/_____\/ \r\n \r\n ______ ______ _____ ______ ______ __ __ __ ______ \r\n\/\\ == \\\/\\ ___\\\/\\ __-.\/\\ ___\\\/\\ ___\/\\ \\\/\\ \"-.\\ \\\/\\ ___\\ \r\n\\ \\ __<\\ \\ __\\\\ \\ \\\/\\ \\ \\ __\\\\ \\ __\\ \\ \\ \\ \\-. \\ \\ __\\ \r\n \\ \\_\\ \\_\\ \\_____\\ \\____-\\ \\_____\\ \\_\\ \\ \\_\\ \\_\\\\\"\\_\\ \\_____\\ \r\n \\\/_\/ \/_\/\\\/_____\/\\\/____\/ \\\/_____\/\\\/_\/ \\\/_\/\\\/_\/ \\\/_\/\\\/_____\/\r\n \r\n Github: https:\/\/github.com\/EvanNotFound\/hexo-theme-redefine\n current version v${version}, the latest version is v${jsonData["dist-tags"].latest}\n===================================================================`,
// );

hexo.log.info(
`
hexo.log.info(
`
+======================================================================================+
| |
| _____ _ _ _____ __ __ _____ ____ _____ ____ _____ _____ ___ _ _ _____ |
Expand All @@ -32,21 +36,51 @@ hexo.on("ready", async () => {
| | | | _ | |___| | | | |___ | _ <| |___| |_| | |___| _| | || |\\ | |___ |
| |_| |_| |_|_____|_| |_|_____| |_| \\_\\_____|____/|_____|_| |___|_| \\_|_____| |
| |
| current v${version} latest v${jsonData["dist-tags"].latest} |
| current v${version} latest v${jsonData.npmVersion} |
| https://github.com/EvanNotFound/hexo-theme-redefine |
+======================================================================================+
`,
);
);

if (jsonData["dist-tags"].latest > version) {
hexo.log.warn(
`\x1b[33m%s\x1b[0m`,
`Redefine v${version} is outdated, please update to v${jsonData["dist-tags"].latest}!`,
);
}
} catch (error) {
hexo.log.info(
`
if (jsonData.npmVersion > version) {
hexo.log.warn(
`\x1b[33m%s\x1b[0m`,
`Redefine v${version} is outdated, please update to v${jsonData.npmVersion}!`,
);
}

if (jsonData.staticfileCDN) {
hexo.log.info(
`\x1b[32m%s\x1b[0m`,
`CDN available: StaticfileCDN`,
);
hexo.locals.set(`cdnTestStatus_staticfile`, 200);
} else {
hexo.log.warn(
`\x1b[31m%s\x1b[0m`,
`StaticfileCDN is unavailable yet.`,
);
hexo.locals.set(`cdnTestStatus_staticfile`, 404);
}

if (jsonData.bootCDN) {
hexo.log.info(`\x1b[32m%s\x1b[0m`, `CDN available: BootCDN`);
hexo.locals.set(`cdnTestStatus_bootcdn`, 200);
} else {
hexo.log.warn(
`\x1b[31m%s\x1b[0m`,
`BootCDN CDN is unavailable yet.`,
);
hexo.locals.set(`cdnTestStatus_bootcdn`, 404);
}

resolve();
});
},
)
.on("error", (error) => {
hexo.log.info(
`
+======================================================================================+
| |
| _____ _ _ _____ __ __ _____ ____ _____ ____ _____ _____ ___ _ _ _____ |
Expand All @@ -59,60 +93,12 @@ hexo.on("ready", async () => {
| https://github.com/EvanNotFound/hexo-theme-redefine |
+======================================================================================+
`,
);
hexo.log.error(`Check latest version failed: ${error}`);
}
);
hexo.log.error(`Check latest version failed: ${error}`);
reject(error);
});
});
}

await checkNpmPackage();

const cdnTestEndpoints = {
staticfile: {
name: "Staticfile CDN",
url: `https://cdn.staticfile.org/hexo-theme-redefine/${version}/js/main.js`,
site: "https://staticfile.org/",
},

bootcdn: {
name: "BootCDN",
url: `https://cdn.bootcdn.net/ajax/libs/hexo-theme-redefine/${version}/js/main.js`,
site: "https://www.bootcdn.cn/",
},
};

const fetchCDNStatus = async (key, data) => {
try {
const res = await axios.head(data.url);
if (res.status === 200) {
// console.log(`\x1b[32m%s\x1b[0m`, `CDN test success: ${key}`);
} else {
hexo.log.warn(`\x1b[31m%s\x1b[0m`, `${data.name} CDN test failed.`);
}
hexo.locals.set(`cdnTestStatus_${key}`, res.status);
} catch (error) {
hexo.locals.set(`cdnTestStatus_${key}`, 404);
hexo.log.warn(
`\x1b[31m%s\x1b[0m`,
`${key} CDN test failed. Falling back to local version.`,
);
hexo.log.warn(
`\x1b[34m%s\x1b[0m`,
`Redefine v${version} may not be available on ${data.name} yet. Check again later at ${data.site}.`,
);
hexo.log.warn(
`\x1b[34m%s\x1b[0m`,
`If you are not using ${data.name}, you can ignore this warning.`,
);
}
};

const testEndpoints = () => {
return Promise.allSettled(
Object.entries(cdnTestEndpoints).map(([key, url]) =>
fetchCDNStatus(key, url),
),
);
};

await testEndpoints();
await fetchRedefineInfo();
});

0 comments on commit ccba8d4

Please sign in to comment.