From 11e5e994cf9e2a98fcc900d09c68e0452095af10 Mon Sep 17 00:00:00 2001 From: Louis Person Date: Mon, 10 Apr 2017 19:24:47 +0200 Subject: [PATCH 1/4] Add docs.rs integration When a crate does not specify a documentation link, we query docs.rs to know if the documentation for the requested version was successfully built. If if is, we set the crate's documentation link to the corresponding docs.rs page, if not nothing changes. --- app/routes/crate/version.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index a38a4eba0f2..93dcb0c3ea1 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -68,6 +68,17 @@ export default Ember.Route.extend({ .finally(() => controller.set('fetchingFollowing', false)); } + if (!crate.get('documentation')) { + let crateName = crate.get('name'); + let crateVersion = params.version_num; + ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`) + .then((r) => { + if (r.length > 0 && r[0].build_status === true) { + crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/${crateName}/`); + } + }); + } + // Find version model return crate.get('versions') .then(versions => { From a13a6da18dd327be796b341a25ca29f48097f47f Mon Sep 17 00:00:00 2001 From: Louis Person Date: Sat, 15 Apr 2017 13:03:53 +0200 Subject: [PATCH 2/4] Don't force lib name to be the crate name in docs.rs link --- app/routes/crate/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 93dcb0c3ea1..2ffef657499 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -74,7 +74,7 @@ export default Ember.Route.extend({ ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`) .then((r) => { if (r.length > 0 && r[0].build_status === true) { - crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/${crateName}/`); + crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`); } }); } From bb622cea36073174d727ed577e152d62cda625a0 Mon Sep 17 00:00:00 2001 From: Louis Person Date: Sat, 15 Apr 2017 13:52:47 +0200 Subject: [PATCH 3/4] Fix version number being undefined when crate only has unstable versions --- app/routes/crate/version.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index 2ffef657499..e0067305891 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -35,6 +35,19 @@ export default Ember.Route.extend({ return result; }; + const fetchCrateDocumentation = () => { + if (!crate.get('documentation')) { + let crateName = crate.get('name'); + let crateVersion = params.version_num; + ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`) + .then((r) => { + if (r.length > 0 && r[0].build_status === true) { + crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`); + } + }); + } + }; + // Fallback to the crate's last stable version // If `max_version` is `0.0.0` then all versions have been yanked if (!requestedVersion && maxVersion !== '0.0.0') { @@ -52,10 +65,13 @@ export default Ember.Route.extend({ } else { params.version_num = latestStableVersion.get('num'); } - }); + }).then(fetchCrateDocumentation); } else { params.version_num = maxVersion; + fetchCrateDocumentation(); } + } else { + fetchCrateDocumentation(); } controller.set('crate', crate); @@ -68,17 +84,6 @@ export default Ember.Route.extend({ .finally(() => controller.set('fetchingFollowing', false)); } - if (!crate.get('documentation')) { - let crateName = crate.get('name'); - let crateVersion = params.version_num; - ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`) - .then((r) => { - if (r.length > 0 && r[0].build_status === true) { - crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`); - } - }); - } - // Find version model return crate.get('versions') .then(versions => { From c025fbba001ca064160db55d017a36d9392eb1f6 Mon Sep 17 00:00:00 2001 From: Louis Person Date: Mon, 1 May 2017 21:56:59 +0200 Subject: [PATCH 4/4] Fix auto-documentation link not being updated on version change As we edit the live model, the fetchCrateDocumentation was not being called as the documentation property of the model was not undefined annymore. Bonus feature: Any crate that has a docs.rs link as documentation automatically gets versioning on it --- app/routes/crate/version.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/routes/crate/version.js b/app/routes/crate/version.js index e0067305891..9a4600ee692 100644 --- a/app/routes/crate/version.js +++ b/app/routes/crate/version.js @@ -8,7 +8,6 @@ export default Ember.Route.extend({ model(params) { const requestedVersion = params.version_num === 'all' ? '' : params.version_num; - const crate = this.modelFor('crate'); const controller = this.controllerFor(this.routeName); const maxVersion = crate.get('max_version'); @@ -36,7 +35,8 @@ export default Ember.Route.extend({ }; const fetchCrateDocumentation = () => { - if (!crate.get('documentation')) { + if (!crate.get('documentation') || + crate.get('documentation').substr(0, 16) === 'https://docs.rs/') { let crateName = crate.get('name'); let crateVersion = params.version_num; ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`)