Skip to content

Commit e441951

Browse files
committed
✨ Add CSS customiser experiment
1 parent 5bb6133 commit e441951

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

src/_data/site.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ export default function () {
7878
},
7979
],
8080
legalLinks: [
81-
{ href: "/brand/", text: "beeps' brand" },
82-
{ href: "/colophon/", text: "Colophon" },
83-
{ href: "/accessibility/", text: "Accessibility statement" },
84-
{ href: "/privacy/", text: "Cookies and privacy" },
8581
{
8682
href: "/feed.xml",
8783
text: "RSS feed",
@@ -91,6 +87,11 @@ export default function () {
9187
type: "application/atom+xml",
9288
},
9389
},
90+
{ href: "/brand/", text: "beeps' brand" },
91+
{ href: "/colophon/", text: "Colophon" },
92+
{ href: "/accessibility/", text: "Accessibility statement" },
93+
{ href: "/privacy/", text: "Cookies and privacy" },
94+
{ href: "/customise/", text: "Customise CSS" },
9495
],
9596
};
9697
}

src/_layouts/layout.njk

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@
5050
</head>
5151
<body class="kimPage_body">
5252

53+
{# Custom CSS element #}
54+
<script>
55+
let $cssElement = document.getElementById("customCSS");
56+
if (!$cssElement) {
57+
$cssElement = document.createElement("style");
58+
$cssElement.id = "customCSS";
59+
document.head.insertAdjacentElement("beforeend", $cssElement);
60+
}
61+
window.$cssElement = $cssElement;
62+
63+
if (localStorage.getItem("customCSS")) {
64+
window.$cssElement.innerText = localStorage.getItem("customCSS");
65+
}
66+
</script>
67+
5368
{% include "src/_includes/development-tag.njk" %}
5469

5570
{% block beforeMasthead %}
@@ -134,7 +149,7 @@
134149
{{- link.html | safe if link.html else link.text -}}
135150
</a>
136151
</li>
137-
{%- endfor%}
152+
{%- endfor %}
138153
</ul>
139154
</div>
140155

src/customise.njk

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
title: Customise this site
3+
metadata:
4+
description: Write your own CSS to customise how this site looks.
5+
---
6+
7+
{% extends 'src/_layouts/layout.njk' %}
8+
9+
{% block main %}
10+
<div class="kim-!-margin-block-8-9">
11+
<div class="kimWrapper">
12+
<h1 class="kimHeading-xl">
13+
{{ title }}
14+
</h1>
15+
<div class="kimGrid">
16+
<div class="kimGrid_column kimGrid_column-full defiant:kimGrid_column-oneThird">
17+
<p class="kimBody-l">Write your own CSS to customise how this site looks.</p>
18+
<p class="kimBody">This code is stored on your device and is never sent to the server. JavaScript must be available for it to work.</p>
19+
<p class="kimBody">This is here as an experiment. I might get rid of it again at some point. 🤷</p>
20+
</div>
21+
<div class="kimGrid_column kimGrid_column-full defiant:kimGrid_column-twoThirds">
22+
<label for="css" class="kim-!-visually-hidden">Write some CSS</label>
23+
<textarea class="pageCodeEditor" id="css" rows="30" cols="80" disabled>
24+
.kimPage {
25+
/** Force light or dark mode by uncommenting one of these. */
26+
/* color-scheme: light; */
27+
/* color-scheme: dark; */
28+
29+
/** Change body font by uncommenting and editing this. */
30+
/* --font-body: system-ui, sans-serif; */
31+
}</textarea>
32+
</div>
33+
</div>
34+
</div>
35+
{% endblock %}
36+
37+
{% css %}
38+
.pageCodeEditor {
39+
inline-size: 100%;
40+
margin-block-end: var(--space-5);
41+
padding: var(--space-3);
42+
border: var(--border-regular) solid var(--color-furniture);
43+
color: var(--color-text);
44+
background-color: var(--color-surface);
45+
font-family: var(--font-code);
46+
font-size: var(--size--1);
47+
resize: vertical;
48+
tab-size: 4;
49+
}
50+
.pageCodeEditor:focus-visible {
51+
outline: 3px solid var(--color-focus-text);
52+
box-shadow: 0 0 0 5px var(--color-focus-background);
53+
}
54+
{% endcss %}
55+
56+
{% block scripts %}
57+
{{ super() }}
58+
<script>
59+
const $cssEditor = document.getElementById("css");
60+
$cssEditor.disabled = false;
61+
62+
$cssEditor.addEventListener("input", function() {
63+
localStorage.setItem("customCSS", $cssEditor.value);
64+
window.$cssElement.innerText = $cssEditor.value;
65+
})
66+
67+
if(localStorage.getItem("customCSS")) {
68+
$cssEditor.value = localStorage.getItem("customCSS");
69+
}
70+
</script>
71+
{% endblock %}

0 commit comments

Comments
 (0)