Skip to content

Commit

Permalink
add support for new resources page
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosalm committed Jan 27, 2025
1 parent 292e936 commit fec8f12
Show file tree
Hide file tree
Showing 8 changed files with 299 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .astro/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"_variables": {
"lastUpdateCheck": 1736791334401
"lastUpdateCheck": 1737940308832
}
}
155 changes: 151 additions & 4 deletions .astro/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,64 @@ declare module 'astro:content' {
data: InferEntrySchema<"blog">
} & { render(): Render[".md"] };
};
"docs": {
"Code-of-Conduct.md": {
id: "Code-of-Conduct.md";
slug: "code-of-conduct";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"Coordinator-Responsibilities.md": {
id: "Coordinator-Responsibilities.md";
slug: "coordinator-responsibilities";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"New User Form/New_User_Signup_Form.md": {
id: "New User Form/New_User_Signup_Form.md";
slug: "new-user-form/new_user_signup_form";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"New User Form/README.md": {
id: "New User Form/README.md";
slug: "new-user-form/readme";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"README.md": {
id: "README.md";
slug: "readme";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"Start-Of-Semester-Checklist.md": {
id: "Start-Of-Semester-Checklist.md";
slug: "start-of-semester-checklist";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"building-tour-guide.md": {
id: "building-tour-guide.md";
slug: "building-tour-guide";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
"coord-app.md": {
id: "coord-app.md";
slug: "coord-app";
body: string;
collection: "docs";
data: any
} & { render(): Render[".md"] };
};
"events": {
"lightning-talks-fall-2024-1.md": {
id: "lightning-talks-fall-2024-1.md";
Expand All @@ -212,6 +270,99 @@ declare module 'astro:content' {
collection: "events";
data: InferEntrySchema<"events">
} & { render(): Render[".md"] };
};
"resources": {
"CONTRIBUTING.md": {
id: "CONTRIBUTING.md";
slug: "contributing";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"README.md": {
id: "README.md";
slug: "readme";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/algorithms.md": {
id: "lists/algorithms.md";
slug: "lists/algorithms";
body: string;
collection: "resources";
data: any
} & { 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
} & { render(): Render[".md"] };
"lists/essentials.md": {
id: "lists/essentials.md";
slug: "lists/essentials";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/for-fun.md": {
id: "lists/for-fun.md";
slug: "lists/for-fun";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/math.md": {
id: "lists/math.md";
slug: "lists/math";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/need-sorting.md": {
id: "lists/need-sorting.md";
slug: "lists/need-sorting";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/performance.md": {
id: "lists/performance.md";
slug: "lists/performance";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/productivity.md": {
id: "lists/productivity.md";
slug: "lists/productivity";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/programming-languages.md": {
id: "lists/programming-languages.md";
slug: "lists/programming-languages";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/unix.md": {
id: "lists/unix.md";
slug: "lists/unix";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
"lists/web-development.md": {
id: "lists/web-development.md";
slug: "lists/web-development";
body: string;
collection: "resources";
data: any
} & { render(): Render[".md"] };
};

};
Expand Down Expand Up @@ -333,10 +484,6 @@ declare module 'astro:content' {
collection: "coordinators";
data: InferEntrySchema<"coordinators">
};
};
"docs": {
};
"resources": {
};

};
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/update_submodules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Update Submodules

on:
schedule:
- cron: '0 0 */3 * *' # every 3 days at midnight
workflow_dispatch:

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
token: ${{ secrets.PAT }}

- name: Update submodules
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
git submodule update --remote --recursive
git add .
git diff --cached --quiet || git commit -m "action: update submodules"
git push
59 changes: 27 additions & 32 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,32 @@ import sitemap from "@astrojs/sitemap";
import tailwind from "@astrojs/tailwind";
import react from "@astrojs/react";
import { remarkReadingTime } from "./remark-reading-time.mjs";

import playformCompress from "@playform/compress";
import { generateResourceRedirects } from "./src/utils/redirects";

const createConfig = async () => {
const redirects = await generateResourceRedirects();

return defineConfig({
site: "https://www.upl.cs.wisc.edu/",
redirects,
integrations: [sitemap(), tailwind(), react(), playformCompress()],
compressHTML: false,
markdown: {
syntaxHighlight: "prism",
remarkPlugins: [remarkReadingTime],
optimize: true,
remarkRehype: {
footnoteLabel: 'Footnotes',
footnoteLabelProperties: {
className: ['sr-only']
}
}
},
build: {
format: 'file',
}
});
};

// https://astro.build/config
export default defineConfig({
site: "https://www.upl.cs.wisc.edu/",
redirects: {
"/hours.html": "/hours",
"/blog.html": "/blog",
"/coords": "/about",
// blog post back-links
"/2022/02/25/incorrect-reification.html": "/blog/incorrect-reification/",
"/2022/02/02/learning-to-code-with-projects.html":
"/blog/learning-to-code-with-projects/",
"/2022/02/09/a-cautionary-tale-of-amazon-web-service-classes.html":
"/blog/a-cautionary-tale-of-amazon-web-service-classes/",
"/2022/03/17/exploiting-github-actions.html":
"/blog/exploiting-github-actions/",
"/2022/04/03/why-i-use-firefox.html": "/blog/why-i-use-firefox/",
"/2022/04/16/Game-Design-and-Education.html":
"/blog/game-design-and-education/",
"/2022/04/7/Artificial-Consciousness-and-Phenomenology.html":
"/blog/artificial-consciousness-and-phenomenology/",
"/2022/05/12/Using-GPT3-To-Write-A-Blog-Post.html":
"/blog/using-gpt3-to-write-a-blog-post/",
},
integrations: [sitemap(), tailwind(), react(), playformCompress()],
compressHTML: false,
markdown: {
syntaxHighlight: "prism",
remarkPlugins: [remarkReadingTime],
optimize: true,
},
});
export default createConfig();
41 changes: 41 additions & 0 deletions src/pages/lists/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
import { getCollection } from "astro:content";
import Layout from "../../layouts/Layout.astro";
export async function getStaticPaths() {
const resources = await getCollection("resources");
return resources.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>
</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';
}
}
});
</script>
15 changes: 8 additions & 7 deletions src/pages/resources.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { getCollection } from "astro:content";
import Layout from "../layouts/Layout.astro";
const resources = await getCollection("resources");
const readmeRendered = await resources.filter(d => d.id == "README.md")[0].render();
const readme = resources.find(d => d.id === "README.md");
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">
<readmeRendered.Content>
</div>
</div>
<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>
</div>
</Layout>
46 changes: 46 additions & 0 deletions src/utils/redirects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fs from 'fs';
import path from 'path';

function getAllMarkdownFiles(dirPath: string, arrayOfFiles: string[] = []): string[] {
const files = fs.readdirSync(dirPath);

files.forEach((file) => {
const filePath = path.join(dirPath, file);
if (fs.statSync(filePath).isDirectory()) {
arrayOfFiles = getAllMarkdownFiles(filePath, arrayOfFiles);
} else if (path.extname(file) === '.md') {
const relativePath = path.relative(path.join(process.cwd(), 'src/content/resources'), filePath);
arrayOfFiles.push(relativePath);
}
});

return arrayOfFiles;
}

export function generateResourceRedirects() {
const redirects: Record<string, string> = {
// existing static redirects
"/hours.html": "/hours",
"/blog.html": "/blog",
"/coords": "/about",
"/2022/02/25/incorrect-reification.html": "/blog/incorrect-reification/",
"/2022/02/02/learning-to-code-with-projects.html": "/blog/learning-to-code-with-projects/",
"/2022/02/09/a-cautionary-tale-of-amazon-web-service-classes.html": "/blog/a-cautionary-tale-of-amazon-web-service-classes/",
"/2022/03/17/exploiting-github-actions.html": "/blog/exploiting-github-actions/",
"/2022/04/03/why-i-use-firefox.html": "/blog/why-i-use-firefox/",
"/2022/04/16/Game-Design-and-Education.html": "/blog/game-design-and-education/",
"/2022/04/7/Artificial-Consciousness-and-Phenomenology.html": "/blog/artificial-consciousness-and-phenomenology/",
"/2022/05/12/Using-GPT3-To-Write-A-Blog-Post.html": "/blog/using-gpt3-to-write-a-blog-post/",
};

// get all markdown files from the resources dir & add redirects to each
const contentDir = path.join(process.cwd(), 'src/content/resources');
const markdownFiles = getAllMarkdownFiles(contentDir);

markdownFiles.forEach((file) => {
const normalizedPath = file.split(path.sep).join('/');
redirects[`/${normalizedPath}`] = `/${normalizedPath.replace(/\.md$/, '')}`;
});

return redirects;
}

0 comments on commit fec8f12

Please sign in to comment.