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

Added phys.org translator #3238

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LaurenceOfAustralia
Copy link
Contributor

Added a translator for the site phys.org, for which we previously weren't getting all metadata from. Also added support for the sites search feature. This should fix issue #2897.

This is my first time working with this codebase so i'd be grateful if whoever approves this could take a look over my code to make sure I haven't done something stupid through inexperience!

physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
physorg.js Outdated Show resolved Hide resolved
@LaurenceOfAustralia
Copy link
Contributor Author

Thanks @AbeJellinek for helping to fix up all the mistakes I made!

I think i've fixed all the issues you raised (except for one i've asked for your advice on).

I'd also however be gratefully if you could take a look at the async code i've added. It was created mainly through cannibalising other translators because i've never used async in javascript before, so its very possible some errors have crept in.

@AbeJellinek
Copy link
Member

Strip the tags, but otherwise, looks good!

@LaurenceOfAustralia
Copy link
Contributor Author

Done. Thanks @AbeJellinek!

"translatorID": "e835ac2f-181b-41fe-a509-4f9d20797515",
"label": "Phys.org",
"creator": "Laurence Stevens",
"target": "https?://(www\\.)?phys\\.org/news",
Copy link
Member

Choose a reason for hiding this comment

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

Wait, the target matches /news...

if (url.includes('/news')) {
return 'blogPost';
}
else if (url.includes('/search') && getSearchResults(doc, true)) {
Copy link
Member

Choose a reason for hiding this comment

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

So won't this else if never happen? The URL will always include /news.

});

let em = await translator.getTranslatorObject();
em.itemType = type || "webpage";
Copy link
Member

Choose a reason for hiding this comment

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

We can just do

Suggested change
em.itemType = type || "webpage";
em.itemType = "blogPost";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants