Skip to content

Commit 01bf197

Browse files
committed
all alone on christmas
1 parent dac9d59 commit 01bf197

File tree

107 files changed

+568
-225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+568
-225
lines changed

content/_data/changelog.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[
22
{ "date": "2026-01-XX", "text": "TEMPLATE", "link": "" },
3+
4+
{ "date": "2025-12-18", "text": "Updated/improved the code of the layout base code in the 'How to load the same layout on every page' tutorial.", "link": "/coding/layout-base-code" },
35
{ "date": "2025-12-16", "text": "Changed relationship status to taken! :3 + other small changes and extended indie web contest deadline!", "link": "/contest" },
46
{ "date": "2025-12-07", "text": "Please consider donating to my ko-fi to help me finance raising a stray cat's kittens! Thank you!", "link": "https://ko-fi.com/petrastipjar/goal?g=0" },
57
{ "date": "2025-11-30", "text": "Advent calendar of digital challenges has been filled! Check it out tomorrow!", "link": "/fun/advent-calendar-2025" },

content/_data/sites.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@
172172
"neighbor": true
173173
},
174174
{
175-
"link": "https://metmoxie.com/",
176-
"title": "metmoxie",
175+
"link": "https://moxiemoshpit.com/",
176+
"title": "Moxie Moshpit",
177177
"image": "metmoxie.webp",
178178
"neighbor": true
179179
},

content/_includes/email.njk

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
<span class="email-svg">
2-
<svg xmlns="http://www.w3.org/2000/svg" lang="en-GB" aria-labelledby="title" viewBox="0 0 160 24">
3-
<title id="title">Email Me!</title>
4-
<a href="mailto:petracoding@outlook.com" aria-label="Email Me!">
5-
<text x="50%" y="50%" text-anchor="middle" dominant-baseline="middle">petracoding@outlook.com</text>
6-
</a>
7-
</svg>
2+
<img src="{{ nesting }}assets/img/email.svg" alt="my email address" />
83
</span>

content/coding/base-code-example/index.html

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,30 @@
88
<script src="layout.js"></script>
99
<link href="../../favicon.ico" rel="icon" type="image/x-icon" />
1010
<style>
11+
body {
12+
margin: 5px;
13+
background: white;
14+
}
15+
1116
header,
1217
footer {
18+
padding: 1.75em 3em;
1319
background: lightgray;
1420
}
1521

22+
nav {
23+
margin-top: 0.5em;
24+
}
25+
26+
nav a {
27+
display: inline-block;
28+
margin-right: 0.5em;
29+
}
30+
1631
main {
17-
margin: 3em 0;
32+
margin: 10px 0;
33+
padding: 3em;
34+
border: 1px dashed gray;
1835
}
1936

