Skip to content

Commit

Permalink
Dark mode (#16)
Browse files Browse the repository at this point in the history
* dark logo & favicon

* more dark theme

* more dark theme

* finished with dark mode, separated meta and seo stuff into components
  • Loading branch information
Mordechai Dror authored Dec 13, 2023
1 parent ed28a6d commit c9a4bda
Show file tree
Hide file tree
Showing 46 changed files with 681 additions and 313 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ packages/blog/src/content/templates
# Documentation here: https://yarnpkg.com/features/zero-installs
!.yarn/cache
#.pnp.*

**/.DS_Store
16 changes: 10 additions & 6 deletions packages/blog/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ export default defineConfig({
rehypeAutolinkHeadings,
{
behavior: 'append',
content: () =>
h(
'span.fa-solid.fa-link.fa-sm.ml-2.invisible.group-hover:visible',
{ ariaHidden: 'true' },
),
content: () => {
return h('span.ml-2.invisible.text-sm.group-hover:visible', '🔗');
},
properties: {
className: 'no-underline',
},
},
],
[
Expand All @@ -52,7 +53,10 @@ export default defineConfig({
],
],
shikiConfig: {
theme: 'github-light',
experimentalThemes: {
light: 'github-light',
dark: 'github-dark',
},
},
},
});
1 change: 1 addition & 0 deletions packages/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"mdast-util-to-string": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-responsive": "^9.0.2",
"reading-time": "^1.5.0",
"rehype-add-classes": "^1.0.0",
"rehype-autolink-headings": "^7.1.0",
Expand Down
Binary file added packages/blog/public/favicon-dark.ico
Binary file not shown.
Binary file removed packages/blog/src/.DS_Store
Binary file not shown.
Binary file removed packages/blog/src/content/.DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions packages/blog/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />

declare module React {
interface CSSProperties {
[key: `--${string}`]: string | number;
}
}
Binary file removed packages/blog/src/pages/.DS_Store
Binary file not shown.
28 changes: 19 additions & 9 deletions packages/blog/src/pages/about.astro
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
---
import '@fortawesome/fontawesome-free/css/fontawesome.css';
import '@fortawesome/fontawesome-free/css/brands.css';
import Layout from '../shared/components/templates/Layout.astro';
import { Intro } from '../shared/components/organisms/Intro';
import { Link } from '../shared/components/atoms/Link';
import { PROFILE } from '../shared/Profile';
import { Divider } from '../shared/components/atoms/Divider';
import { Icon } from '../shared/components/atoms/Icon';
import { Headline } from '../shared/components/atoms/Headline';
import { Body } from '../shared/components/atoms/Body';
import { THEME } from '../shared/Theme';
---

<Layout title="About">
<Intro />

<Divider>
<h3 class="text-2xl">Stay up to date</h3>
<Headline>Stay up to date</Headline>
</Divider>

<p>
<Body>
If you wish to be up to date with new posts you can
<Link
href="/rss.xml"
target="_blank">
subscribe with RSS
</Link>
</p>
</Body>

<p>There will also be an email newsletter somewhere in the future</p>
<Body>There will also be an email newsletter somewhere in the future</Body>

<Divider>
<h3 class="text-2xl">How to reach me</h3>
<Headline>How to reach me</Headline>
</Divider>

