Skip to content

Commit

Permalink
feat: Rework project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Nov 4, 2023
1 parent 9c42b70 commit 8ed93a3
Show file tree
Hide file tree
Showing 17 changed files with 358 additions and 72 deletions.
8 changes: 3 additions & 5 deletions elixir-api/lib/routes/api/v1/project.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,10 @@ defmodule Router.Api.V1.Project do
"body",
"desc",
"date",
"external",
"externalAuthor",
"externalLinks",
"externalUrl",
"image",
"images",
"links",
"language",
"github",
%{
"tags[]" => [
"_id",
Expand Down
8 changes: 3 additions & 5 deletions elixir-api/lib/routes/api/v1/projects.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,10 @@ defmodule Router.Api.V1.Projects do
"body",
"desc",
"date",
"external",
"externalAuthor",
"externalLinks",
"externalUrl",
"image",
"images",
"links",
"language",
"github",
%{
"tags[]" => [
"_id",
Expand Down
1 change: 1 addition & 0 deletions elixir-api/lib/routes/cdn.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defmodule Router.Cdn do
with {:ok, %HTTPoison.Response{status_code: 200, body: body}} <-
Hexerei.Env.get(:http_client, Hexerei.HTTP.DefaultClient).get(url) do
conn
|> put_resp_header("Access-Control-Allow-Origin", "*")
|> put_resp_content_type("image/#{url_parts.filetype}")
|> send_resp(200, body)
else
Expand Down
48 changes: 20 additions & 28 deletions sanity-cms/schemas/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,40 @@ export default {
type: 'document',
fields: [
...BaseDocument.filter((field) => field.name !== 'author'),
{
name: 'external',
title: 'External',
type: 'boolean',
description: 'Is this project hosted on an external site?',
initialValue: false,
validation: (Rule: Rule) => Rule.required()
},
{
name: 'externalUrl',
title: 'External URL',
type: 'url',
description: 'Link to external project'
},
{
name: 'author',
title: 'Author',
type: 'reference',
to: { type: 'author' }
},
{
name: 'externalAuthor',
title: 'External Author',
type: 'string',
description: 'Name of external author, if applicable'
},
{
name: 'image',
title: 'Project Image',
type: 'image',
options: {
hotspot: true
}
name: 'images',
title: 'Project Images',
type: 'array',
of: [
{
type: 'image',
options: {
hotspot: true
}
}
],
validation: (Rule: Rule) => Rule.max(4)
},
{
name: 'language',
title: 'Language',
type: 'string',
description: 'Primary programming language used in project'
description: 'Primary language used in project'
},
{
name: 'github',
title: 'Github Link',
type: 'url',
description: 'Github repository link'
},
{
name: 'externalLinks',
name: 'links',
title: 'External Links',
type: 'array',
of: [
Expand Down
14 changes: 7 additions & 7 deletions sanity-cms/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,20 @@ export const structure = (
.title('Projects')
.items([
S.listItem()
.title('Writeups')
.title('Published')
.icon(BsFillFileTextFill)
.child(
S.documentTypeList('project')
.title('Writeups')
.filter('_type == "project" && !external')
.title('Published')
.filter('_type == "project" && !(_id in path("drafts.**"))')
),
S.listItem()
.title('External')
.icon(BiLinkExternal)
.title('Drafts')
.icon(BsFillFileEarmarkTextFill)
.child(
S.documentTypeList('project')
.title('External')
.filter('_type == "project" && external == true')
.title('Drafts')
.filter('_type == "project" && _id in path("drafts.**")')
),
S.divider(),
S.listItem()
Expand Down
15 changes: 11 additions & 4 deletions svelte-app/src/components/context-menu/menu.svelte
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<script lang="ts">
import { createEventDispatcher, setContext } from 'svelte';
import { circIn, circOut } from 'svelte/easing';
import { blur } from 'svelte/transition';
import { fade } from 'svelte/transition';
import { BASE_ANIMATION_DURATION } from '$lib/consts';
import { setState } from '$lib/helpers/menu';
import { key } from './menu';
import { key } from '$components/context-menu/menu';
export let x: number;
export let y: number;
Expand Down Expand Up @@ -56,8 +57,14 @@

<div
style="top: {y}px; left: {x}px"
in:blur={{ duration: 200, easing: circOut }}
out:blur={{ duration: 200, easing: circIn }}
in:fade={{
duration: BASE_ANIMATION_DURATION * 0.5,
easing: circOut
}}
out:fade={{
duration: BASE_ANIMATION_DURATION * 0.5,
easing: circIn
}}
bind:this={menuElement}
>
<slot />
Expand Down
14 changes: 14 additions & 0 deletions svelte-app/src/components/document/content/common/footer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,28 @@
import { isMobile } from '$lib/helpers/responsive';
import ArrowButton from '$components/controls/arrow-button.svelte';
import Divider from '$components/divider.svelte';
import Icon from '$components/icon.svelte';
import Link from '$components/link.svelte';
import type { PostDocument, ProjectDocument } from '$types';
export let data: PostDocument | ProjectDocument,
model: 'post' | 'project' = data._type;
</script>

{#if data._type === 'project' && data.github}
<div>
<h1 class="my-4 font-display text-2xl font-bold">{$t('Links')}</h1>
<span class="flex items-center justify-start gap-2 text-base">
<Icon icon="ExternalLink" class="mb-0.5" inline />
<Link href={data.github}>
{'github/' + data.github.split('github.com/')?.[1]}
</Link>
</span>
</div>
<Divider />
{/if}
<div>
<ArrowButton
class="w-full text-left"
Expand Down
39 changes: 35 additions & 4 deletions svelte-app/src/components/document/content/common/header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
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';
import type { PostDocument, ProjectDocument, PTBlock } from '$types';
Expand All @@ -34,10 +37,19 @@
<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>
{#if data._type === 'post'}
<BulletPoint />
<p class="cursor-default font-mono text-base">
{$t('{length} min read', { length: Math.floor(readingTime / 60) })}
</p>
{: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 flex-1 whitespace-nowrap rounded-sm text-right"
Expand All @@ -53,6 +65,25 @@
</ArrowButton>
</div>
</svelte:fragment>
{#if data._type === 'project' && data.images?.length}
<Divider />
<ImageCarousel images={data.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}
</svelte:component>
</div>
</div>
Expand Down
10 changes: 2 additions & 8 deletions svelte-app/src/components/document/content/content.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
import EmptyContent from '$components/empty-content.svelte';
import PortableText from '$components/portable-text/portable-text.svelte';
import type {
DocumentHeadings,
PostDocument,
ProjectDocument,
RouteFetch
} from '$types';
import type { PostDocument, ProjectDocument, RouteFetch } from '$types';
export let data: PostDocument | ProjectDocument,
model = data._type,
headings: DocumentHeadings[] | undefined,
routeFetch: RouteFetch | undefined = undefined;
</script>

<Header {data} {headings} />
<Header {data} />
<Divider />
<div>
{#if data.body}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="relative z-[1]">
<slot name="title" />
<slot name="meta" />
<slot />
</div>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="relative z-[1]">
<slot name="title" />
<slot name="meta" />
<slot name="desc" />
<slot />
</div>
2 changes: 1 addition & 1 deletion svelte-app/src/components/document/route.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@
</svelte:head>

<ContentWrapper>
<Content {data} {headings} {routeFetch} />
<Content {data} />
</ContentWrapper>
5 changes: 4 additions & 1 deletion svelte-app/src/components/icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import { t } from '$i18n';
import icons from '$lib/icons';
export let icon: string,
import type { icons as iconsType } from '$lib/icons';
// eslint-disable-next-line @typescript-eslint/ban-types
export let icon: keyof typeof iconsType | (string & {}),
hovered = false,
inline = false,
width = 20,
Expand Down
Loading

0 comments on commit 8ed93a3

Please sign in to comment.