Skip to content

Commit

Permalink
feat(app): Major UI refactor & new additions
Browse files Browse the repository at this point in the history
Added RSS feed, Added theme toggle, Added Preact component; Optimized CSS; Added Mobile Nav; New Tags pages; and more...

Closes #2
  • Loading branch information
djsiddz committed Feb 23, 2024
1 parent 9dc7ab6 commit ce89861
Show file tree
Hide file tree
Showing 16 changed files with 663 additions and 187 deletions.
15 changes: 10 additions & 5 deletions src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ const currentYear = new Date().getFullYear();
---

<footer class="kanit-light">
<span>©️ {currentYear}</span>
<a href="https://github.com/djsiddz" title="Astro-naut Siddhesh Thadeshwar" target="_blank"
>👨‍🚀 Siddhesh Thadeshwar</a
>
<a href="https://github.com/djsiddz" title="Astro-naut Siddhesh Thadeshwar" target="_blank">
<span>©️ {currentYear}</span> 👨‍🚀 Siddhesh Thadeshwar
</a>
<a href="https://github.com/djsiddz/space-ahead" title="Star this on GitHub" target="_blank"
>⭐ this on GitHub</a
>
Expand All @@ -17,16 +16,22 @@ const currentYear = new Date().getFullYear();
<style>
footer {
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
font-size: 0.75rem;
gap: 1.5rem;
padding: 1rem 0;
width: 100%;
}
@media (orientation: portrait) {
footer {
font-size: 0.5rem;
gap: 1rem;
padding: 0;
}
footer a:first-child {
width: 100%;
text-align: center;
}
}
</style>
17 changes: 17 additions & 0 deletions src/components/Hamburger.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
---

<span id="hamburger-menu" title="Menu">🍔</span>
<style>
#hamburger-menu {
display: none;
font-size: 1.25rem;
cursor: pointer;
}
@media (orientation: portrait) {
#hamburger-menu {
display: block;
}
}
</style>
152 changes: 133 additions & 19 deletions src/components/Nav.astro
Original file line number Diff line number Diff line change
@@ -1,35 +1,149 @@
---
import Hamburger from "./Hamburger.astro";
import ThemeSwitcher from "./ThemeSwitcher.astro";
const { activePage } = Astro.props;
---
<header>
<nav class="kanit-regular">
<a class="sigmar-ff" href="/space-ahead/">
<img src="/space-ahead/space-ahead-logo.png" alt="Logo" height="36">Space Ahead
</a>
<div class="desktop-links">
<a class={activePage === "blog" && "active"} href="/space-ahead/blog">Blog</a>
<a class={activePage === "tags" && "active"} href="/space-ahead/tags">Tags</a>
<a class={activePage === "about" && "active"} href="/space-ahead/about/">About</a>
</div>
<Hamburger />
</nav>
<ThemeSwitcher/>
<div id="mobile-links" class="kanit-regular animated slideOutUp">
<a class={activePage === "home" && "active"} href="/space-ahead/">Home</a>
<a class={activePage === "blog" && "active"} href="/space-ahead/blog">Blog</a>
<a class={activePage === "tags" && "active"} href="/space-ahead/tags">Tags</a>
<a class={activePage === "about" && "active"} href="/space-ahead/about/">About</a>
<span id="close-menu">❌</span>
</div>
</header>
<script is:inline>
document.querySelector("#hamburger-menu").addEventListener("click", () => {
console.log("clicked...");
document.querySelector("#mobile-links").classList.toggle("slideOutUp");
document.querySelector("#mobile-links").classList.toggle("expanded");
document.querySelector("#mobile-links").classList.toggle("slideInDown");
});
document.querySelector("#close-menu").addEventListener("click", () => {
console.log("clicked...");
document.querySelector("#mobile-links").classList.replace("slideInDown","slideOutUp");
setTimeout(() => {
document.querySelector("#mobile-links").classList.toggle("expanded");
}, 1050);
});
</script>

<nav class="kanit-regular">
<a href="/space-ahead/">Home</a>
<a href="/space-ahead/blog">Stories</a>
<a href="/space-ahead/tags">Tags</a>
<a href="/space-ahead/about/">About</a>
</nav>
<style>
header {
display: flex;
align-items: center;
justify-content: center;
padding: 0 0.5rem;
margin: 1rem;
font-size: 1rem;
column-gap: 0.5rem;
}
nav {
border-radius: 2rem;
border: 2px solid whitesmoke;
display: flex;
font-size: 1rem;
align-items: center;
justify-content: space-between;
padding: 0.25rem 1.25rem;
gap: 4rem;
margin-top: 1rem;
padding: 0.25rem 3rem;
}
nav > a {
color: whitesmoke;
}
nav > a:hover {
color: #ffff85;
}
}
nav a:first-child {
display: flex;
align-items: center;
}
.desktop-links {
display: flex;
align-items: center;
gap: 2rem
}
.active {
border-radius: 1rem;
padding: 0.125rem 0.75rem;
}
html.dark .active {
color: #ffff85;
}
html.light .active {
color: #ff6b6d;
}
#mobile-links {
width: 100%;
height: 0;
display: none;
margin: 0;
top: 0;
opacity: 0;
}
.#mobile-links a {
display: block;
text-align: center;
padding: 10px 0;
text-decoration: none;
font-size: 1.2rem;
font-weight: bold;
text-transform: uppercase;
}
#close-menu {
cursor: pointer;
padding-top: 2rem;
text-align: right;
}
.expanded {
display: unset;
top: -100vh;
}

