feat: added 404 page

This commit is contained in:
Sergey Yarkov 2022-07-31 18:31:55 +03:00
parent 51d628d810
commit d0882b41ea
5 changed files with 29 additions and 14 deletions

1
public/assets/js/detect-theme.min.js vendored Normal file
View File

@ -0,0 +1 @@
window.theme=(()=>{const e=localStorage.getItem("theme");if(e&&("dark"===e||"light"===e))return e;const t=window.matchMedia("(prefers-color-scheme: dark)").matches;return t?"dark":"light"})(),document.documentElement.setAttribute("data-theme",window.theme),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",({matches:e})=>{window.theme=e?"dark":"light",localStorage.setItem("theme",window.theme),document.documentElement.setAttribute("data-theme",window.theme)});

View File

@ -21,5 +21,5 @@
</title>
<meta name='title' content={title} />
<meta name='description' content={description || SITE_METADATA.description} />
<script is:inline src='assets/js/detect-theme.js' />
<script is:inline src='assets/js/detect-theme.min.js' />
<slot></slot>

View File

@ -1,12 +1,13 @@
---
import './Header.scss';
import { SITE_METADATA } from '@root/config';
import ThemeSwitcher from '@components/ThemeSwticher';
import { Icon } from 'astro-icon';
import NavToggle from './NavToggle';
import './Header.scss';
import { SITE_METADATA } from '@root/config';
import ThemeSwitcher from '@components/ThemeSwticher';
import { Icon } from 'astro-icon';
import { removeSlashes } from '@utils/string'
import NavToggle from './NavToggle';
const { name, nav, contacts } = SITE_METADATA;
const { pathname } = Astro.canonicalURL;
const { name, nav, contacts } = SITE_METADATA;
const { pathname } = Astro.canonicalURL;
---
<header class='header'>
@ -18,7 +19,7 @@ const { pathname } = Astro.canonicalURL;
<ul class='header__nav-links'>
{nav.map((link) => (
<li>
<a class={pathname.includes(link.url) && 'active'} href={link.url}>
<a class={removeSlashes(pathname)===removeSlashes(link.url) && 'active' } href={link.url}>
{link.name}
</a>
</li>

10
src/pages/404.astro Normal file
View File

@ -0,0 +1,10 @@
---
import PageLayout from '@layouts/default.astro'
---
<PageLayout title="404" showPageHeading={false}>
<div class="container">
<h1 style="font-size:var(--font-size-5xl);">404</h1>
<p>Страницу которую вы пытаетесь найти не существует.</p>
</div>
</PageLayout>

3
src/utils/string.ts Normal file
View File

@ -0,0 +1,3 @@
export function removeSlashes(string: string): string {
return string.replaceAll('/', '');
}