mirror of
https://github.com/pcottle/learnGitBranching.git
synced 2025-06-28 00:40:07 +02:00
Merge pull request #493 from PanAeon/feature/generate-alternate-urls
Generate alternate url for different locales so search engine could find them all.
This commit is contained in:
commit
51205e416b
2 changed files with 27 additions and 0 deletions
|
@ -86,6 +86,23 @@ 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 = LocaleStore.getSupportedLocales().map(function(langCode) {
|
||||
var url = "https://learngitbranching.js.org/?locale=" + langCode;
|
||||
return '<link rel="alternate" hreflang="'+langCode+'" href="' + url +'" />';
|
||||
});
|
||||
var defaultUrl = "https://learngitbranching.js.org/?locale=" + LocaleStore.getDefaultLocale();
|
||||
altLinks.push('<link rel="alternate" hreflang="x-default" href="' + defaultUrl +'" />');
|
||||
$('head').prepend(altLinks);
|
||||
|
||||
};
|
||||
|
||||
var intlRefresh = function() {
|
||||
if (!window.$) { return; }
|
||||
var countryCode = LocaleStore.getLocale().split("_")[0];
|
||||
|
@ -252,6 +269,8 @@ var initDemo = function(sandbox) {
|
|||
tryLocaleDetect();
|
||||
}
|
||||
|
||||
insertAlternateLinks();
|
||||
|
||||
if (params.command) {
|
||||
var command = unescape(params.command);
|
||||
sandbox.mainVis.customEvents.on('gitEngineReady', function() {
|
||||
|
|
|
@ -30,6 +30,10 @@ var headerLocaleMap = {
|
|||
'pt-BR': 'pt_BR'
|
||||
};
|
||||
|
||||
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(',');
|
||||
var desiredLocale;
|
||||
|
@ -73,6 +77,10 @@ AppConstants.StoreSubscribePrototype,
|
|||
return _locale;
|
||||
},
|
||||
|
||||
getSupportedLocales: function() {
|
||||
return supportedLocalesList.slice();
|
||||
},
|
||||
|
||||
dispatchToken: AppDispatcher.register(function(payload) {
|
||||
var action = payload.action;
|
||||
var shouldInform = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue