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

URL of the final wikipage #260

Closed
lawrencenull opened this issue Mar 24, 2019 · 10 comments · Fixed by #355
Closed

URL of the final wikipage #260

lawrencenull opened this issue Mar 24, 2019 · 10 comments · Fixed by #355

Comments

@lawrencenull
Copy link

Was going through the API, is there a current way to generate a link to the wiki URL that the info is being pulled from.

@spencermountain
Copy link
Owner

hey lawrence, no there isn't a clean one. Maybe there should be.
right now i'd just do something like this:

let title=doc.title().replace(/ /g,'_')
title=encodeURIComponent(title)
let url=`${lang}.wikipedia.org/wiki/${title}}`

we need to store the language for the upcoming image url refactor, so maybe we should add this in after that.
cheers

@niebert
Copy link
Contributor

niebert commented Apr 19, 2019

When you pull from an other wiki domain - e.g. Wikiversity

/* FILE: /src/_fetch/_title2url
   function that converts a title from domain Wikipedia, Wikiversity, .... and 
   a specific language "lang" and a domain "wikipedia", "wikiversity" into 
   an URL that displays the source e.g.
   https://en.wikiversity.org/wiki/Swarm_intelligence 
   default language is: "en"
   default domain is: "wikipedia"
*/

const title2url = function( title, lang, domain ) {
  // set default values for parameters
   title = title || "Main Page";
   domain = domain || "wikipedia";
   lang = lang || "en";
   // replace blank to underscore 
   title=title.replace(/ /g,'_');
   title = encodeURIComponent(title);
   let url=`https://${lang}.${domain}.org/wiki/${title}}`
  return url;
};

module.exports =title2url;

Maybe Spencer could provide the function as file in /src/_fetch/_title2url.js for further use or integrate title2url into the API. See also Github-Wiki about the WikiID

cheers,

@spencermountain
Copy link
Owner

added .language() and .url() methods, will release as 8.1.0
cheers

@skipjack
Copy link
Contributor

Can you ping this thread once 497e075 makes it into master and/or when the new release is cut?

@spencermountain
Copy link
Owner

sure

@spencermountain
Copy link
Owner

released as 8.1.0
cheers

@skipjack
Copy link
Contributor

skipjack commented Apr 6, 2020

Works like a charm, thanks!

@skipjack
Copy link
Contributor

skipjack commented Apr 21, 2020

I spoke too soon, I'm seeing a small issue where the final url from doc.url() contains .org twice, for example:

https://en.wikipedia.org.org/wiki/Nuclear_Waste_Technical_Review_Board

I can look into this if you want, should be reproducible with the following script but note that I'm seeing it for every doc.url() call, not just this one:

const doc = await wtf.fetch('Nuclear Waste Technical Review Board')
console.log(doc.url())

spencermountain added a commit that referenced this issue Apr 22, 2020
@spencermountain
Copy link
Owner

ah, good eye.
fixed on dev, will add to next release.

@spencermountain
Copy link
Owner

fixed in 8.2.1

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

Successfully merging a pull request may close this issue.

4 participants