2037
a {
@@ -28,10 +45,8 @@
2845
</head>
2946
<body class="load-layout">
3047
<main>
31-
<p>This is the page content.</p>
32-
<br />
33-
<p>The image in the footer was inserted using the following code:</p>
34-
<code>&lt;img src="${nesting}/assets/img/layout/divider1.gif" alt="" aria-hidden="true"/&gt;</code>
48+
This is the page content, and the only element in the HTML file! The header and footer are both added via JavaScript, which means that the HTML code for them is in a singular JavaScript file
49+
instead of every HTML file.
3550
</main>
3651
</body>
3752
</html>

content/coding/base-code-example/layout.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@ document.addEventListener("DOMContentLoaded", function () {
77
document.body.insertAdjacentHTML("afterbegin", headerEl);
88
document.body.insertAdjacentHTML("beforeend", footerEl);
99

10+
// To insert something inside another element:
11+
const wrapperElement = document.querySelector(".my-wrapper"); // <- your selector here
12+
if (wrapperElement) wrapperElement.insertAdjacentHTML("afterbegin", `<b>Element at beginning of wrapper element.</b>`);
13+
if (wrapperElement) wrapperElement.insertAdjacentHTML("beforeend", `<b>Element at the end of wrapper element.</b>`);
14+
1015
// Other initializations:
1116
initActiveLinks();
1217

13-
// your code here...
18+
// your javascript code here...
1419
});
1520

1621
/* ********************************* */
@@ -70,10 +75,12 @@ const nesting = getNestingString();
7075
// You don't need to use the <header> element, but I recommend it.
7176
const headerEl = `
7277
<header>
73-
Header...
78+
Header. Example of how to use the 'active' class to style active links (here: bold):
7479
<nav>
75-
<a href="/coding/layout-base-code.html">some link</a>
76-
<a href="/coding/base-code-example/index.html">active link</a>
80+
<a href="/coding/layout-base-code">homepage</a>
81+
<a href="/coding/base-code-example/">this page</a>
82+
<a href="/coding/layout-base-code">other page</a>
83+
<a href="/coding/layout-base-code">other page</a>
7784
</nav>
7885
</header>
7986
`;
@@ -82,7 +89,7 @@ const headerEl = `
8289
// You don't need to use the <footer> element, but I recommend it.
8390
const footerEl = `
8491
<footer>
85-
Footer...
92+
Footer. Example of how to add an image:
8693
<img src="${nesting}/assets/img/layout/divider1.gif" alt="" aria-hidden="true"/>
8794
</footer>
8895
`;

content/coding/layout-base-code.html

Lines changed: 120 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,33 +17,49 @@ <h1>Layout Base Code</h1>
1717
Tired of <a href="/coding/common-questions.html#layout">having to update all of you HTML files every time you update your layout</a>? Here's an easy solution. We'll be using JavaScript to load a
1818
header and footer on every page. We'll also take care of active links and relative paths.
1919
</p>
20-
<div class="cw">Keep in mind that users who have deactivated JavaScript in their browser will not be able to navigate your site.</div>
2120

21+
<blockquote class="warning">Keep in mind that users who have deactivated JavaScript in their browser will not be able to navigate your site!</blockquote>
2222
<!--
23+
2324
<blockquote class="contact">
2425
<p>
2526
If you have questions or feedback regarding the tutorial, please use the <a href="#comments">comment section</a> at the end of the page! Don't be shy; I know it's frustrating when you're stuck,
2627
and I'd love to help.
2728
</p>
2829
</blockquote>
29-
-->
30+
3031
3132
<blockquote class="warning">
3233
<p>Please note that due to the nested HTML generated by <b>sadgrl's layout maker</b> you can't use the code on this page as-is if you're using a layout generated with her layout maker!</p>
3334
</blockquote>
34-
35+
-->
3536
<blockquote class="tip">
36-
Alternatively, you could also use a static site generator such as Eleventy (11ty). See <a href="/coding/eleventy-tutorial">my tutorial here</a>. It's more difficult to set up but the result is
37-
better!
37+
Alternatively to this you could also use a static site generator such as Eleventy (11ty). See <a href="/coding/eleventy-tutorial">my tutorial here</a>. It's much more difficult to set up but the
38+
result is better, and works for those who have deactivated JavaScript too!
3839
</blockquote>
3940

40-
<div id="toc">
41+
<div id="toc" data-two-levels="true">
4142
<b>Table of Contents:</b>
42-
<ol>
43-
<li><a href="#what-it-will-do">What it will do</a></li>
44-
<li><a href="#tutorial">Tutorial</a></li>
45-
<li><a href="#comments">Comments</a></li>
46-
</ol>
43+
<ul>
44+
<li>
45+
<a href="#what-it-will-do">What it will do</a>
46+
<ul></ul>
47+
</li>
48+
<li>
49+
<a href="#tutorial">Tutorial</a>
50+
<ol>
51+
<li><a href="#the-script">The Script</a></li>
52+
<li><a href="#loading-the-script">Loading the script</a></li>
53+
<li><a href="#insert-your-layout-code-in-the-javascript">Insert your layout code in the JavaScript</a></li>
54+
<li><a href="#prepare-your-pages">Prepare your pages</a></li>
55+
<li><a href="#style">Style</a></li>
56+
</ol>
57+
</li>
58+
<li>
59+
<a href="#comments">Comments</a>
60+
<ul></ul>
61+
</li>
62+
</ul>
4763
</div>
4864

4965
<!-- ----------------------------------------------------------------------------------------------------- -->
@@ -53,21 +69,61 @@ <h1>Layout Base Code</h1>
5369
<section>
5470
<h2>What it will do</h2>
5571
<p>Your header and footer HTML will be in a single JavaScript file, so you'll only need to update it once.</p>
56-
<p>HTML in your .html file:</p>
57-
<pre><code>&lt;body&gt;
72+
<hr />
73+
74+
<div class="two-columns">
75+
<div>
76+
<p><b>HTML in your .html file:</b></p>
77+
<pre><code>&lt;body&gt;
5878
&lt;main&gt;
5979
your page here...
6080
&lt;/main&gt;
6181
&lt;/body&gt;</code></pre>
62-
<p>HTML rendered in the browser (the script automatically adds the header and footer):</p>
63-
<pre><code>&lt;body&gt;
64-
&lt;header&gt;...&lt;/header&gt;
82+
<p>(The header and footer code are not in the HTML files.)</p>
83+
</div>
84+
<div>
85+
<p><b>HTML rendered in the browser:</b></p>
86+
<pre><code>&lt;body&gt;
87+
&lt;header&gt;example...&lt;/header&gt;
6588
&lt;main&gt;
6689
your page here...
6790
&lt;/main&gt;
68-
&lt;footer&gt;...&lt;/footer&gt;
91+
&lt;footer&gt;example...&lt;/footer&gt;
6992
&lt;/body&gt;</code></pre>
70-
<p>You can see the code in action <a href="/coding/base-code-example/index.html" target="_blank">here</a>.</p>
93+
<p>(The script automatically adds the header and footer.)</p>
94+
</div>
95+
</div>
96+
97+
<hr />
98+
<p>You can see the code in action here (this is an iFrame of the <a href="/coding/base-code-example" target="_blank">example page</a>):</p>
99+
<iframe src="/coding/base-code-example" style="width: 100%; border: 1px solid currentColor; min-height: 342px" frameborder="0"></iframe>
100+
101+
<hr />
102+
103+
<p>You can even add elements inside of your wrapper element which contains your content, e.g. for a sidebar:</p>
104+
<div class="two-columns">
105+
<div>
106+
<p><b>HTML in your .html file:</b></p>
107+
<pre><code>&lt;body&gt;
108+
&lt;main&gt;
109+
&lt;p&gt;your page here...&lt;/p&gt;
110+
&lt;/main&gt;
111+
&lt;/body&gt;</code></pre>
112+
<p>(The code for the other elements is in the JavaScript file as well.)</p>
113+
</div>
114+
<div>
115+
<p><b>HTML rendered in the browser:</b></p>
116+
<pre><code>&lt;body&gt;
117+
&lt;header&gt;example&lt;/header&gt;
118+
&lt;main&gt;
119+
&lt;div&gt;your sidebar here...&lt;/div&gt;
120+
&lt;p&gt;your page here...&lt;/p&gt;
121+
&lt;div&gt;your sidebar here...&lt;/div&gt;
122+
&lt;/main&gt;
123+
&lt;footer&gt;example&lt;/footer&gt;
124+
&lt;/body&gt;</code></pre>
125+
</div>
126+
</div>
71127

72128
<!-- ----------------------------------------------------------------------------------------------------- -->
73129
<!-- ----------------------------------------------------------------------------------------------------- -->
@@ -82,11 +138,15 @@ <h3 data-step="1">The Script</h3>
82138
<label style="display: block; text-align: right"><input type="checkbox" id="explanation-toggle" checked="true" /> Show explanatory comments</label>
83139

84140
<pre id="hide-explanation" style="display: none">
85-
<code>
86-
document.addEventListener("DOMContentLoaded", function () {
141+
<code>document.addEventListener("DOMContentLoaded", function () {
87142
if (document.body.classList.contains("no-layout")) return;
88143
document.body.insertAdjacentHTML("afterbegin", headerEl);
89144
document.body.insertAdjacentHTML("beforeend", footerEl);
145+
146+
const wrapperEl = document.querySelector(".my-wrapper");
147+
if (wrapperEl) wrapperEl.insertAdjacentHTML("afterbegin", `&lt;b&gt;Element at beginning of wrapper element.&lt;/b&gt;`);
148+
if (wrapperEl) wrapperEl.insertAdjacentHTML("beforeend", `&lt;b&gt;Element at the end of wrapper element.&lt;/b&gt;`);
149+
90150
initActiveLinks();
91151
});
92152

@@ -113,6 +173,8 @@ <h3 data-step="1">The Script</h3>
113173

114174
const nesting = getNestingString();
115175

176+
// How to use the nesting variable: &lt;img src="${nesting}/images/example.jpg" /&gt;
177+
116178
const headerEl = `
117179
&lt;header&gt;Header...&lt;/header&gt;
118180
&lt;aside&gt;Sidebar...&lt;/aside&gt;
@@ -124,7 +186,7 @@ <h3 data-step="1">The Script</h3>
124186
<!-- ---------------------------------------------- -->
125187
<!-- ---------------------------------------------- -->
126188
<pre id="show-explanation">
127-
<code>// initLayout() is called once the DOM (the HTML content of your website) has been loaded.
189+
<code>// Everything in here is executed once the DOM (the HTML content of your website) has finished loading.
128190
document.addEventListener("DOMContentLoaded", function () {
129191
// The layout will be loaded on all pages that do NOT have the "no-layout" class in the &lt;body&gt; element.
130192
if (document.body.classList.contains("no-layout")) return;
@@ -133,10 +195,15 @@ <h3 data-step="1">The Script</h3>
133195
document.body.insertAdjacentHTML("afterbegin", headerEl);
134196
document.body.insertAdjacentHTML("beforeend", footerEl);
135197

136-
// Other initializations:
198+
// To insert something inside another element, e.g. for sidebars:
199+
const wrapperEl = document.querySelector(".my-wrapper"); // &lt;- your selector here
200+
if (wrapperEl) wrapperEl.insertAdjacentHTML("afterbegin", `&lt;b&gt;Element at beginning of wrapper element.&lt;/b&gt;`);
201+
if (wrapperEl) wrapperEl.insertAdjacentHTML("beforeend", `&lt;b&gt;Element at the end of wrapper element.&lt;/b&gt;`);
202+
203+
// Give class 'active' to links to the current page:
137204
initActiveLinks();
138205

139-
// your code here...
206+
// add your own JavaScript code here...
140207
});
141208

142209
/* ********************************* */
@@ -186,7 +253,7 @@ <h3 data-step="1">The Script</h3>
186253
Example:
187254
&lt;img src="${nesting}/images/example.jpg" /&gt;
188255
will output
189-
&lt;img src="./images/example.jpg" /&gt; on a page that isn't in any folder.
256+
&lt;img src="./images/example.jpg" /&gt; on a page that isn't in any folder.
190257
&lt;img src="../images/example.jpg" /&gt; on a page that is in a folder.
191258
&lt;img src="../../images/example.jpg" /&gt; on a page that is in a sub-folder.
192259
etc.
@@ -208,28 +275,34 @@ <h3 data-step="1">The Script</h3>
208275
<!-- ----------------------------------------------------------------------------------------------------- -->
209276

210277
<h3 data-step="2">Loading the script</h3>
211-
<p><strong>Step 2: Load the JS</strong></p>
212278
<p>Load that javascript file on every page.</p>
213-
<details>
214-
<summary>Show me how</summary>
215279

216-
<ul>
217-
<li>For your index file, or any other page that is not in a folder: <code>&lt;script src="layout.js"&gt;&lt;/script&gt;</code></li>
218-
<li>For any file that is in a folder: <code>&lt;script src="../layout.js"&gt;&lt;/script&gt;</code></li>
219-
<li>For files that are in a subfolder use <code>../../layout.js</code> , and so on. (add another ../ for every subfolder)</li>
220-
</ul>
221-
<p>This line should be inserted into the head of your HTML file (before &lt;/head&gt;).</p>
222-
</details>
280+
<ul>
281+
<li>For your index file, or any other page that is not in a folder: <code>&lt;script src="layout.js"&gt;&lt;/script&gt;</code></li>
282+
<li>For any file that is in a folder: <code>&lt;script src="../layout.js"&gt;&lt;/script&gt;</code></li>
283+
<li>For files that are in a subfolder use <code>&lt;script src="../../layout.js"&gt;&lt;/script&gt;</code> , and so on. (add another ../ for every subfolder)</li>
284+
</ul>
285+
<p>(This line should be inserted into the head of your HTML file (= inbetween &lt;head&gt; and &lt;/head&gt;).)</p>
223286

224287
<!-- ----------------------------------------------------------------------------------------------------- -->
225288

226-
<h3 data-step="3">Insert your header/footer</h3>
227-
<p>Paste your header and footer inbetween the ticks (``) of the variables headerEl and footerEl.</p>
228-
<blockquote class="tip">
229-
<p>If you have a <b>sidebar</b>, either include it inside of your header element, or add it after the header element (but still in the headerEl JavaScript variable) (see code).</p>
230-
</blockquote>
231-
<p>Use <code>${nesting}</code> to output a . or .. or ../.. etc according to the current page's folder depth. This is helpful when you want to use relative paths to images.</p>
232-
<p>Example:</p>
289+
<h3 data-step="3">Insert your layout code in the JavaScript</h3>
290+
<p>In the javascript file, paste your header and footer inbetween the ticks (``) of the variables <i>headerEl</i> and <i>footerEl</i>.</p>
291+
292+
<h4>Sidebars</h4>
293+
294+
<p>If you have a <b>sidebar</b>, you have three options. Choose the best depending on how your original layout was structured:</p>
295+
<ul>
296+
<li>Include it inside of your header element</li>
297+
<li>or: Add it after the header element (but still in the <i>headerEl</i> variable) like shown in the code above.</li>
298+
<li>or: Use the <i>wrapperEl</i> variable (make sure to adjust the CSS selector!) to get your element in the HTML file and add additional elements inside it.</li>
299+
</ul>
300+
301+
<h4>Images</h4>
302+
<p>
303+
Use <code>${nesting}</code> to output <code>.</code> or <code>..</code> or <code>../..</code> etc according to the current page's folder depth. This is helpful when you want to use relative paths
304+
to images. For Example:
305+
</p>
233306
<pre><code>const headerEl = `&lt;img src="${nesting}/images/example.jpg" /&gt;`;</code></pre>
234307
<p>... will output:</p>
235308
<ul>
@@ -252,21 +325,21 @@ <h3 data-step="4">Prepare your pages</h3>
252325
&lt;/main&gt;
253326
&lt;/body&gt;</code></pre>
254327

328+
<p>If you have page on which your layout should not be loaded, give the <code>&lt;body&gt;</code> element the "no-layout" class.</p>
329+
255330
<!-- ----------------------------------------------------------------------------------------------------- -->
256331

257332
<h3 data-step="5">Style</h3>
258-
<p>Now, style your layout with CSS like you would normally do.</p>
333+
<p>You don't need to make any changes in the CSS.</p>
259334
<p>
260-
My code adds the class "active" to any links that are linked to the current page. This makes it easy to style active menu links. Just make a CSS rule that checks for the "active" class,
261-
<br />e.g. <code>.active { font-weight:bold; }</code>
335+
<b>Tip: </b>My code adds the class "active" to any links that are linked to the current page. This makes it easy to style active menu links. Just make a CSS rule that checks for the "active"
336+
class, e.g. <code>.active { font-weight:bold; }</code>
262337
</p>
263338

264339
<!-- ----------------------------------------------------------------------------------------------------- -->
265340
<br />
266-
<br />
267341
<blockquote class="success">
268-
<p><strong>Done!</strong></p>
269-
<p>If you have page on which your layout should not be loaded, give the <code>&lt;body&gt;</code> element the "no-layout" class.</p>
342+
<p><strong>And that's it!</strong></p>
270343
</blockquote>
271344
</section>
272345

0 commit comments

Comments
 (0)