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

Integrate GDPR banner add-on #473

Closed
wants to merge 9 commits into from
14 changes: 14 additions & 0 deletions assets/scss/partials/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ body {
scrollbar-color: var(--scrollbar-thumb) transparent;
}
/**/

/* scrollbar styles for Chromium */
::-webkit-scrollbar {
height: auto;
}

::-webkit-scrollbar-thumb {
background-color: var(--scrollbar-thumb);
}

::-webkit-scrollbar-track {
background-color: transparent;
}
/**/
10 changes: 10 additions & 0 deletions assets/scss/partials/footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,14 @@ footer.site-footer {
color: var(--body-text-color);
}
}

.GDPRbanner {
color: var(--body-text-color);
font-weight: normal;
font-size: 1.2rem;

a {
color: var(--body-text-color);
}
}
}
63 changes: 36 additions & 27 deletions assets/scss/partials/layout/article.scss
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
}

.article-page.has-toc {

.left-sidebar {
display: none;
}
Expand Down Expand Up @@ -395,6 +394,41 @@
}
}

.highlight {
background-color: var(--pre-background-color);
padding: var(--card-padding);
position: relative;

&:hover {
.copyCodeButton {
opacity: 1;
}
}

pre {
margin: initial;
padding: 0;
margin: 0;
width: auto;
}
}

.copyCodeButton {
position: absolute;
top: calc(var(--card-padding));
right: calc(var(--card-padding));
background: var(--card-background);
border: none;
box-shadow: var(--shadow-l2);
border-radius: var(--tag-border-radius);
padding: 8px 16px;
color: var(--card-text-color-main);
cursor: pointer;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s ease;
}

.table-wrapper {
padding: 0 var(--card-padding);
overflow-x: auto;
Expand Down Expand Up @@ -449,6 +483,7 @@
/// Negative margins
blockquote,
figure,
.highlight,
pre,
.gallery,
.video-wrapper,
Expand All @@ -458,30 +493,4 @@
margin-right: calc((var(--card-padding)) * -1);
width: calc(100% + var(--card-padding) * 2);
}

.highlight {
position: relative;

&:hover {
.copyCodeButton {
opacity: 1;
}
}
}

.copyCodeButton {
position: absolute;
top: calc(var(--card-padding));
right: 0;
background: var(--card-background);
border: none;
box-shadow: var(--shadow-l2);
border-radius: var(--tag-border-radius);
padding: 8px 16px;
color: var(--card-text-color-main);
cursor: pointer;
font-size: 14px;
opacity: 0;
transition: opacity 0.3s ease;
}
}
27 changes: 13 additions & 14 deletions assets/scss/variables.scss
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
$defaultTagBackgrounds: #8ea885, #df7988, #0177b8, #ffb900, #6b69d6;
$defaultTagColors: #fff, #fff, #fff, #fff, #fff;

[data-scheme="light"] {
--pre-text-color: #272822;
--pre-background-color: #fafafa;
@import "partials/highlight/light.scss";
}

[data-scheme="dark"] {
color-scheme: dark;
--pre-text-color: #f8f8f2;
--pre-background-color: #272822;
@import "partials/highlight/dark.scss";
}

/*
* Global style
*/
Expand Down Expand Up @@ -46,7 +33,7 @@ $defaultTagColors: #fff, #fff, #fff, #fff, #fff;
--accent-color-darker: #bdc3c7;
--accent-color-text: #000;
--body-text-color: rgba(255, 255, 255, 0.7);
--scrollbar-thumb: #424242;
--scrollbar-thumb: hsl(0, 0%, 40%);
--scrollbar-track: var(--body-background);
}
}
Expand Down Expand Up @@ -160,3 +147,15 @@ $defaultTagColors: #fff, #fff, #fff, #fff, #fff;
--shadow-l4: 0px 24px 32px rgba(0, 0, 0, 0.04), 0px 16px 24px rgba(0, 0, 0, 0.04), 0px 4px 8px rgba(0, 0, 0, 0.04),
0px 0px 1px rgba(0, 0, 0, 0.04);
}

[data-scheme="light"] {
--pre-text-color: #272822;
--pre-background-color: #fafafa;
@import "partials/highlight/light.scss";
}

[data-scheme="dark"] {
--pre-text-color: #f8f8f2;
--pre-background-color: #272822;
@import "partials/highlight/dark.scss";
}
56 changes: 55 additions & 1 deletion assets/ts/gallery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,60 @@ class StackGallery {
}

public static createGallery(container: HTMLElement) {
/// The process of wrapping image with figure tag is done using JavaScript instead of only Hugo markdown render hook
/// because it can not detect whether image is being wrapped by a link or not
/// and it lead to a invalid HTML construction (<a><figure><img></figure></a>)

const images = container.querySelectorAll('img');
for (const img of Array.from(images)) {
/// Images are wrapped with figure tag if the paragraph has only images without texts
/// This is done to allow inline images within paragraphs
const paragraph = img.closest('p');

if (!paragraph || !container.contains(paragraph)) continue;

if (paragraph.textContent.trim() == '') {
/// Once we insert figcaption, this check no longer works
/// So we add a class to paragraph to mark it
paragraph.classList.add('no-text');
}

let isNewLineImage = paragraph.classList.contains('no-text');
if (!isNewLineImage) continue;

const hasLink = img.parentElement.tagName == 'A';

let el: HTMLElement = img;
/// Wrap image with figure tag, with flex-grow and flex-basis values extracted from img's data attributes
const figure = document.createElement('figure');
figure.style.setProperty('flex-grow', img.getAttribute('data-flex-grow') || '1');
figure.style.setProperty('flex-basis', img.getAttribute('data-flex-basis') || '0');
if (hasLink) {
/// Wrap <a> if it exists
el = img.parentElement;
}
el.parentElement.insertBefore(figure, el);
figure.appendChild(el);

/// Add figcaption if it exists
if (img.hasAttribute('alt')) {
const figcaption = document.createElement('figcaption');
figcaption.innerText = img.getAttribute('alt');
figure.appendChild(figcaption);
}

/// Wrap img tag with <a> tag if image was not wrapped by <a> tag
if (!hasLink) {
figure.className = 'gallery-image';

const a = document.createElement('a');
a.href = img.src;
a.setAttribute('target', '_blank');
img.parentNode.insertBefore(a, img);
a.appendChild(img);
}
}

const figuresEl = container.querySelectorAll('figure.gallery-image');

let currentGallery = [];
Expand Down Expand Up @@ -129,4 +183,4 @@ class StackGallery {
}
}

