Skip to content

Commit

Permalink
fixes to new resources page
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosalm committed Feb 6, 2025
1 parent fec8f12 commit 8341004
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 68 deletions.
33 changes: 20 additions & 13 deletions .astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,91 +277,98 @@ declare module 'astro:content' {
slug: "contributing";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"README.md": {
id: "README.md";
slug: "readme";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/algorithms.md": {
id: "lists/algorithms.md";
slug: "lists/algorithms";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/databases-and-filesystems.md": {
id: "lists/databases-and-filesystems.md";
slug: "lists/databases-and-filesystems";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/essentials.md": {
id: "lists/essentials.md";
slug: "lists/essentials";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/for-fun.md": {
id: "lists/for-fun.md";
slug: "lists/for-fun";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/math.md": {
id: "lists/math.md";
slug: "lists/math";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/need-sorting.md": {
id: "lists/need-sorting.md";
slug: "lists/need-sorting";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/performance.md": {
id: "lists/performance.md";
slug: "lists/performance";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/productivity.md": {
id: "lists/productivity.md";
slug: "lists/productivity";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/programming-languages.md": {
id: "lists/programming-languages.md";
slug: "lists/programming-languages";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/stuff-to-do.md": {
id: "lists/stuff-to-do.md";
slug: "lists/stuff-to-do";
body: string;
collection: "resources";
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/unix.md": {
id: "lists/unix.md";
slug: "lists/unix";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
"lists/web-development.md": {
id: "lists/web-development.md";
slug: "lists/web-development";
body: string;
collection: "resources";
data: any
data: InferEntrySchema<"resources">
} & { render(): Render[".md"] };
};

Expand Down
24 changes: 0 additions & 24 deletions .github/workflows/update_submodules.yml

This file was deleted.

6 changes: 3 additions & 3 deletions src/content/_coord-hours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ let CoordHours: CoordHour[] = [
},
{
Time: "11 AM - 12 PM",
Coords: ["Pusti", "", "Sam", "", "Anna"],
Coords: ["Pusti", "Nico", "Sam", "Nico", "Anna"],
},
{
Time: "12 - 1 PM",
Coords: ["Pusti", "Jiamu", "Mari", "Jiamu", "Anna"],
},
{
Time: "1 - 2 PM",
Coords: ["Nico", "Emily", "Rahul", "Emily", "Michael"],
Coords: ["", "Emily", "Rahul", "Emily", "Michael"],
},
{
Time: "2 - 3 PM",
Coords: ["Nico", "", "", "", "Michael"],
Coords: ["", "", "", "", "Michael"],
},
{
Time: "3 - 4 PM",
Expand Down
10 changes: 9 additions & 1 deletion src/content/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ const coordinators = defineCollection({
)
})

export const collections = { blog, events, coordinators };
const resources = defineCollection({
type: "content",
schema: z.object({
title: z.string().optional(),
description: z.string().optional(),
}),
});

export const collections = { blog, events, resources, coordinators };
2 changes: 1 addition & 1 deletion src/content/resources
71 changes: 51 additions & 20 deletions src/pages/lists/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,70 @@ import { getCollection } from "astro:content";
import Layout from "../../layouts/Layout.astro";
export async function getStaticPaths() {
const resources = await getCollection("resources");
const resources = await getCollection("resources");
return resources.map((x) => ({
params: {
slug: x.id.replace(/^lists\//, '').replace(/\.md$/, '')
},
props: { entry: x },
}));
return resources
.filter(resource => resource.id.startsWith('lists/'))
.map((x) => ({
params: {
slug: x.id.replace(/^lists\//, '').replace(/\.md$/, '')
},
props: { entry: x },
}));
}
const { entry } = Astro.props;
const { Content } = await entry.render();
---

<Layout>
<div class="inline w-full overflow-hidden text-slate-800">
<div class="mx-auto w-3/4">
<div class="text-base/6 font-sans prose prose-lg prose-zinc">
<Content />
</div>
<div class="flex justify-center w-full min-h-screen text-slate-800">
<div class="w-full max-w-3xl px-4 py-8">
<div class="prose prose-lg prose-zinc mx-auto">
<Content />
</div>
</div>
</div>
</div>
</Layout>

<script>
document.addEventListener('click', (e) => {
const target = e.target as HTMLElement;
if (target.tagName === 'A') {
const href = target.getAttribute('href');
if (href?.includes('README.md')) {
e.preventDefault();
window.location.href = '/resources';
const target = e.target as HTMLElement;
if (target.tagName === 'A') {
const href = target.getAttribute('href');
// Handle README.md case
if (href?.includes('README.md')) {
e.preventDefault();
history.pushState({}, '', '/resources');
window.location.href = '/resources';
return;
}
// Handle other .md files
if (href?.endsWith('.md') && !href.startsWith('http')) {
e.preventDefault();
const cleanPath = href.replace(/\.md$/, '');
history.pushState({}, '', cleanPath);
if (window.location.pathname !== cleanPath) {
window.location.href = cleanPath;
}
}
}
});

// Handle browser back/forward buttons
window.addEventListener('popstate', (e) => {
// Check if we're trying to go back to a README.md path
if (window.location.pathname.includes('README')) {
history.pushState({}, '', '/resources');
window.location.href = '/resources';
return;
}

// For other .md paths, clean them
if (window.location.pathname.endsWith('.md')) {
const cleanPath = window.location.pathname.replace(/\.md$/, '');
history.pushState({}, '', cleanPath);
window.location.reload();
}
}
});
</script>
15 changes: 9 additions & 6 deletions src/pages/resources.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import Layout from "../layouts/Layout.astro";
const resources = await getCollection("resources");
const readme = resources.find(d => d.id === "README.md");
if (!readme) {
throw new Error("README.md not found in resources collection");
}
const { Content } = await readme.render();
---

<Layout>
<div class="inline w-full overflow-hidden text-slate-800">
<div class="mx-auto w-3/4">
<div class="text-base/6 font-sans prose prose-lg prose-zinc">
<Content />
</div>
<div class="flex justify-center w-full min-h-screen text-slate-800">
<div class="w-full max-w-3xl px-4 py-8">
<div class="prose prose-lg prose-zinc mx-auto">
<Content />
</div>
</div>
</div>
</div>
</Layout>

0 comments on commit 8341004

Please sign in to comment.