From 89f3a5177b830d03e1d7777174ae264c8e9944ac Mon Sep 17 00:00:00 2001 From: PanAeon Date: Mon, 22 Oct 2018 16:47:20 +0100 Subject: [PATCH 1/2] Generate alternate url for different locales so search engine could find them all. --- src/js/app/index.js | 20 +++++++++++++++++++- src/js/stores/LocaleStore.js | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/js/app/index.js b/src/js/app/index.js index 69e1fdce..072b7945 100644 --- a/src/js/app/index.js +++ b/src/js/app/index.js @@ -1,6 +1,7 @@ var Backbone = require('backbone'); var EventEmitter = require('events').EventEmitter; var React = require('react'); +var _ = require('underscore'); var assign = require('object-assign'); var util = require('../util'); @@ -86,6 +87,22 @@ var vcsModeRefresh = function(eventData) { $('body').toggleClass('hgMode', !isGit); }; +var insertAlternateLinks = function(pageId) { + // For now pageId is null, which would link to the main page. + // In future if pageId is provided this method should link to a specific page + + // The value of the hreflang attribute identifies the language (in ISO 639-1 format) + // and optionally a region (in ISO 3166-1 Alpha 2 format) of an alternate URL + var altLinks = _.map(LocaleStore.getSupportedLocales(), function(langCode) { + var url = "https://learngitbranching.js.org/?locale=" + langCode; + return ''; + }); + var defaultUrl = "https://learngitbranching.js.org/?locale=" + LocaleStore.getDefaultLocale(); + altLinks.push(''); + $('head').prepend(altLinks); + +}; + var intlRefresh = function() { if (!window.$) { return; } $('span.intl-aware').each(function(i, el) { @@ -249,6 +266,8 @@ var initDemo = function(sandbox) { tryLocaleDetect(); } + insertAlternateLinks(); + if (params.command) { var command = unescape(params.command); sandbox.mainVis.customEvents.on('gitEngineReady', function() { @@ -328,4 +347,3 @@ exports.getLevelDropdown = function() { }; exports.init = init; - diff --git a/src/js/stores/LocaleStore.js b/src/js/stores/LocaleStore.js index 3b1a27b4..227bdd67 100644 --- a/src/js/stores/LocaleStore.js +++ b/src/js/stores/LocaleStore.js @@ -3,6 +3,7 @@ var AppConstants = require('../constants/AppConstants'); var AppDispatcher = require('../dispatcher/AppDispatcher'); var EventEmitter = require('events').EventEmitter; +var _ = require('underscore'); var assign = require('object-assign'); @@ -30,6 +31,8 @@ var headerLocaleMap = { 'pt-BR': 'pt_BR' }; +var supportedLocalesList = _.values(langLocaleMap).concat(_.values(headerLocaleMap)); + function _getLocaleFromHeader(langString) { var languages = langString.split(','); var desiredLocale; @@ -73,6 +76,10 @@ AppConstants.StoreSubscribePrototype, return _locale; }, + getSupportedLocales: function() { + return assign({}, supportedLocalesList); + }, + dispatchToken: AppDispatcher.register(function(payload) { var action = payload.action; var shouldInform = false; From 9d14feb1b39751ebddcd39efed3444bc25413381 Mon Sep 17 00:00:00 2001 From: PanAeon Date: Wed, 24 Oct 2018 11:12:48 +0100 Subject: [PATCH 2/2] Requested changes - removed underscore and sorted out duplicates in locales --- src/js/app/index.js | 4 ++-- src/js/stores/LocaleStore.js | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/js/app/index.js b/src/js/app/index.js index 072b7945..82e66870 100644 --- a/src/js/app/index.js +++ b/src/js/app/index.js @@ -1,7 +1,6 @@ var Backbone = require('backbone'); var EventEmitter = require('events').EventEmitter; var React = require('react'); -var _ = require('underscore'); var assign = require('object-assign'); var util = require('../util'); @@ -93,7 +92,8 @@ var insertAlternateLinks = function(pageId) { // The value of the hreflang attribute identifies the language (in ISO 639-1 format) // and optionally a region (in ISO 3166-1 Alpha 2 format) of an alternate URL - var altLinks = _.map(LocaleStore.getSupportedLocales(), function(langCode) { + + var altLinks = LocaleStore.getSupportedLocales().map(function(langCode) { var url = "https://learngitbranching.js.org/?locale=" + langCode; return ''; }); diff --git a/src/js/stores/LocaleStore.js b/src/js/stores/LocaleStore.js index 227bdd67..544a5af7 100644 --- a/src/js/stores/LocaleStore.js +++ b/src/js/stores/LocaleStore.js @@ -3,7 +3,6 @@ var AppConstants = require('../constants/AppConstants'); var AppDispatcher = require('../dispatcher/AppDispatcher'); var EventEmitter = require('events').EventEmitter; -var _ = require('underscore'); var assign = require('object-assign'); @@ -31,7 +30,9 @@ var headerLocaleMap = { 'pt-BR': 'pt_BR' }; -var supportedLocalesList = _.values(langLocaleMap).concat(_.values(headerLocaleMap)); +var supportedLocalesList = Object.values(langLocaleMap) + .concat(Object.values(headerLocaleMap)) + .filter(function (value, index, self) { return self.indexOf(value) === index;}); function _getLocaleFromHeader(langString) { var languages = langString.split(','); @@ -77,7 +78,7 @@ AppConstants.StoreSubscribePrototype, }, getSupportedLocales: function() { - return assign({}, supportedLocalesList); + return supportedLocalesList.slice(); }, dispatchToken: AppDispatcher.register(function(payload) {