layout.pug 4.6 KB

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