Skip to content

Commit

Permalink
✨ Add a rotating tagline component (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
NatoBoram authored Jan 15, 2024
1 parent 9c138a1 commit fd0b3d7
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
.env.*
.eslintignore
.eslintrc.cjs
.git
.github
.gitignore
.markdownlint.yaml
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FROM base AS prod-deps
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile

FROM base AS build
RUN apt update && apt install -y git && rm -rf /var/lib/apt/lists/*
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
RUN --mount=type=secret,id=BUILD_BASE BUILD_BASE="$(cat /run/secrets/BUILD_BASE)" BUILD_ADAPTER='node' pnpm run build

Expand Down
2 changes: 1 addition & 1 deletion src/lib/SiteSidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<br />

{#if site.sidebar}
<Prose class="mx-auto prose-a:text-primary" markdown={site.sidebar} />
<Prose class="prose-a:text-primary" markdown={site.sidebar} />
{/if}
</aside>
37 changes: 37 additions & 0 deletions src/lib/Taglines.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import TaglineSvelte from '$lib/Tagline.svelte'
import type { Tagline } from 'lemmy-js-client'
import { onMount } from 'svelte'
import { fly } from 'svelte/transition'
let className: string | undefined = undefined
export { className as class }
export let taglines: Tagline[]
// Start with a random tagline
let index = Math.floor(Math.random() * taglines.length)
$: tagline = taglines[index]
onMount(() => {
if (!taglines.length) return
// Get a random tagline every 10 seconds
const interval = setInterval(
() => (index = Math.floor(Math.random() * taglines.length)),
10_000,
)
return () => {
clearInterval(interval)
}
})
</script>

{#if tagline}
{#key tagline.id}
<div class={className} in:fly={{ duration: 300, x: 300 }}>
<TaglineSvelte {tagline} />
</div>
{/key}
{/if}
12 changes: 4 additions & 8 deletions src/routes/[site]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import LimitSelector from '$lib/LimitSelector.svelte'
import ListingTypeSelector from '$lib/ListingTypeSelector.svelte'
import PaginationBar from '$lib/PaginationBar.svelte'
import Posts from '$lib/posts/Posts.svelte'
import SiteSidebar from '$lib/SiteSidebar.svelte'
import SortSelector from '$lib/SortSelector.svelte'
import Tagline from '$lib/Tagline.svelte'
import Taglines from '$lib/Taglines.svelte'
import Posts from '$lib/posts/Posts.svelte'
import type { PageData } from './$types.js'
export let data: PageData
Expand Down Expand Up @@ -47,12 +47,8 @@
<!-- Main content -->
<main class="flex flex-grow flex-col gap-4 justify-self-stretch">
<!-- Taglines -->
<div class="flex flex-col gap-4">
{#if data.taglines}
{#each data.taglines as tagline (tagline.id)}
<Tagline {tagline} class="base-container rounded-md" />
{/each}
{/if}
<div class="base-container flex flex-col gap-4 rounded-md">
<Taglines taglines={data.taglines} />
</div>

<!-- Post form -->
Expand Down

0 comments on commit fd0b3d7

Please sign in to comment.