layout.pug 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. doctype html
  2. html(
  3. lang=(currentLngCode || 'en')
  4. )
  5. - metadata = metadata || {}
  6. block vars
  7. head
  8. include ./_metadata.pug
  9. script(type="text/javascript", nonce=scriptNonce).
  10. // Stop superfish from loading
  11. window.similarproducts = true
  12. if (typeof(gaExperiments) != "undefined")
  13. |!{gaExperiments}
  14. //- Stylesheet
  15. link(rel='stylesheet', href=buildCssPath(getCssThemeModifier(userSettings, brandVariation)), id="main-stylesheet")
  16. link(rel='stylesheet', href=buildStylesheetPath("libraries.css"))
  17. block _headLinks
  18. if settings.i18n.subdomainLang
  19. each subdomainDetails in settings.i18n.subdomainLang
  20. if !subdomainDetails.hide
  21. link(rel="alternate", href=subdomainDetails.url+currentUrl, hreflang=subdomainDetails.lngCode)
  22. //- Scripts
  23. //- Google Analytics
  24. if (typeof(gaToken) != "undefined")
  25. script(type="text/javascript", nonce=scriptNonce).
  26. (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  27. (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  28. m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  29. })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  30. script(type="text/javascript", nonce=scriptNonce).
  31. ga('create', '#{gaToken}', '#{settings.cookieDomain.replace(/^\./, "")}');
  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. block meta
  60. meta(name="ol-csrfToken" content=csrfToken)
  61. //- Configure dynamically loaded assets (via webpack) to be downloaded from CDN
  62. //- See: https://webpack.js.org/guides/public-path/#on-the-fly
  63. meta(name="ol-baseAssetPath" content=buildBaseAssetPath())
  64. meta(name="ol-usersEmail" content=getUserEmail())
  65. meta(name="ol-sharelatex" data-type="json" content={
  66. siteUrl: settings.siteUrl,
  67. wsUrl,
  68. })
  69. meta(name="ol-ab" data-type="json" content={})
  70. meta(name="ol-user_id" content=getLoggedInUserId())
  71. //- Internationalisation settings
  72. meta(name="ol-i18n" data-type="json" content={
  73. currentLangCode: currentLngCode
  74. })
  75. //- Expose some settings globally to the frontend
  76. meta(name="ol-ExposedSettings" data-type="json" content=ExposedSettings)
  77. if (typeof(settings.algolia) != "undefined")
  78. meta(name="ol-sharelatex.algolia" data-type="json" content={
  79. app_id: settings.algolia.app_id,
  80. api_key: settings.algolia.read_only_api_key,
  81. indexes: settings.algolia.indexes
  82. })
  83. if (typeof(settings.templates) != "undefined")
  84. meta(name="ol-sharelatex.templates" data-type="json" content={
  85. user_id : settings.templates.user_id,
  86. cdnDomain : settings.templates.cdnDomain,
  87. indexName : settings.templates.indexName
  88. })
  89. block head-scripts
  90. body(ng-csp=(cspEnabled ? "no-unsafe-eval" : false))
  91. if(settings.recaptcha && settings.recaptcha.siteKeyV3)
  92. script(type="text/javascript", nonce=scriptNonce, src="https://www.google.com/recaptcha/api.js?render="+settings.recaptcha.siteKeyV3)
  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. }