layout.pug 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. if (typeof(gaTokenV4) != "undefined")
  60. script(async, nonce=scriptNonce, src='https://www.googletagmanager.com/gtag/js?id=' + gaTokenV4)
  61. script(type="text/javascript", nonce=scriptNonce).
  62. window.dataLayer = window.dataLayer || [];
  63. function gtag(){dataLayer.push(arguments);}
  64. gtag('js', new Date());
  65. gtag('config', '#{gaTokenV4}');
  66. block meta
  67. meta(name="ol-csrfToken" content=csrfToken)
  68. //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
  69. //- See: https://webpack.js.org/guides/public-path/#on-the-fly
  70. meta(name="ol-baseAssetPath" content=buildBaseAssetPath())
  71. meta(name="ol-usersEmail" content=getUserEmail())
  72. meta(name="ol-sharelatex" data-type="json" content={
  73. siteUrl: settings.siteUrl,
  74. wsUrl,
  75. })
  76. meta(name="ol-ab" data-type="json" content={})
  77. meta(name="ol-user_id" content=getLoggedInUserId())
  78. //- Internationalisation settings
  79. meta(name="ol-i18n" data-type="json" content={
  80. currentLangCode: currentLngCode
  81. })
  82. //- Expose some settings globally to the frontend
  83. meta(name="ol-ExposedSettings" data-type="json" content=ExposedSettings)
  84. meta(name="ol-splitTestVariants" data-type="json" content=splitTestVariants || {})
  85. if (typeof(settings.algolia) != "undefined")
  86. meta(name="ol-algolia" data-type="json" content={
  87. appId: settings.algolia.app_id,
  88. apiKey: settings.algolia.read_only_api_key,
  89. indexes: settings.algolia.indexes
  90. })
  91. if (typeof(settings.templates) != "undefined")
  92. meta(name="ol-sharelatex.templates" data-type="json" content={
  93. user_id : settings.templates.user_id,
  94. cdnDomain : settings.templates.cdnDomain,
  95. indexName : settings.templates.indexName
  96. })
  97. block head-scripts
  98. body(ng-csp=(cspEnabled ? "no-unsafe-eval" : false))
  99. if(settings.recaptcha && settings.recaptcha.siteKeyV3)
  100. script(type="text/javascript", nonce=scriptNonce, src="https://www.recaptcha.net/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
  101. if (typeof(suppressSkipToContent) == "undefined")
  102. a(class="skip-to-content" href="#main-content") #{translate('skip_to_content')}
  103. if (typeof(suppressNavbar) == "undefined")
  104. include layout/navbar
  105. block content
  106. if (typeof(suppressFooter) == "undefined")
  107. include layout/footer
  108. != moduleIncludes("contactModal", locals)
  109. block foot-scripts
  110. each file in entrypointScripts("main")
  111. script(type="text/javascript", nonce=scriptNonce, src=file)
  112. script(type="text/javascript", nonce=scriptNonce).
  113. //- Look for bundle
  114. var cdnBlocked = typeof Frontend === 'undefined'
  115. //- Prevent loops
  116. var noCdnAlreadyInUrl = window.location.href.indexOf("nocdn=true") != -1
  117. if (cdnBlocked && !noCdnAlreadyInUrl && navigator.userAgent.indexOf("Googlebot") == -1) {
  118. //- Set query param, server will not set CDN url
  119. window.location.search += "&nocdn=true";
  120. }