layout.pug 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. doctype html
  2. html(
  3. lang=(currentLngCode || 'en')
  4. )
  5. - metadata = metadata || {}
  6. block vars
  7. head
  8. include ./_metadata.pug
  9. if (typeof(gaExperiments) != "undefined")
  10. |!{gaExperiments}
  11. //- Stylesheet
  12. link(rel='stylesheet', href=buildCssPath(getCssThemeModifier(userSettings, brandVariation)), id="main-stylesheet")
  13. block css
  14. each file in entrypointStyles('main')
  15. link(rel='stylesheet', href=file)
  16. block _headLinks
  17. if settings.i18n.subdomainLang
  18. each subdomainDetails in settings.i18n.subdomainLang
  19. if !subdomainDetails.hide
  20. link(rel="alternate", href=subdomainDetails.url+currentUrl, hreflang=subdomainDetails.lngCode)
  21. //- Scripts
  22. //- Google Analytics
  23. if (typeof(gaToken) != "undefined")
  24. script(type="text/javascript", nonce=scriptNonce).
  25. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  26. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  27. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  28. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  29. script(type="text/javascript", nonce=scriptNonce).
  30. ga('create', '#{gaToken}', '#{settings.cookieDomain.replace(/^\./, "")}');
  31. ga('set', 'anonymizeIp', true);
  32. ga('send', 'pageview');
  33. try {
  34. ga.isBlocked = localStorage.getItem('gaBlocked') === 'true'
  35. if (!ga.isBlocked) {
  36. window.addEventListener('load', function () {
  37. setTimeout(function () {
  38. if (!ga.loaded) localStorage.setItem('gaBlocked', 'true')
  39. }, 4000)
  40. })
  41. }
  42. } catch (e) {}
  43. if gaOptimize === true && typeof(gaOptimizeId) != "undefined"
  44. //- Anti-flicker snippet
  45. style(type='text/css') .async-hide { opacity: 0 !important}
  46. script(type="text/javascript", nonce=scriptNonce).
  47. if (!ga.isBlocked) {
  48. ga('require', '#{gaOptimizeId}');
  49. ga('send', 'event', 'pageview', document.title.substring(0, 499), window.location.href.substring(0, 499));
  50. (function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
  51. h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
  52. (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
  53. })(window,document.documentElement,'async-hide','dataLayer',4000,
  54. {'#{gaOptimizeId}':true});
  55. }
  56. else
  57. script(type="text/javascript", nonce=scriptNonce).
  58. window.ga = function() { console.log("would send to GA", arguments) };
  59. block meta
  60. meta(name="ol-csrfToken" content=csrfToken)
  61. //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
  62. //- See: https://webpack.js.org/guides/public-path/#on-the-fly
  63. meta(name="ol-baseAssetPath" content=buildBaseAssetPath())
  64. meta(name="ol-usersEmail" content=getUserEmail())
  65. meta(name="ol-sharelatex" data-type="json" content={
  66. siteUrl: settings.siteUrl,
  67. wsUrl,
  68. })
  69. meta(name="ol-ab" data-type="json" content={})
  70. meta(name="ol-user_id" content=getLoggedInUserId())
  71. //- Internationalisation settings
  72. meta(name="ol-i18n" data-type="json" content={
  73. currentLangCode: currentLngCode
  74. })
  75. //- Expose some settings globally to the frontend
  76. meta(name="ol-ExposedSettings" data-type="json" content=ExposedSettings)
  77. meta(name="ol-splitTestVariants" data-type="json" content=splitTestVariants || {})
  78. if (typeof(settings.algolia) != "undefined")
  79. meta(name="ol-algolia" data-type="json" content={
  80. appId: settings.algolia.app_id,
  81. apiKey: settings.algolia.read_only_api_key,
  82. indexes: settings.algolia.indexes
  83. })
  84. if (typeof(settings.templates) != "undefined")
  85. meta(name="ol-sharelatex.templates" data-type="json" content={
  86. user_id : settings.templates.user_id,
  87. cdnDomain : settings.templates.cdnDomain,
  88. indexName : settings.templates.indexName
  89. })
  90. block head-scripts
  91. body(ng-csp=(cspEnabled ? "no-unsafe-eval" : false))
  92. if(settings.recaptcha && settings.recaptcha.siteKeyV3)
  93. script(type="text/javascript", nonce=scriptNonce, src="https://www.recaptcha.net/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
  94. if (typeof(suppressSkipToContent) == "undefined")
  95. a(class="skip-to-content" href="#main-content") #{translate('skip_to_content')}
  96. if (typeof(suppressNavbar) == "undefined")
  97. include layout/navbar
  98. block content
  99. if (typeof(suppressFooter) == "undefined")
  100. include layout/footer
  101. != moduleIncludes("contactModal", locals)
  102. block foot-scripts
  103. each file in entrypointScripts("main")
  104. script(type="text/javascript", nonce=scriptNonce, src=file)
  105. script(type="text/javascript", nonce=scriptNonce).
  106. //- Look for bundle
  107. var cdnBlocked = typeof Frontend === 'undefined'
  108. //- Prevent loops
  109. var noCdnAlreadyInUrl = window.location.href.indexOf("nocdn=true") != -1
  110. if (cdnBlocked && !noCdnAlreadyInUrl && navigator.userAgent.indexOf("Googlebot") == -1) {
  111. //- Set query param, server will not set CDN url
  112. window.location.search += "&nocdn=true";
  113. }
  114. if hasFeature('saas')
  115. script(type="text/javascript", nonce=scriptNonce, src=buildJsPath('cdn-load-test.js'))