move header and footer into base template

This commit is contained in:
Shawn Smith
2021-11-26 15:29:13 +09:00
parent bd1dc0715a
commit 892d28f58b
15 changed files with 203 additions and 467 deletions

View File

@@ -1,58 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
<style>
.header .is-active {
font-weight: bold;
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ define "content" ]]
<section class="section">
<div class="container">
<div class="columns">
@@ -67,7 +13,6 @@
</div>
</div>
</section>
[[ template "footer" . ]]
<style>
#gopherimage {
width: 200px;
@@ -80,27 +25,4 @@
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
})
</script>
</body>
</html>
[[ end ]]

View File

@@ -1,61 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
<style>
.header .is-active {
font-weight: bold;
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item">
<a href="/supporters">Supporters</a>
</span>
<span class="header-item is-active">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ define "content" ]]
<section class="section">
<div class="container">
<h1 class="title">About</h1>
@@ -66,28 +9,4 @@
<p>Go Report Card relies on the excellent <a href="https://github.com/alecthomas/gometalinter">Go Meta Linter</a> tool.</p>
</div>
</section>
[[ template "footer" . ]]
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
})
</script>
</body>
</html>
[[ end ]]

125
assets/templates/base.html Normal file
View File

@@ -0,0 +1,125 @@
[[ define "base" ]]
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<link rel="stylesheet" href="/assets/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/assets/goreportcard.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
<style>
.header .is-active {
font-weight: bold;
}
</style>
</head>
<body>
<div id="notifications">
</div>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item">
<a href="/supporters"><b>Supporters</b></a>
</span>
<span class="header-item">
<a href="https://patreon.com/goreportcard" style="color:green">Patreon</a>
</span>
<span class="header-item">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ template "content" . ]]
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
<p>
<strong>Go Report Card</strong> by
<a href="https://twitter.com/shawnps">Shawn Smith</a> and
<a href="https://twitter.com/ironzeb">Herman Schaaf</a>,
authors of <a href="https://leanpub.com/productiongo">Production Go</a>.
</p>
<p>Sponsored by:</p>
<p>
<a href="https://www.messaged.com">
<img width="15%" src="/assets/messaged.png">
</a>
</p>
<p>
<a href="https://www.cooperpress.com">
<img width="15%" src="/assets/cooperpress.png">
</a>
</p>
<p>
<a href="https://www.digitalocean.com?utm_medium=opensource&utm_source=goreportcard">
<img width="15%" src="/assets/digitalocean.svg">
</a>
</p>
</div>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/handlebars@4.7.7/dist/handlebars.min.js" integrity="sha256-ZSnrWNaPzGe8v25yP0S6YaMaDLMTDHC+4mHTw0xydEk=" crossorigin="anonymous"></script>
<script>
$(function () {
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
})
</script>
</body>
</html>
[[ end ]]

View File

@@ -1,30 +0,0 @@
[[ define "footer" ]]
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
<p>
<strong>Go Report Card</strong> by
<a href="https://twitter.com/shawnps">Shawn Smith</a> and
<a href="https://twitter.com/ironzeb">Herman Schaaf</a>,
authors of <a href="https://leanpub.com/productiongo">Production Go</a>.
</p>
<p>Sponsored by:</p>
<p>
<a href="https://www.messaged.com">
<img width="15%" src="/assets/messaged.png">
</a>
</p>
<p>
<a href="https://www.cooperpress.com">
<img width="15%" src="/assets/cooperpress.png">
</a>
</p>
<p>
<a href="https://www.digitalocean.com?utm_medium=opensource&utm_source=goreportcard">
<img width="15%" src="/assets/digitalocean.svg">
</a>
</p>
</div>
</div>
</footer>
[[ end ]]

View File

@@ -1,61 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
<style>
.header .is-active {
font-weight: bold;
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item is-active">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item">
<a href="/supporters">Supporters</a>
</span>
<span class="header-item">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ define "content" ]]
<section class="section">
<div class="container">
<h1 class="title">High Scores</h1>
@@ -85,28 +28,4 @@
</p>
</div>
</section>
[[ template "footer" . ]]
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
})
</script>
</body>
</html>
[[ end ]]

