layout.pug 4.7 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. 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('send', 'pageview');
  30. try {
  31. ga.isBlocked = localStorage.getItem('gaBlocked') === 'true'
  32. if (!ga.isBlocked) {
  33. window.addEventListener('load', function () {
  34. setTimeout(function () {
  35. if (!ga.loaded) localStorage.setItem('gaBlocked', 'true')
  36. }, 4000)
  37. })
  38. }
  39. } catch (e) {}
  40. if gaOptimize === true && typeof(gaOptimizeId) != "undefined"
  41. //- Anti-flicker snippet
  42. style(type='text/css') .async-hide { opacity: 0 !important}
  43. script(type="text/javascript", nonce=scriptNonce).
  44. if (!ga.isBlocked) {
  45. ga('require', '#{gaOptimizeId}');
  46. ga('send', 'event', 'pageview', document.title.substring(0, 499), window.location.href.substring(0, 499));
  47. (function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;
  48. h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};
  49. (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;
  50. })(window,document.documentElement,'async-hide','dataLayer',4000,
  51. {'#{gaOptimizeId}':true});
  52. }
  53. else
  54. script(type="text/javascript", nonce=scriptNonce).
  55. window.ga = function() { console.log("would send to GA", arguments) };
  56. block meta
  57. meta(name="ol-csrfToken" content=csrfToken)
  58. //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
  59. //- See: https://webpack.js.org/guides/public-path/#on-the-fly
  60. meta(name="ol-baseAssetPath" content=buildBaseAssetPath())
  61. meta(name="ol-usersEmail" content=getUserEmail())
  62. meta(name="ol-sharelatex" data-type="json" content={
  63. siteUrl: settings.siteUrl,
  64. wsUrl,
  65. })
  66. meta(name="ol-ab" data-type="json" content={})
  67. meta(name="ol-user_id" content=getLoggedInUserId())
  68. //- Internationalisation settings
  69. meta(name="ol-i18n" data-type="json" content={
  70. currentLangCode: currentLngCode
  71. })
  72. //- Expose some settings globally to the frontend
  73. meta(name="ol-ExposedSettings" data-type="json" content=ExposedSettings)
  74. if (typeof(settings.algolia) != "undefined")
  75. meta(name="ol-sharelatex.algolia" data-type="json" content={
  76. app_id: settings.algolia.app_id,
  77. api_key: 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))
  88. if(settings.recaptcha && settings.recaptcha.siteKeyV3)
  89. script(type="text/javascript", nonce=scriptNonce, src="https://www.google.com/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
  90. if (typeof(suppressNavbar) == "undefined")
  91. include layout/navbar
  92. block content
  93. if (typeof(suppressFooter) == "undefined")
  94. include layout/footer
  95. != moduleIncludes("contactModal", locals)
  96. block foot-scripts
  97. script(type="text/javascript", nonce=scriptNonce, src=buildJsPath('libraries.js'))
  98. script(type="text/javascript", nonce=scriptNonce, src=buildJsPath('main.js'))
  99. script(type="text/javascript", nonce=scriptNonce).
  100. //- Look for bundle
  101. var cdnBlocked = typeof Frontend === 'undefined'
  102. //- Prevent loops
  103. var noCdnAlreadyInUrl = window.location.href.indexOf("nocdn=true") != -1
  104. if (cdnBlocked && !noCdnAlreadyInUrl && navigator.userAgent.indexOf("Googlebot") == -1) {
  105. //- Set query param, server will not set CDN url
  106. window.location.search += "&nocdn=true";
  107. }