Skip to content

Commit

Permalink
feat: Rework post/proj list styles
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Nov 7, 2023
1 parent d620599 commit f7733ad
Show file tree
Hide file tree
Showing 17 changed files with 168 additions and 284 deletions.
1 change: 0 additions & 1 deletion elixir-api/lib/routes/api/v1/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ defmodule Router.Api.V1.Project do
"date",
"images",
"links",
"language",
"github",
%{
"tags[]" => [
Expand Down
1 change: 0 additions & 1 deletion elixir-api/lib/routes/api/v1/projects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ defmodule Router.Api.V1.Projects do
"views",
"images",
"links",
"language",
"github",
%{
"tags[]" => [
Expand Down
6 changes: 0 additions & 6 deletions sanity-cms/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ export default {
],
validation: (Rule: Rule) => Rule.max(4)
},
{
name: 'language',
title: 'Language',
type: 'string',
description: 'Primary language used in project'
},
{
name: 'github',
title: 'Github Link',
Expand Down
8 changes: 7 additions & 1 deletion svelte-app/src/components/about/timeline-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
}
p {
@apply font-mono text-base transition-colors;
@apply text-right font-mono text-base text-dark/80 transition-colors;
}
}
Expand All @@ -52,5 +52,11 @@
h2 {
@apply text-white;
}
div {
p {
@apply text-light/80;
}
}
}
</style>
145 changes: 60 additions & 85 deletions svelte-app/src/components/document/content/common/header.svelte
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
<script lang="ts">
import { derived } from 'svelte/store';
import { formatDate, getReadingTime } from '$helpers/date';
import { getTotalWords } from '$helpers/pt';
import { currentLang, linkTo, t } from '$i18n';
import { isMobile } from '$lib/helpers/responsive';
import { parseViews } from '$lib/views';
import BulletPoint from '$components/bullet-point.svelte';
import ArrowButton from '$components/controls/arrow-button.svelte';
import Divider from '$components/divider.svelte';
import PostHeader from '$components/document/content/post/header.svelte';
import ProjectHeader from '$components/document/content/project/header.svelte';
import Icon from '$components/icon.svelte';
import Link from '$components/link.svelte';
import ImageCarousel from '$components/portable-text/image-carousel.svelte';
Expand All @@ -21,96 +18,74 @@
images: ProjectImage[] | undefined,
model = data._type;
const readingTime = getReadingTime(getTotalWords((data?.body ?? []) as PTBlock[])),
parsedViews = derived(currentLang, (currentLang) => {
if (!data.views || data.views < 1) {
return 0;
}
try {
const parser = new Intl.NumberFormat(currentLang, {
notation: 'compact',
compactDisplay: 'short'
});
return parser.format(data.views);
} catch {
return data.views;
}
});
const readingTime = getReadingTime(getTotalWords((data?.body ?? []) as PTBlock[]));
$: date = formatDate(data.date, 'full', $currentLang);
</script>

<div data-test-id="{model}-header">
<div class="flex flex-col">
<svelte:component this={model === 'post' ? PostHeader : ProjectHeader}>
<svelte:fragment slot="title">
<h1>{data.title}</h1>
</svelte:fragment>
<svelte:fragment slot="meta">
<div class="flex flex-row flex-wrap items-center justify-between gap-4">
<div
class="flex flex-row flex-wrap items-center justify-start gap-y-2 transition-[color]"
>
<p class="cursor-default font-mono text-base">
{date ? date : $t('Unknown date')}
</p>
{#if data._type === 'post'}
<BulletPoint />
<p class="cursor-default font-mono text-base">
{$t('{length} min read', { length: Math.floor(readingTime / 60) })}
</p>
{#if data.views}
<BulletPoint />
<p class="cursor-default font-mono text-base">
{$t('{views} views', { views: $parsedViews })}
</p>
{/if}
{:else if data.github}
<BulletPoint />
<span class="font-mono text-base">
<Link href={data.github}>
{'github/' + data.github.split('github.com/')?.[1]}
</Link>
</span>
{/if}
</div>
<ArrowButton
class="focusOutline-sm -mb-1 hidden flex-1 whitespace-nowrap rounded-sm text-right sm:block"
href={model === 'post' ? $linkTo('/blog') : $linkTo('/work')}
preload
>
<span class="flex items-center justify-end gap-2 text-base">
{#key $isMobile}
<Icon icon={$isMobile ? 'ArrowUp' : 'ArrowLeft'} class="mb-0.5" inline />
{/key}
<p>{$t('Read more')}</p>
<h1>{data.title}</h1>

<div class="flex flex-row flex-wrap items-center justify-between gap-4">
<div
class="flex flex-row flex-wrap items-center justify-start gap-y-2 transition-[color]"
>
<p class="cursor-default font-mono text-base">
{date ? date : $t('Unknown date')}
</p>
<BulletPoint />
<p class="cursor-default font-mono text-base">
{$t('{length} min read', { length: Math.floor(readingTime / 60) })}
</p>
<BulletPoint />
<p class="cursor-default font-mono text-base">
{$t('{views} views', { views: $parseViews(data.views) })}
</p>
</div>
<ArrowButton
class="focusOutline-sm -mb-1 hidden flex-1 whitespace-nowrap rounded-sm text-right sm:block"
href={model === 'post' ? $linkTo('/blog') : $linkTo('/work')}
preload
>
<span class="flex items-center justify-end gap-2 text-base">
{#key $isMobile}
<Icon icon={$isMobile ? 'ArrowUp' : 'ArrowLeft'} class="mb-0.5" inline />
{/key}
<p>{$t('Read more')}</p>
</span>
</ArrowButton>
</div>
{#if data._type === 'project' && (data.tags?.length || data.github)}
<Divider />
<div class="flex flex-row flex-wrap items-center justify-start gap-0.5 text-base">
{#if data._type === 'project' && data.tags?.length}
<div class="flex flex-row flex-wrap items-center justify-start gap-2">
{#each data.tags as tag}
<span
class="cursor-default rounded-sm bg-dark/10 px-1.5 py-0.5 font-code text-base transition-colors dark:bg-light/10"
>
{tag.title.toLowerCase()}
</span>
</ArrowButton>
{/each}
</div>
</svelte:fragment>
{#if data._type === 'project' && images?.length}
<Divider />
<ImageCarousel {images} />
{/if}
{#if data._type === 'project' && data.tags?.length}
<Divider />
<div class="flex flex-row items-center justify-start gap-4">
<Icon icon="Label" class="ml-1" />
<div class="flex flex-row flex-wrap items-center justify-start gap-2">
{#each data.tags as tag}
<span
class="cursor-default rounded-sm border border-dark/60 px-1.5 py-0.5 font-mono text-sm transition-colors dark:border-light/60"
>
{tag.title}
</span>
{/each}
</div>
</div>
{#if data.tags?.length && data._type === 'project' && data.github}
<BulletPoint />
{/if}
</svelte:component>
</div>
{#if data._type === 'project' && data.github}
<span class="font-mono">
<Link href={data.github}>
{'github/' + data.github.split('github.com/')?.[1]}
</Link>
</span>
{/if}
</div>
{/if}

{#if data._type === 'project' && images?.length}
<Divider />
<ImageCarousel {images} />
{/if}
</div>

<style lang="scss">
Expand Down
11 changes: 8 additions & 3 deletions svelte-app/src/components/footer.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import { t } from '$i18n';
import { APP_VERSION } from '$lib/env';
import Divider from '$components/divider.svelte';
import Icon from './icon.svelte';
import Icon from '$components/icon.svelte';
import type { SiteConfig } from '$types';
Expand Down Expand Up @@ -38,6 +38,7 @@
target="_blank"
rel="noopener noreferrer"
href="https://github.com/kiosion/kio.dev/commit/{APP_VERSION}"
aria-label={$t('View latest commit on GitHub')}
>
<Icon icon="GitCommit" inline />
{APP_VERSION.slice(0, 6)}
Expand All @@ -63,12 +64,14 @@
}
a {
@apply text-dark/80;
@apply rounded-sm text-dark/80;
&:hover,
&:focus-visible {
@apply text-accent-light;
}
@include focus-state(sm);
}
.version {
Expand All @@ -89,6 +92,8 @@
&:focus-visible {
@apply text-accent-dark;
}
@include focus-state(sm, dark);
}
}
</style>
89 changes: 38 additions & 51 deletions svelte-app/src/components/lists/list-item.svelte
Original file line number Diff line number Diff line change
@@ -1,76 +1,63 @@
<script lang="ts">
import { currentLang, linkTo, t } from '$i18n';
import { formatDate } from '$lib/helpers/date';
import { parseViews } from '$lib/views';
import BulletPoint from '$components/bullet-point.svelte';
import Hoverable from '$components/hoverable.svelte';
import type { PostDocument, ProjectDocument } from '$types';
export let document: PostDocument | ProjectDocument,
type = document._type,
external = document._type === 'project' ? document.external : false,
small = false;
let hovered = false;
const link =
document._type === 'post'
? `/blog/${document.slug.current}`
: external
? document.externalUrl ?? `/work/${document.slug.current}`
: `/work/${document.slug.current}`;
</script>

<Hoverable bind:hovered>
{#if small}
<a
href={$linkTo(link)}
target={external ? '_blank' : undefined}
class="focusOutline flex w-full flex-row items-start justify-start gap-2 rounded-sm"
tabindex="0"
data-sveltekit-preload-code
data-sveltekit-preload-data
<a
href={$linkTo(link)}
class="focusOutline w-full rounded-md"
tabindex="0"
data-sveltekit-preload-code
data-sveltekit-preload-data
>
<div
class="mt-0.5 flex flex-row items-center justify-start font-mono text-sm text-dark/80 transition-colors dark:text-light/80 {small
? 'mb-1.5'
: 'mb-2'}"
class:gap-3={document.tags?.length}
class:gap-0.5={!document.tags?.length}
>
<p
class="mt-0.5 block w-[72px] flex-shrink-0 font-mono text-sm transition-colors"
aria-label={$t('Date posted')}
>
{formatDate(document.date || document._createdAt, 'med', $currentLang)}
<p aria-label={$t('Date posted')}>
{formatDate(document.date || document._createdAt, 'dayMonth', $currentLang)}
</p>
<p
class="block text-base text-black decoration-accent-light decoration-2 underline-offset-2 transition-colors dark:text-white dark:decoration-accent-dark"
class:underline={hovered}
>
{document.title}
</p>
</a>
{:else}
<a
href={$linkTo(link)}
target={external ? '_blank' : undefined}
class="focusOutline flex w-full flex-col items-start justify-start gap-2 rounded-md"
tabindex="0"
data-sveltekit-preload-code
data-sveltekit-preload-data
{#if document.tags?.length}
<span
class="rounded-sm bg-dark/10 px-1.5 py-0.5 font-code text-sm transition-colors dark:bg-light/10"
>{document.tags[0].title.toLowerCase()}</span
>
{:else}
<BulletPoint />
{/if}
<p>{$t('{views} views', { views: $parseViews(document.views) })}</p>
</div>

<h1
class="min-w-fit font-display font-medium decoration-accent-light decoration-[3px] underline-offset-4 transition-colors dark:decoration-accent-dark {small
? 'text-lg decoration-2 underline-offset-2'
: 'text-xl decoration-[3px] underline-offset-4'}"
class:underline={hovered}
>
<div class="flex flex-row gap-4">
<p class="mt-0.5 block w-14 flex-shrink-0 font-code text-base transition-colors">
{formatDate(document.date || document._createdAt, 'dayMonth', $currentLang)}
</p>
<div class="flex flex-row items-center justify-start gap-2 transition-colors">
<h1
class="min-w-fit font-display text-lg font-medium decoration-accent-light decoration-[3px] underline-offset-4 dark:decoration-accent-dark"
class:underline={hovered}
>
{document.title}
</h1>
{#if type === 'project' && document.desc}
<BulletPoint class="flex-shrink-0" />
<p class="line-clamp-1 text-base">{document.desc}</p>
{/if}
</div>
</div>
</a>
{/if}
{document.title}
</h1>
{#if document.desc?.length && !small}
<p class="mt-2 line-clamp-1 text-base">{document.desc}</p>
{/if}
</a>
</Hoverable>
Loading

0 comments on commit f7733ad

Please sign in to comment.