View File

@@ -1,62 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<link rel="stylesheet" href="/assets/goreportcard.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="notifications">
</div>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item">
<a href="/supporters"><b>Supporters</b></a>
</span>
<span class="header-item">
<a href="https://patreon.com/goreportcard" style="color:green">Patreon</a>
</span>
<span class="header-item">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ define "content" ]]
<section class="hero is-primary is-medium has-text-centered gopher">
<div class="hero-content">
<div class="container">
@@ -132,8 +74,6 @@
</div>
</section>
[[ template "footer" . ]]
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/handlebars@4.7.7/dist/handlebars.min.js" integrity="sha256-ZSnrWNaPzGe8v25yP0S6YaMaDLMTDHC+4mHTw0xydEk=" crossorigin="anonymous"></script>
<script id="template-alert" type="text/x-handlebars-template">
@@ -201,29 +141,8 @@
// on ready
$(function(){
// handle form submission
$("form#check_form").submit(loadData);
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
});
</script>
</body>
</html>
[[ end ]]

View File

@@ -87,7 +87,34 @@
</div>
</section>
[[ template "footer" . ]]
<footer class="footer">
<div class="container">
<div class="content has-text-centered">
<p>
<strong>Go Report Card</strong> by
<a href="https://twitter.com/shawnps">Shawn Smith</a> and
<a href="https://twitter.com/ironzeb">Herman Schaaf</a>,
authors of <a href="https://leanpub.com/productiongo">Production Go</a>.
</p>
<p>Sponsored by:</p>
<p>
<a href="https://www.messaged.com">
<img width="15%" src="/assets/messaged.png">
</a>
</p>
<p>
<a href="https://www.cooperpress.com">
<img width="15%" src="/assets/cooperpress.png">
</a>
</p>
<p>
<a href="https://www.digitalocean.com?utm_medium=opensource&utm_source=goreportcard">
<img width="15%" src="/assets/digitalocean.svg">
</a>
</p>
</div>
</div>
</footer>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/handlebars@4.7.7/dist/handlebars.min.js" integrity="sha256-ZSnrWNaPzGe8v25yP0S6YaMaDLMTDHC+4mHTw0xydEk=" crossorigin="anonymous"></script>

View File

@@ -1,61 +1,4 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Go Report Card | Go project code quality report cards</title>
<link rel="stylesheet" href="/assets/bulma.0.0.23.min.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '[[ .google_analytics_key ]]', 'auto');
ga('send', 'pageview');
</script>
<style>
.header .is-active {
font-weight: bold;
}
</style>
</head>
<body>
<header class="header">
<div class="container">
<!-- Left side -->
<div class="header-left">
<a class="header-item" href="/">
<h3 class="title">Go Report Card</h3>
</a>
</div>
<!-- Hamburger menu (on mobile) -->
<span class="header-toggle" data-target="header-menu">
<span></span>
<span></span>
<span></span>
</span>
<!-- Right side -->
<div class="header-right header-menu" id="header-menu">
<span class="header-item">
<a href="/high_scores">High Scores</a>
</span>
<span class="header-item">
<a href="https://github.com/gojp/goreportcard">GitHub</a>
</span>
<span class="header-item is-active">
<a href="/supporters">Supporters</a>
</span>
<span class="header-item">
<a href="/about">About</a>
</span>
</div>
</div>
</header>
[[ define "content" ]]
<section class="section">
<div class="container">
<h1 class="title">Supporters</h1>
@@ -68,28 +11,4 @@
</ul>
</div>
</section>
[[ template "footer" . ]]
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
// Get all "header-toggle" elements
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.header-toggle'), 0);
// Check if there are any navbar burgers
if ($navbarBurgers.length > 0) {
// Add a click event on each of them
$navbarBurgers.forEach(function ($el) {
$el.addEventListener('click', function () {
// Get the target from the "data-target" attribute
var target = $el.dataset.target;
var $target = document.getElementById(target);
// Toggle the class on both the "header-toggle" and the "header-menu"
$el.classList.toggle('is-active');
$target.classList.toggle('is-active');
});
});
}
})
</script>
</body>
</html>
[[ end ]]

