Skip to content
Open
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
14 changes: 14 additions & 0 deletions web/src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ const jsonLd = structuredData ? JSON.stringify(structuredData).replace(/</g, '\\
<meta name="twitter:image:alt" content={imageAlt} />
<title>{title}</title>
{structuredData && <script type="application/ld+json" set:html={jsonLd} />}
<script is:inline>
const theme = (() => {
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
return localStorage.getItem('theme');
}
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
return 'dark';
}
return 'light';
})();
if (theme === 'dark') {
document.documentElement.classList.add('dark');
}
</script>
</head>
<body>
<slot />
Expand Down
24 changes: 24 additions & 0 deletions web/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ const structuredData = createHomeStructuredData();
</svg>
<span>GitHub</span>
</a>
<button id="theme-toggle" class="theme-toggle" aria-label="Cambiar tema">
<svg class="sun-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="4"></circle>
<path d="M12 2v2"></path>
<path d="M12 20v2"></path>
<path d="M5.4 5.4l1.4 1.4"></path>
<path d="M17.2 17.2l1.4 1.4"></path>
<path d="M2 12h2"></path>
<path d="M20 12h2"></path>
<path d="M5.4 18.6l1.4 -1.4"></path>
<path d="M17.2 6.8l1.4 -1.4"></path>
</svg>
<svg class="moon-icon" xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round">
<path d="M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z"></path>
</svg>
</button>
<a class="header-cta" href={`${sourceRepository.href}/issues/new?title=Nuevo+libro+gratuito&body=%23%23+Datos+del+libro%0A%0A-+**T%C3%ADtulo**%3A+%0A-+**Autor**%3A+%0A-+**Enlace**%3A+%0A-+**Idioma**%3A+Espa%C3%B1ol%0A-+**Categor%C3%ADa**%3A+%0A-+**Formato**%3A+%28PDF%2C+HTML%2C+ePub...%29%0A`} target="_blank" rel={externalLinkRel}>
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M5 19.5v-14a2.5 2.5 0 0 1 2.5 -2.5h10.5v18h-10.5a2.5 2.5 0 0 1 0 -5h10.5" />
Expand Down Expand Up @@ -395,6 +411,14 @@ const structuredData = createHomeStructuredData();
});
});

const themeToggle = document.getElementById('theme-toggle');
themeToggle?.addEventListener('click', () => {
const element = document.documentElement;
element.classList.toggle('dark');
const isDark = element.classList.contains('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
});

applyFilters();
</script>
</Layout>
Loading