-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from strideynet/use-sanity
Use Sanity for info site content
- Loading branch information
Showing
43 changed files
with
5,525 additions
and
825 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
web/info/src/components/portable-text/portable-text.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<script lang="ts"> | ||
import CodeSerializer from '$components/portable-text/serializers/code.svelte'; | ||
import FeedsSerializer from '$components/portable-text/serializers/feeds.svelte'; | ||
import HeadingSerializer from '$components/portable-text/serializers/heading.svelte'; | ||
import ImageSerializer from '$components/portable-text/serializers/image.svelte'; | ||
import LinkSerializer from '$components/portable-text/serializers/link.svelte'; | ||
import OlSerializer from '$components/portable-text/serializers/ordered-list.svelte'; | ||
import OlItemSerializer from '$components/portable-text/serializers/ordered-list-item.svelte'; | ||
import ParagraphSerializer from '$components/portable-text/serializers/paragraph.svelte'; | ||
import UlSerializer from '$components/portable-text/serializers/unordered-list.svelte'; | ||
import UlItemSerializer from '$components/portable-text/serializers/unordered-list-item.svelte'; | ||
import { PortableText } from '@portabletext/svelte'; | ||
import type { InputValue } from '@portabletext/svelte/ptTypes'; | ||
import type { FeedInfo } from '$types'; | ||
export let content: InputValue, | ||
feeds: { featured: FeedInfo[] | null; feeds: FeedInfo[] | null }; | ||
</script> | ||
|
||
<PortableText | ||
value={content} | ||
components={{ | ||
types: { | ||
feeds: FeedsSerializer, | ||
image: ImageSerializer | ||
}, | ||
marks: { | ||
link: LinkSerializer, | ||
code: CodeSerializer | ||
}, | ||
block: { | ||
normal: ParagraphSerializer, | ||
h1: HeadingSerializer, | ||
h2: HeadingSerializer, | ||
h3: HeadingSerializer, | ||
h4: HeadingSerializer, | ||
h5: HeadingSerializer | ||
}, | ||
list: { | ||
bullet: UlSerializer, | ||
number: OlSerializer | ||
}, | ||
listItem: { | ||
bullet: UlItemSerializer, | ||
number: OlItemSerializer, | ||
normal: UlItemSerializer | ||
} | ||
}} | ||
context={{ | ||
feeds | ||
}} | ||
/> |
16 changes: 16 additions & 0 deletions
16
web/info/src/components/portable-text/serializers/code.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<script lang="ts"> | ||
import type { MarkComponentProps } from '@portabletext/svelte'; | ||
export let portableText: MarkComponentProps; | ||
$: ({ markType } = portableText); | ||
$: ({ plainTextContent } = portableText); | ||
</script> | ||
|
||
{#if markType === 'code'} | ||
<code class="mx-0.5 rounded bg-gray-400 px-1 py-0.5 font-mono text-[0.95rem]" | ||
>{plainTextContent}</code | ||
> | ||
{:else} | ||
<slot /> | ||
{/if} |
23 changes: 23 additions & 0 deletions
23
web/info/src/components/portable-text/serializers/feeds.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script lang="ts"> | ||
import FeaturedList from '$components/feeds/featured-list.svelte'; | ||
import FeedList from '$components/feeds/list.svelte'; | ||
import type { CustomBlockComponentProps } from '@portabletext/svelte'; | ||
import type { FeedInfo } from '$types'; | ||
export let portableText: CustomBlockComponentProps<{ featured: boolean }>; | ||
$: ({ featured, feeds } = (portableText.global.context?.feeds as { | ||
featured: FeedInfo[]; | ||
feeds: FeedInfo[]; | ||
}) || { | ||
featured: null, | ||
feeds: null | ||
}); | ||
</script> | ||
|
||
{#if portableText.value.featured} | ||
<FeaturedList {feeds} {featured} /> | ||
{:else} | ||
<FeedList {feeds} /> | ||
{/if} |
47 changes: 47 additions & 0 deletions
47
web/info/src/components/portable-text/serializers/heading.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<script lang="ts"> | ||
import { toPlainText } from '@portabletext/svelte'; | ||
import type { BlockComponentProps } from '@portabletext/svelte'; | ||
export let portableText: BlockComponentProps; | ||
$: ({ value } = portableText); | ||
$: ({ style } = value as { style: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' }); | ||
$: plainText = toPlainText(value); | ||
</script> | ||
|
||
<svelte:element this={style}> | ||
<a id={value._key} href={`#${value._key}`}> | ||
{plainText} | ||
</a> | ||
</svelte:element> | ||
|
||
<style lang="scss"> | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5 { | ||
@apply font-bold text-gray-950; | ||
} | ||
h1 { | ||
@apply mb-6 mt-8 text-4xl; | ||
} | ||
h2 { | ||
@apply mb-5 mt-7 text-3xl; | ||
} | ||
h3 { | ||
@apply mb-4 mt-6 text-2xl; | ||
} | ||
h4 { | ||
@apply mb-3 mt-5 text-xl; | ||
} | ||
h5 { | ||
@apply mb-2 mt-4 text-lg; | ||
} | ||
</style> |
35 changes: 35 additions & 0 deletions
35
web/info/src/components/portable-text/serializers/image.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts"> | ||
import { getCrop, urlFor } from '$lib/sanity'; | ||
import type { CustomBlockComponentProps } from '@portabletext/svelte'; | ||
import type { ArbitraryTypedObject } from '@portabletext/types'; | ||
import type { ImageCrop } from '$lib/sanity'; | ||
import type { SanityImageObject } from '$types'; | ||
export let portableText: Omit<CustomBlockComponentProps, 'value'> & { | ||
value: ArbitraryTypedObject & { | ||
asset: SanityImageObject['asset']; | ||
}; | ||
}; | ||
let imageCrop: ImageCrop; | ||
$: ({ value } = portableText); | ||
$: ({ _key } = value); | ||
$: ({ _ref } = value.asset); | ||
$: (imageCrop = getCrop(value as unknown as SanityImageObject)), value; | ||
</script> | ||
|
||
<div class="h-fit w-full"> | ||
<img | ||
src={urlFor(_ref) | ||
.width(800) | ||
.rect(imageCrop.left, imageCrop.top, imageCrop.width, imageCrop.height) | ||
.fit('crop') | ||
.auto('format') | ||
.url()} | ||
class="select-none rounded-sm" | ||
alt={_key} | ||
draggable="false" | ||
/> | ||
</div> |
21 changes: 21 additions & 0 deletions
21
web/info/src/components/portable-text/serializers/link.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import type { MarkComponentProps } from '@portabletext/svelte'; | ||
export let portableText: MarkComponentProps; | ||
$: ({ value } = portableText); | ||
$: ({ plainTextContent } = portableText); | ||
$: href = value.href as string; | ||
$: _external = value.external as boolean; | ||
$: newtab = value.blank as boolean; | ||
</script> | ||
|
||
<a | ||
class="text-sky-600 underline-offset-1 focus-within:text-sky-700 focus-within:underline hover:text-sky-700 hover:underline" | ||
{href} | ||
target={newtab ? '_blank' : undefined} | ||
rel={newtab ? 'noopener noreferrer' : undefined} | ||
tabindex="0" | ||
> | ||
{plainTextContent} | ||
</a> |
11 changes: 11 additions & 0 deletions
11
web/info/src/components/portable-text/serializers/ordered-list-item.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import type { BlockComponentProps } from '@portabletext/svelte'; | ||
export let portableText: BlockComponentProps; | ||
$: ({ value: _value } = portableText); | ||
</script> | ||
|
||
<li> | ||
<slot /> | ||
</li> |
23 changes: 23 additions & 0 deletions
23
web/info/src/components/portable-text/serializers/ordered-list.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script lang="ts"> | ||
import type { BlockComponentProps } from '@portabletext/svelte'; | ||
export let portableText: BlockComponentProps; | ||
const getLevelClass = (level?: number) => { | ||
switch (level) { | ||
case 2: | ||
return 'list-[lower-alpha]'; | ||
case 3: | ||
return 'list-[lower-roman]'; | ||
default: | ||
return 'list-decimal'; | ||
} | ||
}; | ||
$: ({ value } = portableText); | ||
$: ({ level } = value); | ||
</script> | ||
|
||
<ol class="pt-ol my-6 ml-6 {getLevelClass(level)}"> | ||
<slot /> | ||
</ol> |
11 changes: 11 additions & 0 deletions
11
web/info/src/components/portable-text/serializers/paragraph.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import type { BlockComponentProps } from '@portabletext/svelte'; | ||
export let portableText: BlockComponentProps; | ||
$: ({ value } = portableText); | ||
</script> | ||
|
||
<p class="my-3 text-base"> | ||
<slot /> | ||
</p> |
11 changes: 11 additions & 0 deletions
11
web/info/src/components/portable-text/serializers/unordered-list-item.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import type { ListItemComponentProps } from '@portabletext/svelte'; | ||
export let portableText: ListItemComponentProps; | ||
$: ({ value: _value } = portableText); | ||
</script> | ||
|
||
<li> | ||
<slot /> | ||
</li> |
11 changes: 11 additions & 0 deletions
11
web/info/src/components/portable-text/serializers/unordered-list.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<script lang="ts"> | ||
import type { ListComponentProps } from '@portabletext/svelte'; | ||
export let portableText: ListComponentProps; | ||
$: ({ value: _value } = portableText); | ||
</script> | ||
|
||
<ul class="pt-ul my-6 ml-6 list-disc"> | ||
<slot /> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { SANITY_API_VERSION, SANITY_DATASET, SANITY_PROJECT_ID } from '$lib/constants'; | ||
|
||
import { createClient } from '@sanity/client'; | ||
import imageUrlBuilder from '@sanity/image-url'; | ||
|
||
import type { | ||
SanityImageObject, | ||
SanityImageSource | ||
} from '@sanity/image-url/lib/types/types'; | ||
import type { DocumentRegistry } from '$types'; | ||
|
||
const client = createClient({ | ||
projectId: SANITY_PROJECT_ID, | ||
dataset: SANITY_DATASET, | ||
useCdn: true, | ||
apiVersion: SANITY_API_VERSION | ||
}); | ||
|
||
export const getPageDocument = async <T extends string>( | ||
id: T, | ||
preview = false, | ||
token?: string | ||
) => { | ||
const localClient = token ? createClient({ ...client.config(), token }) : client; | ||
const query = `*[_type == "page" && id == "${id}"${ | ||
preview ? '' : ' && !(_id in path("drafts.**"))' | ||
}][0]`; | ||
const document = await localClient | ||
.fetch<T extends keyof DocumentRegistry ? DocumentRegistry[T] : never>(query) | ||
.then((response) => { | ||
const document = response; | ||
return document; | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
return undefined; | ||
}); | ||
|
||
return document; | ||
}; | ||
|
||
export interface ImageCrop { | ||
top: number; | ||
left: number; | ||
bottom: number; | ||
right: number; | ||
width: number; | ||
height: number; | ||
} | ||
|
||
const builder = imageUrlBuilder(client); | ||
|
||
export const urlFor = (source: SanityImageSource) => builder.image(source); | ||
|
||
export const getCrop = (image: SanityImageObject | undefined) => { | ||
if (!image || !image?.asset) { | ||
return { | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
width: 0, | ||
height: 0 | ||
}; | ||
} | ||
const ref = image.asset._ref, | ||
dimensions = ref?.split('-')?.[2]?.split('x'), | ||
crop: ImageCrop = { | ||
top: Math.floor(dimensions[1] * (image?.crop?.top ?? 0)), | ||
left: Math.floor(dimensions[0] * (image?.crop?.left ?? 0)), | ||
bottom: Math.floor(dimensions[1] * (image?.crop?.bottom ?? 0)), | ||
right: Math.floor(dimensions[0] * (image?.crop?.right ?? 0)) | ||
} as ImageCrop; | ||
|
||
crop.width = Math.floor(dimensions[0] - (crop.left + crop.right)); | ||
crop.height = Math.floor(dimensions[1] - (crop.top + crop.bottom)); | ||
|
||
return crop; | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { VALID_DOC_ROUTES } from '$lib/constants'; | ||
|
||
import type { ParamMatcher } from '@sveltejs/kit'; | ||
|
||
export const match: ParamMatcher = (param) => { | ||
return VALID_DOC_ROUTES.includes(param); | ||
}; |
Oops, something went wrong.
2f064d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
bsky-furry-feed-info – ./web/info
bsky-furry-feed-info-strideynet.vercel.app
bsky-furry-feed-info.vercel.app
bsky-furry-feed-info-git-main-strideynet.vercel.app
furryli.st