layout.pug 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. link(rel='stylesheet', href=buildStylesheetPath("libraries.css"))
  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. if gaOptimize === true && typeof(gaOptimizeId) != "undefined"
  42. //- Anti-flicker snippet
  43. style(type='text/css') .async-hide { opacity: 0 !important}
  44. script(type="text/javascript", nonce=scriptNonce).
  45. if (!ga.isBlocked) {
  46. ga('require', '#{gaOptimizeId}');
  47. ga('send', 'event', 'pageview', document.title.substring(0, 499), window.location.href.substring(0, 499));
  48. (function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
  49. h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
  50. (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
  51. })(window,document.documentElement,'async-hide','dataLayer',4000,
  52. {'#{gaOptimizeId}':true});
  53. }
  54. else
  55. script(type="text/javascript", nonce=scriptNonce).
  56. window.ga = function() { console.log("would send to GA", arguments) };
  57. block meta
  58. meta(name="ol-csrfToken" content=csrfToken)
  59. //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
  60. //- See: https://webpack.js.org/guides/public-path/#on-the-fly
  61. meta(name="ol-baseAssetPath" content=buildBaseAssetPath())
  62. meta(name="ol-usersEmail" content=getUserEmail())
  63. meta(name="ol-sharelatex" data-type="json" content={
  64. siteUrl: settings.siteUrl,
  65. wsUrl,
  66. })
  67. meta(name="ol-ab" data-type="json" content={})
  68. meta(name="ol-user_id" content=getLoggedInUserId())
  69. //- Internationalisation settings
  70. meta(name="ol-i18n" data-type="json" content={
  71. currentLangCode: currentLngCode
  72. })
  73. //- Expose some settings globally to the frontend
  74. meta(name="ol-ExposedSettings" data-type="json" content=ExposedSettings)
  75. if (typeof(settings.algolia) != "undefined")
  76. meta(name="ol-algolia" data-type="json" content={
  77. appId: settings.algolia.app_id,
  78. apiKey: settings.algolia.read_only_api_key,
  79. indexes: settings.algolia.indexes
  80. })
  81. if (typeof(settings.templates) != "undefined")
  82. meta(name="ol-sharelatex.templates" data-type="json" content={
  83. user_id : settings.templates.user_id,
  84. cdnDomain : settings.templates.cdnDomain,
  85. indexName : settings.templates.indexName
  86. })
  87. block head-scripts
  88. body(ng-csp=(cspEnabled ? "no-unsafe-eval" : false))
  89. if(settings.recaptcha && settings.recaptcha.siteKeyV3)
  90. script(type="text/javascript", nonce=scriptNonce, src="https://www.recaptcha.net/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
  91. if (typeof(suppressSkipToContent) == "undefined")
  92. a(class="skip-to-content" href="#main-content") #{translate('skip_to_content')}
  93. if (typeof(suppressNavbar) == "undefined")
  94. include layout/navbar
  95. block content
  96. if (typeof(suppressFooter) == "undefined")
  97. include layout/footer
  98. != moduleIncludes("contactModal", locals)
  99. block foot-scripts
  100. script(type="text/javascript", nonce=scriptNonce, src=buildJsPath('libraries.js'))
  101. script(type="text/javascript", nonce=scriptNonce, src=buildJsPath('main.js'))
  102. script(type="text/javascript", nonce=scriptNonce).
  103. //- Look for bundle
  104. var cdnBlocked = typeof Frontend === 'undefined'
  105. //- Prevent loops
  106. var noCdnAlreadyInUrl = window.location.href.indexOf("nocdn=true") != -1
  107. if (cdnBlocked && !noCdnAlreadyInUrl && navigator.userAgent.indexOf("Googlebot") == -1) {
  108. //- Set query param, server will not set CDN url
  109. window.location.search += "&nocdn=true";
  110. }
  111. if hasFeature('saas')
  112. script(type="text/javascript", nonce=scriptNonce).
  113. //- Test for CDN availability and report to sentry if loading failed
  114. var cdnLoadTest = document.createElement('img')
  115. cdnLoadTest.addEventListener('error', function () {
  116. throw new Error('CDN test image load error (cdn.overleaf.net)')
  117. })
  118. cdnLoadTest.src = 'https://cdn.overleaf.net/img/1p.gif'