-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Service_Page schema and front-end code
- Loading branch information
1 parent
6d303d8
commit e8ac49a
Showing
10 changed files
with
99 additions
and
8 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
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
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 |
---|---|---|
@@ -1,15 +1,30 @@ | ||
export { default, type PortableTextValue } from './index.astro'; | ||
|
||
/** | ||
* GROQ query helper for Portable Text fields that ensures proper handling of text formatting | ||
* and link references. The coalesce() wrapper is crucial here because: | ||
* | ||
* 1. When duplicating Sanity documents with formatted text (bold, italic etc.), | ||
* the markDefs array sometimes doesn't get properly initialized | ||
* 2. This causes Astro's Portable Text renderer to throw "Cannot read properties | ||
* of null (reading 'find')" error when processing marks like 'strong' | ||
* 3. By using coalesce(), we ensure markDefs is always an array (falling back | ||
* to empty [] if null), preventing the runtime error | ||
* | ||
* @param name - The field name in your Sanity schema to query | ||
* @returns A GROQ query string that safely handles Portable Text fields | ||
*/ | ||
export const PortableTextQuery = (name: string) => ` | ||
${name}[] { | ||
..., | ||
markDefs[] { | ||
"markDefs": coalesce(markDefs[] { | ||
..., | ||
_type == "link" => { | ||
_type, | ||
_key, | ||
type, | ||
"href": select(type == "internal" => internal -> slug.current, type == "external" => external, "#"), | ||
linkType, | ||
"href": select(linkType == "internal" => internal -> slug.current, linkType == "external" => external, "#"), | ||
}, | ||
}, | ||
}, []), | ||
}, | ||
` |
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,24 @@ | ||
--- | ||
import Layout from '@layouts/Layout.astro' | ||
import metadataFetch from '@utils/metadata.fetch' | ||
import sanityFetch from '@utils/sanity.fetch' | ||
import Breadcrumbs from '@components/ui/Breadcrumbs.astro' | ||
import Components, { Components_Query, type ComponentsProps } from '@components/Components.astro' | ||
const metadata = await metadataFetch('/oferta') | ||
const data = await sanityFetch<{ name: string; slug: string; components: ComponentsProps }>({ | ||
query: ` | ||
*[_type == "Service_Page"][0] { | ||
"name": title, | ||
"slug": slug.current, | ||
${Components_Query} | ||
} | ||
`, | ||
}) | ||
--- | ||
|
||
<Layout {...metadata}> | ||
<Breadcrumbs data={[{ name: data.name, path: data.slug }]} /> | ||
<Components data={data.components} /> | ||
</Layout> |
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,41 @@ | ||
import { defineField, defineType } from "sanity" | ||
import { defineSlugForDocument } from "../../utils/define-slug-for-document"; | ||
|
||
const name = 'Service_Page'; | ||
const title = 'Oferta'; | ||
const slug = '/oferta'; | ||
const icon = () => '💼'; | ||
|
||
export default defineType({ | ||
name: name, | ||
type: 'document', | ||
title: title, | ||
icon, | ||
options: { documentPreview: true }, | ||
fields: [ | ||
...defineSlugForDocument({ slug: slug }), | ||
defineField({ | ||
name: 'components', | ||
type: 'components', | ||
title: 'Page Components', | ||
}), | ||
defineField({ | ||
name: 'seo', | ||
type: 'seo', | ||
title: 'SEO', | ||
group: 'seo', | ||
}), | ||
], | ||
groups: [ | ||
{ | ||
name: 'seo', | ||
title: 'SEO', | ||
}, | ||
], | ||
preview: { | ||
prepare: () => ({ | ||
title: title, | ||
subtitle: slug | ||
}) | ||
} | ||
}); |
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
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