Skip to content
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
50 changes: 29 additions & 21 deletions _includes/giscus.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
{% if site.giscus and site.giscus.repo %}
<div class="giscus-comments">
<script
src="https://giscus.app/client.js"
data-repo="{{ site.giscus.repo }}"
data-repo-id="{{ site.giscus.repo-id }}"
data-category="{{ site.giscus.category }}"
data-category-id="{{ site.giscus.category-id }}"
data-mapping="{{ site.giscus.mapping }}"
data-strict="0"
data-reactions-enabled="{{ site.giscus.reactions-enabled }}"
data-emit-metadata="{{ site.giscus.emit-metadata }}"
data-input-position="{{ site.giscus.input-position }}"
data-theme="dark"
data-lang="{{ site.giscus.lang }}"
crossorigin="anonymous"
async>
<script>
// Get the current theme from localStorage or default to dark
const currentTheme = localStorage.getItem('theme') || 'dark';

// Create the Giscus script with the correct initial theme
const giscusScript = document.createElement('script');
giscusScript.src = 'https://giscus.app/client.js';
giscusScript.setAttribute('data-repo', '{{ site.giscus.repo }}');
giscusScript.setAttribute('data-repo-id', '{{ site.giscus.repo-id }}');
giscusScript.setAttribute('data-category', '{{ site.giscus.category }}');
giscusScript.setAttribute('data-category-id', '{{ site.giscus.category-id }}');
giscusScript.setAttribute('data-mapping', '{{ site.giscus.mapping }}');
giscusScript.setAttribute('data-strict', '0');
giscusScript.setAttribute('data-reactions-enabled', '{{ site.giscus.reactions-enabled }}');
giscusScript.setAttribute('data-emit-metadata', '{{ site.giscus.emit-metadata }}');
giscusScript.setAttribute('data-input-position', '{{ site.giscus.input-position }}');
giscusScript.setAttribute('data-theme', currentTheme);
giscusScript.setAttribute('data-lang', '{{ site.giscus.lang }}');
giscusScript.setAttribute('crossorigin', 'anonymous');
giscusScript.async = true;

// Append the script to load Giscus with the correct theme
document.currentScript.parentNode.insertBefore(giscusScript, document.currentScript);
</script>
</div>

<script>
// Function to update Giscus theme based on Jekyll theme
function updateGiscusTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const currentTheme = document.documentElement.getAttribute('data-theme') || localStorage.getItem('theme') || 'dark';
const giscusFrame = document.querySelector('iframe.giscus-frame');

if (giscusFrame) {
Expand All @@ -39,16 +47,16 @@

// Set initial theme when Giscus loads
document.addEventListener('DOMContentLoaded', function() {
// Wait for Giscus to load, then set initial theme
setTimeout(updateGiscusTheme, 1000);

// Also try updating theme when iframe loads
// Check multiple times to catch when Giscus iframe loads
const checkForGiscus = setInterval(() => {
if (document.querySelector('iframe.giscus-frame')) {
updateGiscusTheme();
clearInterval(checkForGiscus);
}
}, 500);
}, 100);

// Stop checking after 10 seconds
setTimeout(() => clearInterval(checkForGiscus), 10000);
});

// Watch for theme changes on the document element
Expand Down
56 changes: 13 additions & 43 deletions _includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,6 @@
{% endfor %}
</span>

<!-- Theme Toggle -->
<div class="toggleWrapper">
<input type="checkbox" class="dn" id="theme-toggle" onclick="modeSwitcher()" checked />
<label for="theme-toggle" class="toggle">
<span class="toggle__handler">
<span class="crater crater--1"></span>
<span class="crater crater--2"></span>
<span class="crater crater--3"></span>
</span>
<span class="star star--1"></span>
<span class="star star--2"></span>
<span class="star star--3"></span>
<span class="star star--4"></span>
<span class="star star--5"></span>
<span class="star star--6"></span>
</label>
</div>

<br style="clear: both;">
<div style="margin-top: 0.5em; padding-top: 0.75em;">
<a href="/about/" style="display: inline-block; margin-right: 2em; color: #de5684; text-decoration: none; font-size: 1em;">About</a>
Expand All @@ -39,49 +21,37 @@
</div>

<script type="text/javascript">
const theme = localStorage.getItem('theme');

if (theme === "light") {
document.documentElement.setAttribute('data-theme', 'light');
} else {
document.documentElement.setAttribute('data-theme', 'dark');
}
const userPrefers = getComputedStyle(document.documentElement).getPropertyValue('content');
// Get theme from localStorage, default to dark if not set
const theme = localStorage.getItem('theme') || 'dark';

function activateDarkTheme() {
document.getElementById('theme-toggle').checked = true;
document.documentElement.setAttribute('data-theme', 'dark');
document.documentElement.classList.add('theme--dark');
document.documentElement.classList.remove('theme--light');
document.getElementById("theme-toggle").className = 'light';
window.localStorage.setItem('theme', 'dark');
window.localStorage.setItem('theme', 'dark');
}

function activateLightTheme() {
document.getElementById('theme-toggle').checked = false;
document.documentElement.setAttribute('data-theme', 'light');
document.documentElement.classList.add('theme--light');
document.documentElement.classList.remove('theme--dark');
document.getElementById("theme-toggle").className = 'dark';
window.localStorage.setItem('theme', 'light');
window.localStorage.setItem('theme', 'light');
}

if (theme === "dark") {
activateDarkTheme();
} else if (theme === "light") {
// Apply theme immediately to prevent flash
if (theme === "light") {
activateLightTheme();
} else if (userPrefers === "light") {
activateDarkTheme();
} else {
// Default to dark theme
activateDarkTheme();
}

function modeSwitcher() {
let currentMode = document.documentElement.getAttribute('data-theme');
if (currentMode === "dark") {
activateLightTheme();
} else {
activateDarkTheme();
}
let currentMode = document.documentElement.getAttribute('data-theme');
if (currentMode === "dark") {
activateLightTheme();
} else {
activateDarkTheme();
}
}
</script>