View File

@@ -14,7 +14,9 @@ func (gh *GRCHandler) AboutHandler(w http.ResponseWriter, r *http.Request) {
return
}
t.Execute(w, map[string]interface{}{
if err := t.ExecuteTemplate(w, "base", map[string]interface{}{
"google_analytics_key": googleAnalyticsKey,
})
}); err != nil {
log.Println("ERROR:", err)
}
}

View File

@@ -15,6 +15,8 @@ func (gh *GRCHandler) errorHandler(w http.ResponseWriter, r *http.Request, statu
return
}
t.Execute(w, nil)
if err := t.ExecuteTemplate(w, "base", nil); err != nil {
log.Println("ERROR:", err)
}
}
}

View File

@@ -68,9 +68,11 @@ func (gh *GRCHandler) HighScoresHandler(w http.ResponseWriter, r *http.Request,
sortedScores[len(sortedScores)-i-1] = heap.Pop(scores).(scoreItem)
}
t.Execute(w, map[string]interface{}{
if err := t.ExecuteTemplate(w, "base", map[string]interface{}{
"HighScores": sortedScores,
"Count": humanize.Comma(int64(count)),
"google_analytics_key": googleAnalyticsKey,
})
}); err != nil {
log.Println("ERROR:", err)
}
}

View File

@@ -69,10 +69,12 @@ func (gh *GRCHandler) HomeHandler(w http.ResponseWriter, r *http.Request, db *ba
return
}
t.Execute(w, map[string]interface{}{
if err := t.ExecuteTemplate(w, "base", map[string]interface{}{
"Recent": recentRepos,
"google_analytics_key": googleAnalyticsKey,
})
}); err != nil {
log.Println(err)
}
return
}

View File

@@ -42,11 +42,13 @@ func (gh *GRCHandler) ReportHandler(w http.ResponseWriter, r *http.Request, db *
return
}
t.Execute(w, map[string]interface{}{
if err := t.Execute(w, map[string]interface{}{
"repo": repo,
"response": string(respBytes),
"loading": needToLoad,
"domain": domain,
"google_analytics_key": googleAnalyticsKey,
})
}); err != nil {
log.Println("ERROR:", err)
}
}

View File

@@ -14,7 +14,9 @@ func (gh *GRCHandler) SupportersHandler(w http.ResponseWriter, r *http.Request)
return
}
t.Execute(w, map[string]interface{}{
if err := t.ExecuteTemplate(w, "base", map[string]interface{}{
"google_analytics_key": googleAnalyticsKey,
})
}); err != nil {
log.Println("ERROR:", err)
}
}

View File

@@ -27,18 +27,6 @@ func (gh *GRCHandler) loadTemplate(name string) (*template.Template, error) {
return nil, err
}
footer, err := gh.AssetsFS.Open("/templates/footer.html")
if err != nil {
return nil, err
}
defer footer.Close()
footerContents, err := ioutil.ReadAll(footer)
if err != nil {
return nil, err
}
tpl, err := template.New(name).Delims("[[", "]]").Funcs(template.FuncMap{
"add": add,
"formatScore": formatScore,
@@ -47,5 +35,21 @@ func (gh *GRCHandler) loadTemplate(name string) (*template.Template, error) {
return nil, err
}
return tpl.Parse(string(footerContents))
if name == "/templates/report.html" {
return tpl, nil
}
base, err := gh.AssetsFS.Open("/templates/base.html")
if err != nil {
return nil, err
}
defer base.Close()
baseContents, err := ioutil.ReadAll(base)
if err != nil {
return nil, err
}
return tpl.Parse(string(baseContents))
}