Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in run.js #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ async function run(url, options) {
image = imageUrl;
} else {
// Get cover image of the article
imageSelector = imageSelector || configstore.get('imageSelector');
if (imageSelector) {
// get image using selector specified
image = dom.window.document.querySelector(imageSelector);
Expand All @@ -276,31 +277,25 @@ async function run(url, options) {
}
} else {
// check if there's a default image selector in config
imageSelector = configstore.get('imageSelector');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would drop support for configstore.get?

if (imageSelector) {
image = dom.window.document.querySelector(imageSelector);
if (image) {
image = image.getAttribute('src');
}
} else {
if (url.includes("hashnode")) {
await getImageForHashnode(url).then((img) => {
const params = new URLSearchParams(img.split('?')[1]);
image = params.get('url');
});
}else{
image = search('image')
}
if (url.includes("hashnode")) {
await getImageForHashnode(url).then((img) => {
const params = new URLSearchParams(img.split('?')[1]);
image = params.get('url');
});
} else{
image = search('image', articleNode);
}
}
// check if image is dataurl
if (image && isDataURL(image)) {
const res = await uploadToCloudinary(image);
image = res.url;
} else if (image.indexOf('/') === 0 && !local) {
// get domain name of url and prepend it to the image URL
const urlObject = new URL(url);
image = `${urlObject.protocol}//${urlObject.hostname}${image}`;
if (image) {
// check if image is dataurl
if (isDataURL(image)) {
const res = await uploadToCloudinary(image);
image = res.url;
} else if (image.indexOf('/') === 0 && !local) {
// get domain name of url and prepend it to the image URL
const urlObject = new URL(url);
image = `${urlObject.protocol}//${urlObject.hostname}${image}`;
}
}
}
}
Expand Down