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:
Peter Cottle 2018-10-24 08:52:11 -07:00 committed by GitHub
commit 51205e416b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -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() {