MOBILE-3615 url: Fix docs url release number

main
Pau Ferrer Ocaña 2021-05-18 15:45:14 +02:00
parent 972e1e2a81
commit 07d05d0a26
2 changed files with 18 additions and 1 deletions

View File

@ -668,6 +668,21 @@ export class CoreSitesProvider {
return ''; return '';
} }
/**
* Returns the major release number from site release info.
*
* @param rawRelease Raw release info text.
* @return Major release number or empty.
*/
getMajorReleaseNumber(rawRelease: string): string {
const matches = rawRelease.match(/^\d+(\.\d+)?/);
if (matches) {
return matches[0];
}
return '';
}
/** /**
* Saves a site in local DB. * Saves a site in local DB.
* *

View File

@ -20,6 +20,7 @@ import { CoreConstants } from '@/core/constants';
import { makeSingleton } from '@singletons'; import { makeSingleton } from '@singletons';
import { CoreUrl } from '@singletons/url'; import { CoreUrl } from '@singletons/url';
import { CoreApp } from '@services/app'; import { CoreApp } from '@services/app';
import { CoreSites } from '@services/sites';
/* /*
* "Utils" service with helper functions for URLs. * "Utils" service with helper functions for URLs.
@ -233,7 +234,8 @@ export class CoreUrlUtilsProvider {
let docsUrl = 'https://docs.moodle.org/en/' + page; let docsUrl = 'https://docs.moodle.org/en/' + page;
if (typeof release != 'undefined') { if (typeof release != 'undefined') {
const version = release.substr(0, 3).replace('.', ''); const version = CoreSites.getMajorReleaseNumber(release).replace('.', '');
// Check is a valid number. // Check is a valid number.
if (Number(version) >= 24) { if (Number(version) >= 24) {
// Append release number. // Append release number.