<ul class="grid grid-cols-3 gap-5 mx-auto">
{
PROFILE.socialLinks.map((link) => (
<li>
<a
class="rounded-2xl w-24 h-24 border flex flex-col gap-2 items-center justify-center hover:outline outline-blue-500 hover:text-blue-500 p-2"
class:list={[
'w-24 h-24 p-2',
'flex flex-col gap-2 items-center justify-center',
'border rounded-2xl',
'hover:outline outline-cyan-500 hover:text-cyan-500 hover:border-cyan-500',
THEME.text,
]}
href={link.url}
target="_blank">
<i class={`fa-brands ${link.icon} text-xl`} />
<span class="text-xl">
<Icon glyph={link.glyph} />
</span>
<span class="truncate max-w-full">{link.label}</span>
</a>
</li>
Expand Down
2 changes: 0 additions & 2 deletions packages/blog/src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
import '@fortawesome/fontawesome-free/css/fontawesome.css';
import '@fortawesome/fontawesome-free/css/solid.css';
import { PostsService } from '../shared/PostsService';
import { getCollection } from 'astro:content';
import _ from 'lodash';
Expand Down
21 changes: 19 additions & 2 deletions packages/blog/src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const { Content, remarkPluginFrontmatter } = await post.render();
image={coverImageSrc}
description={description}
type="article">
<article class="prose prose-img:mx-auto">
<article class="prose dark:prose-invert prose-img:mx-auto">
<PostFrontmatter
post={post}
minutesRead={remarkPluginFrontmatter.minutesRead}
Expand All @@ -60,5 +60,22 @@ const { Content, remarkPluginFrontmatter } = await post.render();

{related.length > 0 && <RelatedPosts posts={related} />}

<Comments post={post} />
<Comments
post={post}
client:only="react"
/>
</Layout>

<style is:global>
@media (prefers-color-scheme: dark) {
.astro-code,
.astro-code span {
color: var(--shiki-dark) !important;
background-color: var(--shiki-dark-bg) !important;
/* Optional, if you also want font styles */
font-style: var(--shiki-dark-font-style) !important;
font-weight: var(--shiki-dark-font-weight) !important;
text-decoration: var(--shiki-dark-text-decoration) !important;
}
}
</style>
3 changes: 2 additions & 1 deletion packages/blog/src/pages/posts/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getCollection } from 'astro:content';
import Layout from '../../shared/components/templates/Layout.astro';
import { Divider } from '../../shared/components/atoms/Divider';
import { PostList } from '../../shared/components/organisms/PostList';
import { Headline } from '../../shared/components/atoms/Headline';
const postsByYear = PostsService.groupEntriesByYear(
PostsService.sortEntries(await getCollection('posts')),
Expand All @@ -17,7 +18,7 @@ const years = Object.keys(postsByYear).reverse();
years.map((year) => (
<>
<Divider isLeft={false}>
<span class="text-xl">{year}</span>
<Headline>{year}</Headline>
</Divider>
<PostList
posts={postsByYear[year]}
Expand Down
34 changes: 10 additions & 24 deletions packages/blog/src/shared/Profile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { IconGlyph } from './components/atoms/Icon.tsx';

export class Profile {
constructor(
public readonly baseUrl: string,
Expand All @@ -19,7 +21,7 @@ export class NavLink {

export class SocialLink {
constructor(
public readonly icon: string,
public readonly glyph: IconGlyph,
public readonly label: string,
public readonly url: URL,
) {}
Expand All @@ -31,39 +33,23 @@ export const PROFILE = new Profile(
`Welcome to my digital garden, here I write about all sorts of things (mostly about technologies, a little bit on gaming, traveling and self-reflecting)`,
'vorant94@gmail.com',
'Mordechai Dror © 2021-present',
[
new NavLink('Home', '/'),
new NavLink('About', '/about'),
new NavLink('Posts', '/posts'),
],
[new NavLink('👨‍💻 About', '/about'), new NavLink('📒 Posts', '/posts')],
[
new SocialLink(
'fa-linkedin-in',
'linked-in',
'LinkedIn',
new URL('https://www.linkedin.com/in/vorant94/'),
),
new SocialLink('github', 'Github', new URL('https://github.com/vorant94/')),
new SocialLink('medium', 'Medium', new URL('https://vorant94.medium.com/')),
new SocialLink(
'fa-github',
'Github',
new URL('https://github.com/vorant94/'),
),
new SocialLink(
'fa-medium',
'Medium',
new URL('https://vorant94.medium.com/'),
),
new SocialLink(
'fa-stack-overflow',
'stack-overflow',
'Stack Overflow',
new URL('https://stackoverflow.com/users/4995200/vorant94'),
),
new SocialLink('telegram', 'Telegram', new URL('https://t.me/vorant94/')),
new SocialLink(
'fa-telegram',
'Telegram',
new URL('https://t.me/vorant94/'),
),
new SocialLink(
'fa-x-twitter',
'twitter',
'Twitter / X',
new URL('https://twitter.com/vorant94'),
),
Expand Down
80 changes: 7 additions & 73 deletions packages/blog/src/shared/Theme.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,10 @@
export class Theme {
private static readonly colorToBackground: Record<ThemeColor, string> = {
orange: 'bg-orange-500',
violet: 'bg-violet-500',
red: 'bg-red-500',
amber: 'bg-amber-500',
yellow: 'bg-yellow-500',
lime: 'bg-lime-500',
green: 'bg-green-500',
emerald: 'bg-emerald-500',
teal: 'bg-violet-500',
cyan: 'bg-cyan-500',
blue: 'bg-blue-500',
indigo: 'bg-indigo-500',
purple: 'bg-purple-500',
fushia: 'bg-fushia-500',
pink: 'bg-pink-500',
rose: 'bg-rose-500',
};

private static readonly colorToText: Record<ThemeColor, string> = {
orange: 'text-orange-500',
violet: 'text-violet-500',
red: 'text-red-500',
amber: 'text-amber-500',
yellow: 'text-yellow-500',
lime: 'text-lime-500',
green: 'text-green-500',
emerald: 'text-emerald-500',
teal: 'text-violet-500',
cyan: 'text-cyan-500',
blue: 'text-blue-500',
indigo: 'text-indigo-500',
purple: 'text-purple-500',
fushia: 'text-fushia-500',
pink: 'text-pink-500',
rose: 'text-rose-500',
};

constructor(
public readonly primary: ThemeColor,
public readonly secondary: ThemeColor,
) {}

get backgroundTop(): string {
return Theme.colorToBackground[this.primary];
}

get backgroundBottom(): string {
return Theme.colorToBackground[this.secondary];
}

get text(): string {
return Theme.colorToText[this.primary];
}
readonly background = 'bg-slate-50 dark:bg-slate-900';
readonly text = 'text-slate-800 dark:text-slate-100';
readonly border = 'border-slate-300 dark:border-slate-600';
readonly link = 'text-slate-500 hover:text-cyan-500';
readonly linkDecoration =
' hover:underline underline-offset-4 decoration-4 decoration-dotted decoration-cyan-500';
}

export type ThemeColor =
| 'orange'
| 'violet'
| 'red'
| 'amber'
| 'yellow'
| 'lime'
| 'green'
| 'emerald'
| 'teal'
| 'cyan'
| 'blue'
| 'indigo'
| 'purple'
| 'fushia'
| 'pink'
| 'rose';

export const THEME = new Theme('cyan', 'lime');
export const THEME = new Theme();
58 changes: 58 additions & 0 deletions packages/blog/src/shared/components/atoms/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import classNames from 'classnames';
import type { PropsWithChildren, ReactElement } from 'react';
import { THEME } from '../../Theme.ts';

export function Badge({
hashValue = '',
children,
}: PropsWithChildren<BadgeProps>): ReactElement {
const colors = hashToColor(hashValue);
return (
<span
className={classNames(
THEME.text,
'inline-flex items-center rounded-full text-xs px-2.5 py-0.5 font-semibold',
...colors,
)}>
{children}
</span>
);
}

export interface BadgeProps {
hashValue?: string;
}

function hashToColor(value: string): readonly [string, string] {
const hash = value
.split('')
.map((char) => char.charCodeAt(0))
.reduce((prev, curr) => prev + curr, 0);

return COLORS[hash % COLORS.length];
}

const COLORS = [
['bg-slate-100', 'dark:bg-slate-800'],
['bg-gray-100', 'dark:bg-gray-800'],
['bg-zinc-100', 'dark:bg-zinc-800'],
['bg-neutral-100', 'dark:bg-neutral-800'],
['bg-stone-100', 'dark:bg-stone-800'],
['bg-red-100', 'dark:bg-red-800'],
['bg-orange-100', 'dark:bg-orange-800'],
['bg-amber-100', 'dark:bg-amber-800'],
['bg-yellow-100', 'dark:bg-yellow-800'],
['bg-lime-100', 'dark:bg-lime-800'],
['bg-green-100', 'dark:bg-green-800'],
['bg-emerald-100', 'dark:bg-emerald-800'],
['bg-teal-100', 'dark:bg-teal-800'],
['bg-cyan-100', 'dark:bg-cyan-800'],
['bg-sky-100', 'dark:bg-sky-800'],
['bg-blue-100', 'dark:bg-blue-800'],
['bg-indigo-100', 'dark:bg-indigo-800'],
['bg-violet-100', 'dark:bg-violet-800'],
['bg-purple-100', 'dark:bg-purple-800'],
['bg-fuchsia-100', 'dark:bg-fuchsia-800'],
['bg-pink-100', 'dark:bg-pink-800'],
['bg-rose-100', 'dark:bg-rose-800'],
] as const;
Loading

0 comments on commit c9a4bda

Please sign in to comment.