Skip to content

Commit

Permalink
Add public directory
Browse files Browse the repository at this point in the history
  • Loading branch information
silent1mezzo committed Oct 2, 2023
1 parent 75de121 commit c2e68c2
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,4 +1,3 @@
public

# build output
dist/
Expand Down
13 changes: 13 additions & 0 deletions public/favicon.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/resume.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions public/robots.txt
@@ -0,0 +1,5 @@
User-agent: Googlebot
Disallow: /nogooglebot/

User-agent: *
Allow: /
76 changes: 76 additions & 0 deletions public/toggle-theme.js
@@ -0,0 +1,76 @@
const primaryColorScheme = ""; // "light" | "dark"

// Get theme data from local storage
const currentTheme = localStorage.getItem("theme");

function getPreferTheme() {
// return theme value in local storage if it is set
if (currentTheme) return currentTheme;

// return primary color scheme if it is set
if (primaryColorScheme) return primaryColorScheme;

// return user device's prefer color scheme
return window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}

let themeValue = getPreferTheme();

function setPreference() {
localStorage.setItem("theme", themeValue);
reflectPreference();
}

function reflectPreference() {
document.firstElementChild.setAttribute("data-theme", themeValue);

document.querySelector("#theme-btn")?.setAttribute("aria-label", themeValue);

// Get a reference to the body element
const body = document.body;

// Check if the body element exists before using getComputedStyle
if (body) {
// Get the computed styles for the body element
const computedStyles = window.getComputedStyle(body);

// Get the background color property
const bgColor = computedStyles.backgroundColor;

// Set the background color in <meta theme-color ... />
document
.querySelector("meta[name='theme-color']")
?.setAttribute("content", bgColor);
}
}

// set early so no page flashes / CSS is made aware
reflectPreference();

window.onload = () => {
function setThemeFeature() {
// set on load so screen readers can get the latest value on the button
reflectPreference();

// now this script can find and listen for clicks on the control
document.querySelector("#theme-btn")?.addEventListener("click", () => {
themeValue = themeValue === "light" ? "dark" : "light";
setPreference();
});
}

setThemeFeature();

// Runs on view transitions navigation
document.addEventListener("astro:after-swap", setThemeFeature);
};

// sync with system changes
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", ({ matches: isDark }) => {
themeValue = isDark ? "dark" : "light";
setPreference();
});
21 changes: 21 additions & 0 deletions src/pages/index.xml.ts
@@ -0,0 +1,21 @@
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import getSortedPosts from "@utils/getSortedPosts";
import slugify from "@utils/slugify";
import { SITE } from "@config";

export async function GET() {
const posts = await getCollection("posts");
const sortedPosts = getSortedPosts(posts);
return rss({
title: SITE.title,
description: SITE.desc,
site: SITE.website,
items: sortedPosts.map(({ data }) => ({
link: `posts/${slugify(data)}`,
title: data.title,
description: data.description,
pubDate: new Date(data.date),
})),
});
}

0 comments on commit c2e68c2

Please sign in to comment.