Skip to content

Commit

Permalink
Merge branch 'main' into fix/924
Browse files Browse the repository at this point in the history
  • Loading branch information
karnikaavelumani committed Oct 18, 2023
2 parents 50496ca + d6c915c commit b2222ab
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/public/links/links.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,9 @@
"stack-visu": "https://stack-visu.vercel.app/",
"ui-design": "https://www.figma.com/file/B2RNOWZtitLLmPhQ0NUwdH/Crating-User-Interfaces?type=whiteboard&node-id=0%3A1&t=vqt1hqht1lByr3Ib-1",
"ai-art-resources": "https://docs.google.com/document/d/1c8RKbDTg2LcC9DwOXvaY0OXZ61yOQzCIU7TJVDhM0VQ/edit?usp=sharing",
"oss-meeting-3": "https://docs.google.com/presentation/d/1UJOF2p_c9pGvztpB0QiJfLbAMRBkgKLIy_eZPwH6U30/edit?usp=sharing"
"oss-meeting-3": "https://docs.google.com/presentation/d/1UJOF2p_c9pGvztpB0QiJfLbAMRBkgKLIy_eZPwH6U30/edit?usp=sharing",
"oss-meeting-4": "https://docs.google.com/presentation/d/1upCG_6nzI_G5HdK5qKfMvKj61_8qpj1iwOlcIbfvkUo/edit?usp=sharing",
"ai-flowers": "https://docs.google.com/document/d/17aG-MHWo2FO5Hhbnvz_gg5rJWbKPYhfvs9G-4UgBC6U/edit?usp=sharing",
"asset-workshop": "https://docs.google.com/presentation/d/1bFThk1bTUOJ7W8Gqcx0x5zVRuZ6G9rLIx9yewUKXFb4/edit?usp=sharing",
"design2code": "https://www.figma.com/file/47njZNOfMF5lDPSHiG4kJF/Design2Code?type=whiteboard&node-id=0%3A1&t=8SNCeouHjk2sa9mt-1"
}
45 changes: 45 additions & 0 deletions src/routes/(site)/6/lucky.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<script lang="ts">
import AcmButton from '$lib/components/button/button.svelte';
</script>

<section class="lucky-container">
<div class="lucky-inner-container">
<div class="lucky-text">
<h1 class="brand-header size-xl">I'm feeling lucky!</h1>
<div class="lucky-button">
<AcmButton text="Visit a random page?" link="/random" redirect />
</div>
</div>

<img
src="/assets/png/capy-lucky.png"
alt="Chip the Capybara surrounded by all ACM Team badges"
/>
</div>
</section>

<style>
section {
display: grid;
}
section .lucky-inner-container {
display: grid;
grid-template-columns: 1fr;
align-items: center;
gap: 3em;
}
section .lucky-inner-container .lucky-text {
display: grid;
align-items: center;
text-align: center;
gap: 3em;
}
section .lucky-inner-container .lucky-text .lucky-button {
display: grid;
justify-self: center;
}
section .lucky-inner-container img {
max-width: clamp(20rem, 17.342rem + 10.13vw, 30rem);
justify-self: center;
}
</style>
40 changes: 40 additions & 0 deletions src/routes/(site)/random/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { RequestEvent } from '@sveltejs/kit';

/**
* The server-side load function for https://acmcsuf.com/random.
*/
export async function GET({ url }: RequestEvent) {
const modules = Object.keys(
await import.meta.glob('../**/+page.svelte', { eager: true, as: 'raw' })
);
const pages = getPages(modules);
const randomPage = pages[~~(Math.random() * pages.length)];
const destination = new URL(randomPage, url);
console.log({ modules, pages });
return Response.redirect(destination, 302);
}

/**
* getPages gets the SvelteKit pages given a list of module names.
*
* Reference:
* - https://github.com/sveltejs/kit/issues/923#issuecomment-1567052262
*/
function getPages(modules: string[]): string[] {
return modules.map(toPathname).filter((pathname) => pathname !== null) as string[];
}

function toPathname(input: string): string | null {
// Removes dynamic pages that cannot be dynamically retrieved at random.
// Check for [ and ] symbols in the input string and return null if found
if (input.includes('[') || input.includes(']')) {
return null;
}

// Deconstruct the pathname parts.
const parts = input.split('/').filter((part) => !!part && part !== '.' && part !== '..');

// Reconstruct the pathname while ignoring last part.
const pathname = parts.slice(0, parts.length - 1).join('/');
return `/${pathname}`;
}
Binary file added static/assets/png/capy-lucky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b2222ab

Please sign in to comment.