Skip to content

Commit

Permalink
first part of reading page refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ArhanChaudhary committed May 29, 2024
1 parent f7f5d41 commit 660fc35
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
import type { CollectionEntry } from "astro:content";
interface Props {
section: CollectionEntry<"reading">;
section: CollectionEntry<"book-review">;
}
const { section } = Astro.props;
const { Content } = await section.render();
---

<details>
<summary>{section.id.replace(".mdx", "")}</summary>
<div class="indent">
<Content />
</div>
</details>
<h2>{section.id.replace(".mdx", "")}</h2>
<div class="indent">
<Content />
</div>

<style lang="scss">
details {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Writeup.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { CollectionEntry } from "astro:content";
interface Props {
writeup: CollectionEntry<"write-up">;
writeup: CollectionEntry<"ctf-write-up">;
prevCategory: string | undefined;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
rating: 5
read: 2023-10-09T08:00:00
---

hello world

hooray
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
rating: 4.5
read: 2024-05-21T08:00:00
---

hello world

yoo
25 changes: 21 additions & 4 deletions src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const writeupCategory = [
"Binary Exploitation",
] as const;

const writeupCollection = defineCollection({
const CTFWriteupCollection = defineCollection({
type: "content",
schema: z.object({
description: z.string(),
Expand All @@ -34,8 +34,12 @@ const writeupCollection = defineCollection({
}),
});

const readingCollection = defineCollection({
const bookReviewCollection = defineCollection({
type: "content",
schema: z.object({
rating: z.number().gte(1).lte(5).multipleOf(0.5),
read: z.date(),
}),
});

const ctfsCollection = defineCollection({
Expand All @@ -48,9 +52,22 @@ const ctfsCollection = defineCollection({
),
});

const unreadBooksCollection = defineCollection({
type: "data",
schema: z.array(
z.object({
title: z.string(),
author: z.string(),
url: z.string().url(),
inProgress: z.boolean(),
})
),
});

export const collections = {
blog: blogCollection,
"write-up": writeupCollection,
reading: readingCollection,
"ctf-write-up": CTFWriteupCollection,
"book-review": bookReviewCollection,
ctfs: ctfsCollection,
"unread-books": unreadBooksCollection,
};
1 change: 0 additions & 1 deletion src/content/reading/2023.mdx

This file was deleted.

1 change: 0 additions & 1 deletion src/content/reading/2024.mdx

This file was deleted.

1 change: 0 additions & 1 deletion src/content/reading/Reading in progress.mdx

This file was deleted.

5 changes: 0 additions & 5 deletions src/content/reading/Reading list.mdx

This file was deleted.

33 changes: 17 additions & 16 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
---
import "normalize.css";
const sshUsers = [
"home",
"projects",
"blog",
"ctf",
"reading",
"cubing",
"media",
"nuclear-bomb",
] as const;
interface Props {
title: string;
sshUser: string;
sshUser: (typeof sshUsers)[number];
description?: string;
}
Expand All @@ -13,19 +24,7 @@ const {
description = "Arhan's personal website",
} = Astro.props;
const highlightIndex = {
"home": 1,
"projects": 2,
"blog": 3,
"ctf": 4,
"reading": 5,
"cubing": 6,
"media": 7,
"nuclear-bomb": 8,
}[sshUser];
if (highlightIndex === undefined) {
throw new Error("invalid sshUser");
}
const highlightIndex = sshUsers.indexOf(sshUser) + 1;
---

<!doctype html>
Expand Down Expand Up @@ -82,7 +81,9 @@ if (highlightIndex === undefined) {
<div id="flex-wrapper">
<div id="ssh-text" class="input-mono">
<!-- https://stackoverflow.com/a/77568291/12230735 -->
{sshUser}@&#8203;arhan.sh:~$ <span id="troll"></span><span id="cursor">█</span>
{sshUser}@&#8203;arhan.sh:~$ <span id="troll"></span><span id="cursor"
>█</span
>
</div>
<label id="nav-hamburger" for="nav-toggle">
<div></div>
Expand Down Expand Up @@ -230,7 +231,7 @@ if (highlightIndex === undefined) {
<a href="/reading/">Reading</a>
<a href="/cubing/">Cubing</a>
<a href="/media/">Media</a>
{highlightIndex == 8 && <a href="/404">Not Found</a>}
{sshUser === "nuclear-bomb" && <a href="/404">Not Found</a>}
<div id="nav-arrow" style={`--highlightIndex: ${highlightIndex}`}>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-41 0 41 34">
<path
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ctfing.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Layout from "../layouts/Layout.astro";
import { getCollection, getEntry } from "astro:content";
const { data: allCTFs } = await getEntry("ctfs", "ctfs");
const allWriteups = await getCollection("write-up");
const allWriteups = await getCollection("ctf-write-up");
const CTFWriteupNames = new Set(
allWriteups.map((writeup) => {
const ret = writeup.id.split("/").at(-2)!;
Expand Down
54 changes: 49 additions & 5 deletions src/pages/reading.astro
Original file line number Diff line number Diff line change
@@ -1,16 +1,60 @@
---
import Layout from "../layouts/Layout.astro";
import ReadingSection from "../components/ReadingSection.astro";
import BookReview from "../components/BookReview.astro";
import { getCollection } from "astro:content";
import type { CollectionEntry } from "astro:content";
const allSections = await getCollection("reading");
allSections.reverse();
const allBookReviews = await getCollection("book-review");
allBookReviews.reverse();
const yearsToReviews = new Map<number, CollectionEntry<"book-review">[]>();
for (let section of allBookReviews) {
const year = section.data.read.getFullYear();
if (!yearsToReviews.has(year)) {
yearsToReviews.set(year, []);
}
const curr = yearsToReviews.get(year)!;
let i = 0;
while (i < curr.length && curr[i].data.read > section.data.read) {
i++;
}
curr.splice(i, 0, section);
}
---

<Layout title="Arhan's Reading Notes" sshUser="reading">
<div id="max-width-wrapper" class="system-ui">
<h1 class="input-mono">My reading notes</h1>
<h1 class="input-mono">My reading notes & book reviews</h1>
<hr />
{allSections.map((section) => <ReadingSection {section} />)}
{
Array.from(yearsToReviews, ([year, bookReviews]) => (
<>
<details>
<summary>{year}</summary>
<div class="indent">
{bookReviews.map((section) => (
<BookReview {section} />
))}
</div>
</details>
</>
))
}
</div>
</Layout>

<style lang="scss">
details {
margin: 1em 0;

summary {
font-size: 24px;
font-weight: bolder;
cursor: pointer;
}

.indent {
margin-left: 40px;
}
}
</style>
2 changes: 1 addition & 1 deletion src/pages/write-up/[slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getCollection } from "astro:content";
import { writeupCategory } from "../../content/config";
export async function getStaticPaths() {
const allWriteups = await getCollection("write-up");
const allWriteups = await getCollection("ctf-write-up");
const CTFWriteupNames = [
...new Set(allWriteups.map((writeup) => writeup.id.split("/").at(-2)!)),
];
Expand Down

0 comments on commit 660fc35

Please sign in to comment.