Skip to content

Commit

Permalink
Merge pull request #3 from orbisat-oeiras/post-carousel
Browse files Browse the repository at this point in the history
Post carousel
  • Loading branch information
levimcgomes authored Jan 20, 2024
2 parents 60ea593 + 5935b6d commit ba762d6
Show file tree
Hide file tree
Showing 54 changed files with 251 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Deploy to GitHub Pages

on:
push:
branches: "svelte"
branches: "main"

jobs:
build_site:
Expand Down
14 changes: 7 additions & 7 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"tailwindcss": "^3.3.3",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^4.4.2"
"vite": "^4.5.2"
},
"type": "module",
"dependencies": {
Expand Down
18 changes: 12 additions & 6 deletions app/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@
@tailwind utilities;


/*
dark:text-cansat-black dark:bg-cansat-cream text-cansat-cream bg-cansat-grey
md:w-[calc((9/16)*(100vh-120px))]
*/

@layer base {
* {
@apply font-open;
}

html {
@apply md:scroll-pt-[124px];
@apply md:scroll-pt-[120px];
@apply overflow-x-hidden;
}

Expand All @@ -24,7 +30,7 @@
h4,
h5,
h6 {
@apply underline decoration-cansat-accent font-bold;
@apply underline decoration-cansat-accent font-bold pb-4;
}

h1 {
Expand All @@ -48,7 +54,7 @@
}

p {
@apply indent-4 text-lg;
@apply indent-4 text-lg pb-10 text-justify;
}

ul {
Expand All @@ -58,7 +64,7 @@

@layer components {
.btn {
@apply bg-cansat-accent px-2 py-1 rounded-md text-lg cursor-pointer text-center text-cansat-cream not-italic no-underline;
@apply dark:text-cansat-black dark:bg-cansat-cream text-cansat-cream bg-cansat-grey px-2 py-1 rounded-md text-lg cursor-pointer text-center not-italic no-underline;
}

.tag {
Expand All @@ -74,7 +80,7 @@
}

.person>img {
@apply md:relative h-[70vh] w-[39vh] md:h-[calc(100vh-120px)] md:w-[calc((9/16)*(100vh-120px))] md:right-[10vw] lg:right-[20vw] self-center;
@apply object-cover md:relative h-[70vh] w-[39vh] md:h-[calc(100vh-120px)] md:w-[70vh] md:right-[10vw] lg:right-[20vw] self-center;
}

.person:nth-child(even)>img {
Expand All @@ -86,7 +92,7 @@
}

.person:nth-child(even)>div {
@apply md:left-[10vw] lg:left-[20vw] md:items-end;
@apply md:left-[10vw] lg:left-[20vw] md:items-end md:text-right;
}

.person>div * {
Expand Down
8 changes: 7 additions & 1 deletion app/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en" class="">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
<!--HACK: I tried importing this with SASS in the blog page itself
Expand All @@ -26,6 +25,13 @@
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png" />
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="manifest" href="/site.webmanifest" />
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#dd5928" />
<meta name="msapplication-TileColor" content="#dd5928" />
<meta name="theme-color" content="#fffde9" />
</head>
<body data-sveltekit-preload-data="hover">
<script>
Expand Down
34 changes: 22 additions & 12 deletions app/src/lib/components/Header.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
<script>
<script lang="ts">
// Import internal components
import ThemeToggle from './ThemeToggle.svelte';
import Dropdown from './Dropdown.svelte';
import { page } from '$app/stores';
import { isSmallDevice } from '$lib/stores';
import { onMount } from 'svelte';
onMount(() => {
isSmallDevice.set(window.matchMedia('(max-width: 700px)').matches);
});
</script>

<!--Use a nav to make the purpose of this component explicit-->
<nav
class="bg-cansat-black text-cansat-cream flex flex-col items-center justify-between md:flex-row md:justify-between md:content-center py-6 px-4 md:sticky top-0 z-10 [&>*]:h-min"
class="bg-cansat-black text-cansat-cream dark:bg-cansat-light2 dark:text-cansat-cream flex flex-col items-center justify-between md:flex-row md:justify-between md:content-center py-6 px-4 md:sticky top-0 z-10 [&>*]:h-min"
style={$isSmallDevice ? 'margin-bottom: 40px' : ''}
>
<!--Add here a check to see if the app is running on mobile and to see if we are on the archive-->
{#if false || $page.url.pathname != '/24'}
{#if $isSmallDevice || $page.url.pathname != '/24'}
<a class="m-2 no-underline hover:no-underline transition-none md:m-0 md:w-[120px]" href="/">
<!--<h2 class="no-underline text-grey-900 not-italic">How I Made A Game</h2>-->
<img class="w-[90%] md:h-[100%] md:w-auto md:m-0" src="/logo_transparente_claro.png" alt="" />
Expand All @@ -23,15 +30,18 @@
</div>
{/if}
<div class="flex gap-6 content-center [&>*]:h-min">
<Dropdown label="Sobre">
<!--Removed the / behind the # because it was causing issues-->
<a class="text-cansat-cream dark:text-cansat-black" href="#cansat">CanSat</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/#project">O&nbsp;Projeto</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/#team">A&nbsp;Equipa</a>
</Dropdown>
<!--Removed the / behind the # because it was causing issues-->
<!--<Dropdown label="Sobre">
<a class="text-cansat-cream dark:text-cansat-black" href="/24#cansat">CanSat</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/24#project">O&nbsp;Projeto</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/24#team">A&nbsp;Equipa</a>
</Dropdown-->
<a class="text-cansat-cream dark:text-cansat-black" href="/24#cansat">CanSat</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/24#project">Projeto</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/24#team">Equipa</a>
<!--<a class="text-grey-900" href="/24/about">Sobre</a>-->
<a class="text-cansat-cream" href="/#blog">Blog</a>
<a class="text-cansat-cream" href="/#sponsor">Apoios</a>
<ThemeToggle />
<a class="text-cansat-cream dark:text-cansat-black" href="/24#blog">Blog</a>
<a class="text-cansat-cream dark:text-cansat-black" href="/24#sponsor">Apoios</a>
<!--<ThemeToggle />-->
</div>
</nav>
12 changes: 6 additions & 6 deletions app/src/lib/components/PostComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
export let post: Post;
</script>

<div
class="w-auto rounded-lg shadow-[0_4px_8px_0_rgb(0_0_0_/_20%),_0_6px_20px_0_rgb(0_0_0_/_19%)] relative overflow-hidden min-h-[35vh]"
>
<div class="w-auto relative overflow-hidden min-h-[35vh]">
{#if post.cover_image_exists}
<img src={'/' + post.cover_image} alt="" class="pt-5 w-10/12 mx-auto" />
<p
Expand All @@ -23,19 +21,21 @@
{post.date_string}
</p>
{/if}
<!--
<ul class="flex flex-wrap items-center ml-4 list-none">
{#each post.tags as tag}
<li>
<a href={'/tag/' + tag} class="tag">{tag}</a>
</li>
{/each}
</ul>
<p class="text-lg py-1 mb-10 mx-4">{post.excerpt}</p>
-->
<p class="text-lg py-1 mb-10 mx-4 indent-0">{post.excerpt}</p>
<a
class="group btn absolute bottom-0 w-full rounded-none"
class="group btn duration-150 absolute bottom-0 w-full rounded-none"
href={'/blog' + post.path.slice(11).slice(0, -3)}
><span
class="transition-all duration-500 relative inline-block after:transition-all after:duration-500 after:content-['»'] after:opacity-0 after:absolute after:top-0 after:right-[-20px] group-hover:pr-6 group-hover:after:opacity-100 group-hover:after:right-0"
class="transition-all duration-150 relative inline-block after:transition-all after:duration-500 after:content-['»'] after:opacity-0 after:absolute after:top-0 after:right-[-20px] group-hover:pr-6 group-hover:after:opacity-100 group-hover:after:right-0"
>Read More</span
></a
>
Expand Down
66 changes: 61 additions & 5 deletions app/src/lib/components/PostList.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,67 @@
<script lang="ts">
import type { Post } from '$lib/server/post.type';
import { themeStore } from '$lib/stores';
import PostComponent from './PostComponent.svelte';
export let postList: Post[];
// Carousel implementation
// Width of the carousel
let current_width = 0;
// Container for the carouusel items
let container: HTMLElement;
// ????
let scroll_left = 0;
let scroll_width = 0;
// Scroll left to the next item
function left() {
container.scrollBy(-current_width, 0);
}
// Scroll right to the next item
function right() {
container.scrollBy(current_width, 0);
}
function scroll() {
scroll_left = container.scrollLeft;
scroll_width = container.scrollWidth;
}
</script>

<div class="grid grid-cols-1 gap-x-4 gap-y-4 py-4 md:grid-cols-2 md:gap-x-[2%]">
{#each postList as post}
<PostComponent {post} />
{/each}
</div>
{#if postList.length >= 1}
<div class="flex overflow-hidden justify-between w-full">
<button
class="dark:text-cansat-black dark:bg-cansat-cream text-cansat-cream bg-cansat-grey border-cansat-cream border-2 rounded-none rounded-l border-none p-4"
on:pointerdown={left}
style="background-color: {scroll_left == 0 ? '#b7b3a7' : $themeStore ? '#58595b' : '#fffde9'}"
>
<slot name="left_button">&lt;</slot>
</button>
<div
class="flex flex-grow overflow-auto overflow-x-auto snap-x snap-mandatory scroll-smooth [&>*]:snap-start [&>*]:flex-shrink-0 [&>*]:w-full [&::-webkit-scrollbar]:hidden"
bind:clientWidth={current_width}
bind:this={container}
on:scroll={scroll}
>
{#each postList as post}
<PostComponent {post} />
{/each}
</div>
<button
class="dark:text-cansat-black dark:bg-cansat-cream text-cansat-cream bg-cansat-grey border-cansat-cream border-2 rounded-none rounded-r border-none p-4"
on:pointerdown={right}
style="background-color: {Math.abs(scroll_left + current_width - scroll_width) < 3
? '#b7b3a7'
: $themeStore
? '#58595b'
: '#fffde9'}"
>
<slot name="right_button">&gt;</slot>
</button>
</div>
{:else}
<h4 class="no-underline text-center py-10">
Até à data não temos <em>posts</em>, mas estejam preparados para futuras publicações.
</h4>
{/if}
10 changes: 8 additions & 2 deletions app/src/lib/components/ThemeToggle.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@
<circle cx={$cx} cy={$cy} r="9" fill="black" />
</mask>

<circle cx="12" cy="12" r={$r} fill="#fffde9" mask="url(#myMask2)" />
<g stroke="#fffde9" opacity={$opacity}>
<circle
cx="12"
cy="12"
r={$r}
fill={$themeStore ? '#fffde9' : '#231f20'}
mask="url(#myMask2)"
/>
<g stroke={$themeStore ? '#fffde9' : '#231f20'} opacity={$opacity}>
<line x1="12" y1="1" x2="12" y2="3" />
<line x1="12" y1="21" x2="12" y2="23" />
<line x1="4.22" y1="4.22" x2="5.64" y2="5.64" />
Expand Down
2 changes: 2 additions & 0 deletions app/src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ import { writable } from 'svelte/store';

// Give all the app access to the current theme
export const themeStore = writable(true);
// Flag for a small device (width < 700px)
export const isSmallDevice = writable(false);
7 changes: 0 additions & 7 deletions app/src/posts/tmp.md

This file was deleted.

Loading

0 comments on commit ba762d6

Please sign in to comment.