Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronlifton committed Mar 22, 2024
1 parent dac74a2 commit 2caf9de
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/components/LatestCodeList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ import { Code } from "astro:components";
import { getCollection, type CollectionEntry } from "astro:content";
import PlayPause from "$components/react/PlayPause";
const codeOrder = ["vim", "tsx", "jsx","ts","js", "typescript", "javascript","ruby", "go", "rust", "lua", "bash", "json", "shell", "html", "css"];
function codeSort(a: CodeResults[0], b: CodeResults[0]) {
if (a.lang === b.lang) return 0;
if (!a.lang) return 1;
if (!b.lang) return -1;
const aIndex = codeOrder.indexOf(a.lang);
const bIndex = codeOrder.indexOf(b.lang);
if (aIndex === -1) return 1;
if (bIndex === -1) return -1;
if (aIndex < bIndex) return -1;
if (aIndex > bIndex) return 1;
return 0;
}
const posts: CollectionEntry<"blog">[] = await getCollection("blog");
let allCodes: CodeResults = [];
const livePosts = posts.filter((post) => !post.data.draft);
Expand All @@ -12,7 +27,7 @@ for (const post of livePosts) {
if (!codes) continue;
const codesWithPost: CodeResults = codes.map((code) => ({ ...code, post }));
allCodes = allCodes.concat(codesWithPost);
allCodes = allCodes.concat(codesWithPost).sort(codeSort);
}
---

Expand Down Expand Up @@ -82,7 +97,7 @@ for (const post of livePosts) {
<script>
import { isPaused } from "$state/index";

document.addEventListener("astro:page-load", () => {
const onLoad = () => {
const codesContainer = document.querySelector(
".codes-container"
) as HTMLDivElement;
Expand Down Expand Up @@ -192,5 +207,8 @@ for (const post of livePosts) {
// );
//
// codes.forEach((code) => observer.observe(code));
});
}

document.addEventListener("astro:page-load", onLoad)
onLoad()
</script>
2 changes: 1 addition & 1 deletion src/components/PostPreviewList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const { posts, heading, mode = "col", asCard = false } = Astro.props;
// @ts-ignore
const sortedPosts = posts.sort(
(a, b) =>
new Date(a.data.pubDate).valueOf() - new Date(b.data.pubDate).valueOf()
new Date(b.data.pubDate).valueOf() - new Date(a.data.pubDate).valueOf()
);
---

Expand Down
Binary file added src/content/blog/assets/nanostores.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Sharing state between React and Astro components with nanoStores
description: How to use the nanoStores library to share state between React and Astro components
pubDate: Mar 22 2024
cover: ./assets/nanostores.jpg
coverAlt: Screenshot of the nanoStores github README
tags: [astro, react, nanostores]
draft: true
---

Enabling the Speculation Rules API with AstroJS

In the modern web development landscape, page loading speed is integral to user
experience. any web application. Speculation Rules API, an experimental feature,
is pretty much a game changer, as page loads will become instant as the client
fetches them, based on pre-configured rules. This post is intended to guide
developers through the process of integrating the Speculation Rules API with
AstroJS.
1 change: 0 additions & 1 deletion src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const prerender = true;
let posts: CollectionEntry<"blog">[] = await getCollection("blog");
posts = Array.from(posts)
.filter((post) => !post.data.draft)
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
---

<Layout>
Expand Down

0 comments on commit 2caf9de

Please sign in to comment.