Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: call to action banner #2

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ paginate = 5
# TocTitle = "Table of Contents" # default


# you can set a banner on the top of the page with a call to action
# defaults: dismissible = false; URL is optional
# [params.banner]
# dismissible = false
# text = "Check it out on GitHub"
# url = "https://github.com/mirus-ua/hugo-theme-re-terminal"



[params.twitter]
# set Twitter handles for Twitter cards
# see https://developer.twitter.com/en/docs/tweets/optimize-with-cards/guides/getting-started#card-and-content-attribution
Expand Down
23 changes: 23 additions & 0 deletions assets/css/banner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#banner {
width: 100%;
height: 2rem;
display: grid;
grid-template-columns: 1fr auto;
background: $accent;

& span {
display: flex;
align-items: center;
justify-content: center;
}

& a {
color: #1d212c;
display: inline;
}

& > button {
padding: 0 5px 0 0;
margin: 0;
}
}
3 changes: 2 additions & 1 deletion assets/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
@import "post";
@import "pagination";
@import "footer";
@import "banner";

@import "prism";
@import "syntax";
@import "code";
@import "terms";
@import "gist";
@import "gist";
12 changes: 12 additions & 0 deletions assets/js/banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const banner = document.getElementById("banner");
const buttons = banner.getElementsByTagName("button");

if (buttons?.[0]) {
const listener = buttons[0].addEventListener("click", () => {
banner.remove();
});

if (!document.getElementById("banner")) {
removeEventListener("click", listener);
}
}
4 changes: 4 additions & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ themeColor = "blue"
showMenuItems = 2
fullWidthTheme = false
centerTheme = true
[params.banner]
dismissible = false
text = "Check it out on GitHub"
url = "https://github.com/mirus-ua/hugo-theme-re-terminal"

[languages]
[languages.en.params]
Expand Down
17 changes: 17 additions & 0 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@

</head>
<body class="{{- ( or .Params.color $.Site.Params.ThemeColor ) -}}">
{{ if .Site.Params.Banner }}
{{ with .Site.Params.Banner }}
<div id="banner">
<span>
{{ if .url }}
<a href="{{ .url }}">{{ .text }}</a>
{{ else }}
{{ .text }}
{{ end }}
</span>
{{ if .dismissible }}
<button type="button">x</button>
{{ end }}
</div>
{{ end }}
{{ end }}

{{ $container := cond ($.Site.Params.FullWidthTheme | default false) "container full" (cond ($.Site.Params.CenterTheme | default true) "container center" "container") }}

<div class="{{- $container -}}{{- cond ($.Site.Params.oneHeadingSize | default true) " headings--one-size" "" }}">
Expand Down
7 changes: 7 additions & 0 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@

<script type="text/javascript" src="{{ $bundle.RelPermalink }}"></script>

<!-- Banner JS if it enabled -->
{{ if .Site.Params.Banner }}
{{ $banner := resources.Get "js/banner.js" | js.Build | resources.Minify }}

<script type="text/javascript" src="{{ $banner.RelPermalink }}"></script>
{{ end }}

<!-- Extended footer section-->
{{ partial "extended_footer.html" . }}
2 changes: 1 addition & 1 deletion package.hugo.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
"scripts": {
"test": "echo 'Test'"
},
"version": "1.1.2"
"version": "1.2.0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "re-terminal",
"version": "1.1.2",
"version": "1.2.0",
"author": "Mirus <@mirus-ua> <[email protected]>",
"main": "index.js",
"license": "MIT",
Expand Down