Skip to content

Commit

Permalink
update storyblok fetch functions
Browse files Browse the repository at this point in the history
  • Loading branch information
GFier committed Jan 7, 2025
1 parent 5a269d8 commit b039d38
Show file tree
Hide file tree
Showing 12 changed files with 2,865 additions and 2,874 deletions.
19 changes: 8 additions & 11 deletions .husky/_/post-merge
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ call_lefthook()
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook.exe -h >/dev/null 2>&1
elif lefthook -h >/dev/null 2>&1
then
lefthook.exe "$@"
elif lefthook.bat -h >/dev/null 2>&1
then
lefthook.bat "$@"
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe"
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe"
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe"
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe" "$@"
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
Expand Down
19 changes: 8 additions & 11 deletions .husky/_/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ call_lefthook()
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook.exe -h >/dev/null 2>&1
elif lefthook -h >/dev/null 2>&1
then
lefthook.exe "$@"
elif lefthook.bat -h >/dev/null 2>&1
then
lefthook.bat "$@"
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe"
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe"
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe"
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe" "$@"
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
Expand Down
19 changes: 8 additions & 11 deletions .husky/_/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@ call_lefthook()
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook.exe -h >/dev/null 2>&1
elif lefthook -h >/dev/null 2>&1
then
lefthook.exe "$@"
elif lefthook.bat -h >/dev/null 2>&1
then
lefthook.bat "$@"
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe"
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe"
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook.exe" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe"
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook-${osArch}-${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook.exe" "$@"
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
Expand Down
6 changes: 3 additions & 3 deletions app/(pages)/storyblok/(component)/tutorial/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import s from './tutorial.module.css'
// - Draft mode

export function Tutorial() {
const { story } = useStoryblokContext()

const content = story?.content
const {
story: { content },
} = useStoryblokContext()

return (
<div className={s.tutorial} {...storyblokEditable(content)}>
Expand Down
6 changes: 3 additions & 3 deletions app/(pages)/storyblok/[slug]/(component)/article/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useStoryblokContext } from '~/libs/storyblok/context'
import s from './article.module.css'

export function Article() {
const { story } = useStoryblokContext()

const content = story?.content
const {
story: { content },
} = useStoryblokContext()

if (!content) return

Expand Down
67 changes: 23 additions & 44 deletions app/(pages)/storyblok/[slug]/page.jsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,29 @@
import { draftMode } from 'next/headers'
import { notFound } from 'next/navigation'
import { Wrapper } from '~/app/(pages)/(components)/wrapper'
import { StoryblokApi } from '~/libs/storyblok'
import { fetchAll, fetchStoryblokStory } from '~/libs/storyblok'
import { StoryblokContextProvider } from '~/libs/storyblok/context'
import { Wrapper } from '../../(components)/wrapper'
import { Article } from './(component)/article'
import s from './article-page.module.css'

// https://nextjs.org/docs/app/api-reference/functions/generate-static-params
const SLUG = 'cdn/stories/blog'

export async function generateStaticParams() {
const { data } = await new StoryblokApi({
draft: true,
}).get('cdn/stories/', {
const { data } = await fetchAll('cdn/stories', {
starts_with: 'blog',
})

const stories = data?.stories

return stories?.map(({ slug }) => ({ slug }))
return data.map(({ slug }) => ({ slug }))
}

export default async function StoryblokSubPage({ params }) {
const _draftMode = await draftMode()
const isDraftMode =
_draftMode.isEnabled || process.env.NODE_ENV === 'development'

const { data } = await new StoryblokApi({
draft: isDraftMode,
})
.get(`cdn/stories/blog/${params.slug}`, {
resolve_relations: [],
})
.catch(() => notFound())
const { slug } = await params
const { data } = await fetchStoryblokStory(`${SLUG}/${slug}`)

const content = data?.story?.content

if (!content) return
if (!data) return notFound()

return (
<StoryblokContextProvider story={data.story} options={{}}>
<StoryblokContextProvider {...data}>
<Wrapper theme="red" className={s.page}>
<div className={s.inner}>
<Article />
Expand All @@ -51,33 +36,27 @@ export default async function StoryblokSubPage({ params }) {
// https://nextjs.org/docs/app/api-reference/functions/generate-metadata

export async function generateMetadata({ params }) {
const _draftMode = await draftMode()
const isDraftMode =
_draftMode.isEnabled || process.env.NODE_ENV === 'development'

const { data } = await new StoryblokApi({
draft: isDraftMode,
}).get(`cdn/stories/blog/${params.slug}`)

const content = data?.story?.content?.metadata?.[0]
const { slug } = await params
const { data } = await fetchStoryblokStory(`${SLUG}/${slug}`)
const metadata = data?.story?.content?.metadata?.[0]

if (!content) return
if (!metadata) return

return {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
keywords: content?.keywords?.value,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
keywords: metadata?.keywords?.value,
openGraph: {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
url: process.env.NEXT_PUBLIC_BASE_URL,
},
twitter: {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
},
}
}
61 changes: 20 additions & 41 deletions app/(pages)/storyblok/page.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,18 @@
import { draftMode } from 'next/headers'
import { notFound } from 'next/navigation'
import { Wrapper } from '~/app/(pages)/(components)/wrapper'
import { StoryblokApi } from '~/libs/storyblok'
import { fetchStoryblokStory } from '~/libs/storyblok'
import { StoryblokContextProvider } from '~/libs/storyblok/context'
import { Wrapper } from '../(components)/wrapper'
import { Tutorial } from './(component)/tutorial'
import s from './storyblok.module.css'

export default async function Storyblok() {
const _draftMode = await draftMode()
const isDraftMode =
_draftMode.isEnabled || process.env.NODE_ENV === 'development'

const { data } = await new StoryblokApi({
draft: isDraftMode,
})
.get('cdn/stories/home', {
resolve_relations: [],
})
.catch(() => {
notFound()
})
const SLUG = 'cdn/stories/home'

const content = data?.story?.content
export default async function Storyblok() {
const { data } = await fetchStoryblokStory(SLUG)

if (!content) return
if (!data) return notFound()

return (
<StoryblokContextProvider story={data.story} options={{}}>
<StoryblokContextProvider {...data}>
<Wrapper theme="red" className={s.page}>
<div className={s.inner}>
<Tutorial />
Expand All @@ -38,33 +24,26 @@ export default async function Storyblok() {

// https://nextjs.org/docs/app/api-reference/functions/generate-metadata
export async function generateMetadata() {
const _draftMode = await draftMode()
const isDraftMode =
_draftMode.isEnabled || process.env.NODE_ENV === 'development'

const { data } = await new StoryblokApi({
draft: isDraftMode,
}).get('cdn/stories/home')

const content = data?.story?.content?.metadata?.[0]
const { data } = await fetchStoryblokStory(SLUG)
const metadata = data?.story?.content?.metadata?.[0]

if (!content) return
if (!metadata) return

return {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
keywords: content?.keywords?.value,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
keywords: metadata?.keywords?.value,
openGraph: {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
url: process.env.NEXT_PUBLIC_BASE_URL,
},
twitter: {
title: content?.title,
description: content?.description,
images: content?.image?.filename,
title: metadata?.title,
description: metadata?.description,
images: metadata?.image?.filename,
},
}
}
Loading

1 comment on commit b039d38

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚡️ Lighthouse report for the changes in this commit:

🟠 Performance: 79
🟢 Accessibility: 90
🟢 Best practices: 96
🟠 SEO: 63

Lighthouse ran on https://satus-25fdqz1qe-darkroom-engineering.vercel.app/

Please sign in to comment.