mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Use pug template inheritance
Additionally move the javascript code blocks to the end of the html body, instead of the header. This is generally good practice, but it also fixes an issue with the cookie consent overlay due to a html element not existing on the page at the time of script execution.
This commit is contained in:
2
app.js
2
app.js
@@ -426,7 +426,7 @@ aws.initConfig(awsProps)
|
||||
const options = _.extend({}, allExtraOptions, clientOptionsHandler.get());
|
||||
options.optionsHash = clientOptionsHandler.getHash();
|
||||
options.compilerExplorerOptions = JSON.stringify(allExtraOptions);
|
||||
options.extraBodyClass = extraBodyClass;
|
||||
options.extraBodyClass = options.embedded ? 'embedded' : extraBodyClass;
|
||||
options.httpRoot = httpRoot;
|
||||
options.httpRootDir = httpRootDir;
|
||||
options.storageSolution = storageSolution;
|
||||
|
||||
37
views/_layout.pug
Normal file
37
views/_layout.pug
Normal file
@@ -0,0 +1,37 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
base(href=httpRoot)
|
||||
|
||||
block meta
|
||||
include meta.pug
|
||||
|
||||
block styles
|
||||
link(href=require("main.css") rel="stylesheet")
|
||||
style#theme
|
||||
|
||||
body(class=extraBodyClass)
|
||||
block content
|
||||
#root
|
||||
|
||||
block footer
|
||||
include templates.pug
|
||||
|
||||
block scripts
|
||||
script(src=`${httpRootDir}client-options.js?hash=${optionsHash}`)
|
||||
//-
|
||||
The atob/base64 stuff below is to prevent any XSS attacks: now we have user content in the options (from
|
||||
short links), it's possible to do XSS attacks, by leaving <script> tags in the source etc, which can be
|
||||
interpreted by the browser.
|
||||
script
|
||||
| var extraOptions = JSON.parse(decodeURIComponent("!{encodeURIComponent(compilerExplorerOptions)}"));
|
||||
| for (k in extraOptions) { window.compilerExplorerOptions[k] = extraOptions[k]; }
|
||||
|
|
||||
| window.httpRoot = '#{httpRoot}'; window.httpRootDir = '#{httpRootDir}';
|
||||
|
|
||||
| if (window.navigator.userAgent.indexOf("Trident/") > 0) {
|
||||
| var s = document.createElement("script");
|
||||
| s.src = "#{httpRootDir}dist/es6-shim.min.js";
|
||||
| document.head.appendChild(s);
|
||||
| }
|
||||
script(src=require("main.js"))
|
||||
@@ -1,14 +1,7 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
base(href=httpRoot)
|
||||
include head.pug
|
||||
body.embedded
|
||||
a.float-link.link(href="/" target="_blank")
|
||||
| Edit on #{language} Compiler Explorer
|
||||
span.fas.fa-external-link-alt
|
||||
br
|
||||
extends _layout.pug
|
||||
|
||||
#root
|
||||
|
||||
include templates.pug
|
||||
block prepend content
|
||||
a.float-link.link(href="/" target="_blank")
|
||||
| Edit on #{language} Compiler Explorer
|
||||
span.fas.fa-external-link-alt
|
||||
br
|
||||
|
||||
211
views/index.pug
211
views/index.pug
@@ -1,111 +1,106 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
base(href=httpRoot)
|
||||
include head.pug
|
||||
body(class=extraBodyClass)
|
||||
nav.navbar.navbar-godbolt.navbar-expand-md.navbar-light.bg-light
|
||||
a.navbar-brand(href="javascript:;" title="Compiler Explorer")
|
||||
svg.logo.align-top(height="50" width="165")
|
||||
include resources/site-logo.svg
|
||||
if extraBodyClass === "beta"
|
||||
include resources/site-logo-beta.svg
|
||||
else if extraBodyClass === "staging"
|
||||
include resources/site-logo-staging.svg
|
||||
else if extraBodyClass === "dev"
|
||||
include resources/site-logo-dev.svg
|
||||
button.navbar-toggler(type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation")
|
||||
span.navbar-toggler-icon
|
||||
.collapse.navbar-collapse#navbarContent
|
||||
ul.navbar-nav.navbar-left.mr-auto
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#addDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Add...
|
||||
div.dropdown-menu(aria-labelledby="moreDropdown")
|
||||
a.dropdown-item#add-editor(href="javascript:;" title="Click or drag to desired destination")
|
||||
span.dropdown-icon.fa.fa-code
|
||||
| Source Editor
|
||||
a.dropdown-item#add-diff(href="javascript:;" title="Click or drag to desired destination")
|
||||
span.dropdown-icon.fas.fa-exchange-alt
|
||||
| Diff View
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#moreDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") More
|
||||
div.dropdown-menu(aria-labelledby="moreDropdown")
|
||||
a.dropdown-item#setting(href="javascript:;" data-target="#settings" data-toggle="modal")
|
||||
span.dropdown-icon.fas.fa-sliders-h
|
||||
| Settings
|
||||
div.dropdown-divider
|
||||
a.dropdown-item#ui-brokenlink(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-undo-alt
|
||||
| Reset UI layout
|
||||
a.dropdown-item#ui-reset(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-trash-alt
|
||||
| Reset code and UI layout
|
||||
a.dropdown-item#ui-duplicate(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-external-link-alt
|
||||
| Open new tab
|
||||
ul#motd.navbar-nav.navbar-center.mr-auto.community-advert.d-none
|
||||
span.content
|
||||
| Thanks for using Compiler Explorer
|
||||
span.community-hide(title="Hide and never show again" aria-label="Close")
|
||||
button.close(type="button" aria-hidden="true") ×
|
||||
ul.navbar-nav.navbar-right
|
||||
li.nav-item
|
||||
a.nav-link#share(href="javascript:;") Share
|
||||
b.fas.fa-caret-down
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#otherDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Other
|
||||
div.dropdown-menu.dropdown-menu-right(aria-labelledby="otherDropdown")
|
||||
a.dropdown-item(href="https://www.patreon.com/bePatron?u=3691963" title="Help Compiler Explorer - become a Patron" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fab.fa-patreon
|
||||
| Become a Patron
|
||||
if githubEnabled
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer" title="View the source on GitHub" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fab.fa-github
|
||||
| Source on GitHub
|
||||
a.dropdown-item(href="https://groups.google.com/forum/#!forum/compiler-explorer-discussion" title="Join Compiler Explorer Public Google Group" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-envelope
|
||||
| Mailing list
|
||||
a.dropdown-item(href="https://godbolt.org/admin/libraries.html" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-book
|
||||
| Installed libraries
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer/wiki" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-book-open
|
||||
| Wiki
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer/issues" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-exclamation-circle
|
||||
| Report an issue
|
||||
a.dropdown-item#thanks-to(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-users
|
||||
| Thanks to...
|
||||
a.dropdown-item(href="https://xania.org/201609/how-compiler-explorer-runs-on-amazon" target="_blank")
|
||||
span.dropdown-icon.fas.fa-cloud-meatball
|
||||
| How it works
|
||||
a.dropdown-item(href="mailto:matt@godbolt.org" target="_blank" rel="noopener noreferrer")
|
||||
span.dropdown-icon.fas.fa-paper-plane
|
||||
| Contact the author
|
||||
a.dropdown-item(href="https://xania.org/MattGodbolt" rel="author" target="_blank")
|
||||
span.dropdown-icon.fas.fa-address-card
|
||||
| About the author
|
||||
a.dropdown-item#changes(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-sticky-note
|
||||
| Changelog
|
||||
a.dropdown-item#version-tree(href="javascript:;" target="_blank")
|
||||
span.dropdown-icon.fas.fa-code-branch
|
||||
| Version tree
|
||||
if sharingEnabled
|
||||
a.dropdown-item#socialshare
|
||||
if policies.cookies.enabled || policies.privacy.enabled
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#policiesDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Policies
|
||||
div.dropdown-menu.dropdown-menu-right(aria-labelledby="policiesDropdown")
|
||||
a.dropdown-item#cookies(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-cookie-bite
|
||||
| Cookie policy
|
||||
a.dropdown-item#privacy(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-user-lock
|
||||
| Privacy policy
|
||||
#root
|
||||
extends _layout.pug
|
||||
|
||||
include templates.pug
|
||||
block prepend content
|
||||
nav.navbar.navbar-godbolt.navbar-expand-md.navbar-light.bg-light
|
||||
a.navbar-brand(href="javascript:;" title="Compiler Explorer")
|
||||
svg.logo.align-top(height="50" width="165")
|
||||
include resources/site-logo.svg
|
||||
if extraBodyClass === "beta"
|
||||
include resources/site-logo-beta.svg
|
||||
else if extraBodyClass === "staging"
|
||||
include resources/site-logo-staging.svg
|
||||
else if extraBodyClass === "dev"
|
||||
include resources/site-logo-dev.svg
|
||||
button.navbar-toggler(type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation")
|
||||
span.navbar-toggler-icon
|
||||
.collapse.navbar-collapse#navbarContent
|
||||
ul.navbar-nav.navbar-left.mr-auto
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#addDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Add...
|
||||
div.dropdown-menu(aria-labelledby="moreDropdown")
|
||||
a.dropdown-item#add-editor(href="javascript:;" title="Click or drag to desired destination")
|
||||
span.dropdown-icon.fa.fa-code
|
||||
| Source Editor
|
||||
a.dropdown-item#add-diff(href="javascript:;" title="Click or drag to desired destination")
|
||||
span.dropdown-icon.fas.fa-exchange-alt
|
||||
| Diff View
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#moreDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") More
|
||||
div.dropdown-menu(aria-labelledby="moreDropdown")
|
||||
a.dropdown-item#setting(href="javascript:;" data-target="#settings" data-toggle="modal")
|
||||
span.dropdown-icon.fas.fa-sliders-h
|
||||
| Settings
|
||||
div.dropdown-divider
|
||||
a.dropdown-item#ui-brokenlink(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-undo-alt
|
||||
| Reset UI layout
|
||||
a.dropdown-item#ui-reset(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-trash-alt
|
||||
| Reset code and UI layout
|
||||
a.dropdown-item#ui-duplicate(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-external-link-alt
|
||||
| Open new tab
|
||||
ul#motd.navbar-nav.navbar-center.mr-auto.community-advert.d-none
|
||||
span.content
|
||||
| Thanks for using Compiler Explorer
|
||||
span.community-hide(title="Hide and never show again" aria-label="Close")
|
||||
button.close(type="button" aria-hidden="true") ×
|
||||
ul.navbar-nav.navbar-right
|
||||
li.nav-item
|
||||
a.nav-link#share(href="javascript:;") Share
|
||||
b.fas.fa-caret-down
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#otherDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Other
|
||||
div.dropdown-menu.dropdown-menu-right(aria-labelledby="otherDropdown")
|
||||
a.dropdown-item(href="https://www.patreon.com/bePatron?u=3691963" title="Help Compiler Explorer - become a Patron" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fab.fa-patreon
|
||||
| Become a Patron
|
||||
if githubEnabled
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer" title="View the source on GitHub" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fab.fa-github
|
||||
| Source on GitHub
|
||||
a.dropdown-item(href="https://groups.google.com/forum/#!forum/compiler-explorer-discussion" title="Join Compiler Explorer Public Google Group" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-envelope
|
||||
| Mailing list
|
||||
a.dropdown-item(href="https://godbolt.org/admin/libraries.html" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-book
|
||||
| Installed libraries
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer/wiki" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-book-open
|
||||
| Wiki
|
||||
a.dropdown-item(href="https://github.com/mattgodbolt/compiler-explorer/issues" target="_blank" rel="noopener")
|
||||
span.dropdown-icon.fas.fa-exclamation-circle
|
||||
| Report an issue
|
||||
a.dropdown-item#thanks-to(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-users
|
||||
| Thanks to...
|
||||
a.dropdown-item(href="https://xania.org/201609/how-compiler-explorer-runs-on-amazon" target="_blank")
|
||||
span.dropdown-icon.fas.fa-cloud-meatball
|
||||
| How it works
|
||||
a.dropdown-item(href="mailto:matt@godbolt.org" target="_blank" rel="noopener noreferrer")
|
||||
span.dropdown-icon.fas.fa-paper-plane
|
||||
| Contact the author
|
||||
a.dropdown-item(href="https://xania.org/MattGodbolt" rel="author" target="_blank")
|
||||
span.dropdown-icon.fas.fa-address-card
|
||||
| About the author
|
||||
a.dropdown-item#changes(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-sticky-note
|
||||
| Changelog
|
||||
a.dropdown-item#version-tree(href="javascript:;" target="_blank")
|
||||
span.dropdown-icon.fas.fa-code-branch
|
||||
| Version tree
|
||||
if sharingEnabled
|
||||
a.dropdown-item#socialshare
|
||||
if policies.cookies.enabled || policies.privacy.enabled
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle#policiesDropdown(href="javascript:;" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false") Policies
|
||||
div.dropdown-menu.dropdown-menu-right(aria-labelledby="policiesDropdown")
|
||||
a.dropdown-item#cookies(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-cookie-bite
|
||||
| Cookie policy
|
||||
a.dropdown-item#privacy(href="javascript:;")
|
||||
span.dropdown-icon.fas.fa-user-lock
|
||||
| Privacy policy
|
||||
|
||||
block append footer
|
||||
include popups.pug
|
||||
|
||||
@@ -25,22 +25,3 @@ meta(name="author" content="Matt Godbolt")
|
||||
meta(name="google" content="nositelinkssearchbox")
|
||||
meta(name="google" content="notranslate")
|
||||
meta(id="meta-theme" name="theme-color" content="#f2f2f2")
|
||||
|
||||
link(href=require("main.css") rel="stylesheet")
|
||||
style#theme
|
||||
|
||||
// The atob/base64 stuff below is to prevent any XSS attacks: now we have user content in the options (from
|
||||
// short links), it's possible to do XSS attacks, by leaving <script> tags in the source etc, which can be
|
||||
// interpreted by the browser.
|
||||
script(src=`${httpRootDir}client-options.js?hash=${optionsHash}`)
|
||||
script
|
||||
| var extraOptions = JSON.parse(decodeURIComponent("!{encodeURIComponent(compilerExplorerOptions)}"));
|
||||
| for (k in extraOptions) { window.compilerExplorerOptions[k] = extraOptions[k]; }
|
||||
script window.httpRoot = '#{httpRoot}'; window.httpRootDir = '#{httpRootDir}';
|
||||
script
|
||||
| if (window.navigator.userAgent.indexOf("Trident/") > 0) {
|
||||
| var s = document.createElement("script");
|
||||
| s.src = "#{httpRootDir}dist/es6-shim.min.js";
|
||||
| document.head.appendChild(s);
|
||||
| }
|
||||
script(src=require("main.js"))
|
||||
Reference in New Issue
Block a user