Skip to content

Commit 49e10ab

Browse files
committed
WIP: frontend: add selfhosting view toggle
Preliminary commit to cater some feedback about its design and underlying JS code; will implement actual content modification later. Signed-off-by: Luca Zeuch <[email protected]>
1 parent 80379d5 commit 49e10ab

File tree

4 files changed

+69
-0
lines changed

4 files changed

+69
-0
lines changed

assets/js/custom.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
// Put your custom JS code here
2+
3+
// self-hosting view.
4+
5+
const storedSelfhost = localStorage.getItem('selfhost');
6+
7+
const getSelfhost = () => {
8+
if (storedSelfhost) {
9+
return storedSelfhost;
10+
}
11+
12+
return 'no';
13+
};
14+
15+
const setSelfhost = function (selfhost) {
16+
document.documentElement.setAttribute('data-bs-selfhost', selfhost);
17+
};
18+
19+
setSelfhost(getSelfhost());
20+
21+
window.addEventListener('DOMContentLoaded', () => {
22+
document.querySelectorAll('[data-bs-selfhost-value]').forEach((element) => {
23+
element.addEventListener('click', (event) => {
24+
const selfhost = element.getAttribute('data-bs-selfhost-value');
25+
localStorage.setItem('selfhost', selfhost);
26+
setSelfhost(selfhost);
27+
});
28+
}
29+
)});

assets/scss/common/_custom.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,28 @@ pre.shiki {
147147
opacity: var(--ec-frm-inlBtnBgActOpa);
148148
}
149149

150+
// show active server if self-hosting view enabled
151+
html[data-bs-selfhost="yes"] {
152+
.icon-tabler-server {
153+
display: block;
154+
}
155+
156+
.icon-tabler-server-off {
157+
display: none;
158+
}
159+
}
160+
161+
// hide active server if self-hosting view disabled
162+
html[data-bs-selfhost="no"] {
163+
.icon-tabler-server {
164+
display: none;
165+
}
166+
167+
.icon-tabler-server-off {
168+
display: block;
169+
}
170+
}
171+
150172
@media (hover: hover) {
151173
.highlight .copy button {
152174
opacity: 0;

config/postcss.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module.exports = {
2222
'data-bs-popper',
2323
'data-bs-target',
2424
'data-bs-theme',
25+
'data-bs-selfhost',
2526
'data-dark-mode',
2627
'data-global-alert',
2728
'data-pane', // tabs.js

layouts/partials/header/header.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,24 @@ <h5 class="offcanvas-title fw-bold" id="offcanvasNavMainLabel">{{ .Site.Params.T
272272
</ul>
273273
{{ end -}}
274274

275+
<!-- self-hosting view -->
276+
<button id="selfHosting" class="btn btn-link mx-auto nav-link p-0 ms-lg-2 me-lg-1" type="button" aria-label="Toggle self-hosting view">
277+
<svg data-bs-selfhost-value="yes" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-server-off" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
278+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
279+
<path d="M12 12h-6a3 3 0 0 1 -3 -3v-2c0 -1.083 .574 -2.033 1.435 -2.56m3.565 -.44h10a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-2" />
280+
<path d="M16 12h2a3 3 0 0 1 3 3v2m-1.448 2.568a2.986 2.986 0 0 1 -1.552 .432h-12a3 3 0 0 1 -3 -3v-2a3 3 0 0 1 3 -3h6" />
281+
<path d="M7 8v.01" />
282+
<path d="M7 16v.01" />
283+
<path d="M3 3l18 18" />
284+
</svg>
285+
<svg data-bs-selfhost-value="no" xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-server" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
286+
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
287+
<path d="M3 4m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z" />
288+
<path d="M3 12m0 3a3 3 0 0 1 3 -3h12a3 3 0 0 1 3 3v2a3 3 0 0 1 -3 3h-12a3 3 0 0 1 -3 -3z" />
289+
<path d="M7 8l0 .01" />
290+
<path d="M7 16l0 .01" />
291+
</svg>
292+
</button>
275293

276294
<!-- Navbar button mobile -->
277295
{{ if site.Params.doks.navBarButton -}}

0 commit comments

Comments
 (0)