html.dark nav {
border: 2px solid whitesmoke;
background-color: black;
}
html.light nav {
border: 2px solid black;
background-color: white;
}

@media (orientation: portrait) {
header {
flex-direction: column;
row-gap: 0.5rem;
}
nav {
font-size: 0.75rem;
gap: 1rem;
padding: 0.25rem 1.25rem;
padding: 0.25rem 0.75rem;
width: 100%;
}
.desktop-links {
display: none;
}
#mobile-links.expanded {
align-items: center;
background-color: black;
display: flex;
flex-direction: column;
gap: 1rem;
justify-content: center;
left: 0;
position: absolute;
z-index: 10;
top: 0;
opacity: 1;
padding: 1rem 0;
height: 100%;
}
html.light #mobile-links.expanded {
background-color: whitesmoke;
}
}
@media (max-width: 315px) {
Expand Down
27 changes: 11 additions & 16 deletions src/components/PostsList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,39 @@
const { posts } = Astro.props;
---

<section class="posts-list kanit-bold">
<div class="posts-list">
{
posts.reverse().map((post) => (
<div class="card">
<img src={post.frontmatter.image.url} alt={post.frontmatter.image.alt} /><br/>
<a class="balance-text" href={post.url}>{post.frontmatter.title}<br/><span class="kanit-light">{new Date(post.frontmatter.pubDate).toDateString()}</span></a>
<a class="kanit-bold balance-text" href={post.url}>{post.frontmatter.title}<br/><span class="kanit-light pub-date">{new Date(post.frontmatter.pubDate).toDateString()}</span></a>
</div>
))
}
</section>
</div>
<style>
.posts-list {
display: flex;
flex-direction: row;
flex-wrap: wrap;
row-gap: 0;
column-gap: 3rem;
list-style-type: none;
align-items: center;
margin-bottom: 3rem;
gap: 2rem;
justify-content: center;
}
.posts-list .card img {
max-width: 320px;
max-height: 180px;
max-width: 360px;
max-height: 202px;
border-radius: 1rem;
margin-bottom: 1rem;
}
@media (orientation: portrait) {
.posts-list {
flex-direction: column;
row-gap: 3rem;
column-gap: 0;
padding-left: 0;
padding-right: 0;
font-size: 0.75rem;
}
.posts-list .card img {
max-width: 240px;
max-height: 135px;
}
.pub-date {
font-size: 0.5rem;
}
}
</style>
2 changes: 1 addition & 1 deletion src/components/SpaceEmoji.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export default function SpaceEmoji({emojis}) {
const getRandomEmoji = () => emojis[(Math.floor(Math.random() * emojis.length))];
const [emoji, setEmoji] = useState(getRandomEmoji());

return <button class="kanit-regular text-balance" title="Click Me!" style={{fontSize: "1rem", background: "transparent", border: "none", cursor: "pointer", color: "whitesmoke", marginBottom: 0}} onClick={() => setEmoji(getRandomEmoji())}>{emoji}</button>;
return <button id="space-pop-culture" class="kanit-regular text-balance" title="Click Me!" style={{fontSize: "1rem", background: "transparent", border: "none", cursor: "pointer", color: "inherit", marginBottom: 0, textOverflow: "wrap"}} onClick={() => setEmoji(getRandomEmoji())}>{emoji}</button>;
}
84 changes: 84 additions & 0 deletions src/components/ThemeSwitcher.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
---

<button id="themeToggle" title="Click to Switch Theme">
<svg width="20px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
class="sun"
fill-rule="evenodd"
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"
></path>
<path
class="moon"
fill-rule="evenodd"
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"
></path>
</svg>
</button>

<style>
#themeToggle {
border-radius: 1.5rem;
border: 2px solid inherit;
background: none;
cursor: pointer;
padding: 0.4rem 0.5rem;
/* margin-left: 1rem; */
}
.sun {
fill: orange;
}
.moon {
fill: transparent;
}

:global(.dark) .sun {
fill: transparent;
}
:global(.dark) .moon {
fill: whitesmoke;
}
@media (orientation: portrait) {
#themeToggle {
padding: 0.25rem 0.3rem;
/* margin-right: 0.75rem; */
margin-left: auto;
}
}
</style>

<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 === "light") {
document.documentElement.classList.add("light");
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
document.documentElement.classList.remove("light");
}

window.localStorage.setItem("theme", theme);

const handleToggleClick = () => {
const element = document.documentElement;
element.classList.toggle("light");
element.classList.toggle("dark");

const isDark = element.classList.contains("dark");
localStorage.setItem("theme", isDark ? "dark" : "light");
};

document
.getElementById("themeToggle")
.addEventListener("click", handleToggleClick);
</script>
Loading

0 comments on commit ce89861

Please sign in to comment.