layout-base.pug 4.5 KB

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