export default StackGallery;
export default StackGallery;
15 changes: 8 additions & 7 deletions assets/ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ let Stack = {
/**
* Add copy button to code block
*/
const codeBlocks = document.querySelectorAll('.article-content > div.highlight');
const highlights = document.querySelectorAll('.article-content div.highlight');
const copyText = `Copy`,
copiedText = `Copied!`;
codeBlocks.forEach(codeBlock => {

highlights.forEach(highlight => {
const copyButton = document.createElement('button');
copyButton.innerHTML = copyText;
copyButton.classList.add('copyCodeButton');
codeBlock.appendChild(copyButton);
highlight.appendChild(copyButton);

const pre = codeBlock.getElementsByTagName('pre');
const code = pre[0].textContent;
const codeBlock = highlight.querySelector('code[data-lang]');
if (!codeBlock) return;

copyButton.addEventListener('click', () => {
navigator.clipboard.writeText(code)
navigator.clipboard.writeText(codeBlock.textContent)
.then(() => {
copyButton.textContent = copiedText;

Expand Down Expand Up @@ -108,4 +109,4 @@ declare global {
}

window.Stack = Stack;
window.createElement = createElement;
window.createElement = createElement;
8 changes: 8 additions & 0 deletions data/gdpr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins:
- name: gtag
enabled: true
optional: true
title: Google Analytics
description: This code gives us insight into the number of people that visit our website, where they are from and what they are clicking on. We follow the guidelines of the Italian Government.
html_src: gdpr/gtag.html
js_src: gtag.js
33 changes: 20 additions & 13 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ theme: hugo-theme-stack
paginate: 5
title: Example Site



# Change it to your Disqus shortname before using
disqusShortname: hugo-theme-stack

Expand All @@ -29,6 +31,11 @@ params:
rssFullContent: true
favicon:

# mode: nocookie, functional, consent
GDPR:
enable: true
mode: consent

footer:
since: 2020
customText:
Expand Down Expand Up @@ -109,7 +116,7 @@ params:
defaultHomeserverUrl: "https://matrix.cactus.chat:8448"
serverName: "cactus.chat"
siteName: "" # You must insert a unique identifier here matching the one you registered (See https://cactus.chat/docs/getting-started/quick-start/#register-your-site)

giscus:
repo:
repoID:
Expand All @@ -122,15 +129,15 @@ params:
emitMetadata: 0

gitalk:
owner:
admin:
repo:
clientID:
clientSecret:
owner:
admin:
repo:
clientID:
clientSecret:

cusdis:
host:
id:
host:
id:
widgets:
enabled:
- search
Expand Down Expand Up @@ -183,19 +190,19 @@ menu:
### For demonstration purpose, the home link will be open in a new tab
newTab: true
icon: home

social:
- identifier: github
name: GitHub
url: https://github.com/CaiJimmy/hugo-theme-stack
params:
icon: brand-github
icon: brand-github

- identifier: twitter
name: Twitter
url: https://twitter.com
params:
icon: brand-twitter
icon: brand-twitter

related:
includeNewer: true
Expand Down
4 changes: 4 additions & 0 deletions exampleSite/content/post/markdown-syntax/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,7 @@ X<sup>n</sup> + Y<sup>n</sup> = Z<sup>n</sup>
Press <kbd><kbd>CTRL</kbd>+<kbd>ALT</kbd>+<kbd>Delete</kbd></kbd> to end the session.

Most <mark>salamanders</mark> are nocturnal, and hunt for insects, worms, and other small creatures.

## Hyperlinked image

[![Google](https://www.google.com/images/branding/googlelogo/1x/googlelogo_light_color_272x92dp.png)](https://google.com)
4 changes: 4 additions & 0 deletions exampleSite/content/post/rich-content/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ Hugo ships with several [Built-in Shortcodes](https://gohugo.io/content-manageme
## bilibilibi Shortcode

{{< bilibili av498363026 >}}

## Gist Shortcode

{{< gist spf13 7896402 >}}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/CaiJimmy/hugo-theme-stack
module github.com/CaiJimmy/hugo-theme-stack/v3

go 1.12
5 changes: 5 additions & 0 deletions i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ search:
other: "#PAGES_COUNT pages (#TIME_SECONDS seconds)"

footer:
GDPR:
consent: Manage GDPR settings
functional: This website use only functional cookies
nocookie: This website doesn't use any cookie and doesn't collect any personal data

builtWith:
other: Built with {{ .Generator }}

Expand Down
Loading