-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature!: Add support for third-party templating languages (#62)
* feat!: remove hook and refactor to virtual module BREAKING CHANGE: This deprecates the `useSanityClient` hook and exposes `sanityClient` on the 'sanity:client' module * chore: put studio on virtual module (`sanity:studio`) * chore: update examples for new imports * fix(readme): update documentation for new module names * chore: tidy up
- Loading branch information
Showing
20 changed files
with
156 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* A dynamic Newsbar that fetches content live from Sanity. | ||
* | ||
*/ | ||
import { useState, useEffect, useCallback } from "react"; | ||
import { sanityClient } from "sanity:client"; | ||
|
||
export function NewsBar() { | ||
const [news, setNews] = useState({ message: "Loading news…" }); | ||
const client = sanityClient; | ||
const getNews = useCallback(async () => { | ||
const response = await client.fetch( | ||
`*[_type == "sanityIoSettings"][0].banner` | ||
); | ||
setNews(response || { message: "no news" }); | ||
}, [client]); | ||
|
||
useEffect(() => { | ||
getNews(); | ||
}, [getNews]); | ||
|
||
return ( | ||
<marquee style={{ background: "blue", padding: "1em" }}> | ||
<a style={{ color: "white" }} href={`https://www.sanity.io/${news.link}`}> | ||
{news.message} | ||
</a> | ||
</marquee> | ||
); | ||
} |
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,21 +1,20 @@ | ||
--- | ||
import imageUrlBuilder from "@sanity/image-url"; | ||
import {useSanityClient} from "@sanity/astro" | ||
import {sanityClient} from "sanity:client" | ||
const client = useSanityClient() | ||
const builder = imageUrlBuilder(client) | ||
const builder = imageUrlBuilder(sanityClient) | ||
const {node} = Astro.props | ||
const { width = 960 } = Astro.props | ||
// See https://www.sanity.io/docs/presenting-images for general documentation on | ||
// presenting images, and https://www.sanity.io/docs/image-url for specifics on | ||
// this builder API | ||
const image = builder | ||
const image = node && builder | ||
.image(node) | ||
.width(width) | ||
.fit('max') | ||
.auto('format') | ||
--- | ||
|
||
<img src={image.url()} alt={node.alt || ""} title={node.alt} /> | ||
{image && <img src={image.url()} alt={node.alt || ""} title={node.alt} />} |
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,27 +1,19 @@ | ||
--- | ||
import { useSanityClient } from "@sanity/astro"; | ||
import { sanityClient } from "sanity:client"; | ||
import Layout from "../layouts/Layout.astro"; | ||
const client = useSanityClient(); | ||
const posts = await client.fetch(`*[_type == "post" && defined(publishedAt)] | order(publishedAt desc)`); | ||
const posts = await sanityClient.fetch(`*[_type == "post" && defined(publishedAt)] | order(publishedAt desc)`); | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Sanity.io blog</title> | ||
</head> | ||
<body> | ||
<Layout title="Sanity.io blog"> | ||
<h1>Sanity.io blog</h1> | ||
<ul> | ||
{posts.map((post) => ( | ||
<li>, | ||
{posts.map((post: any) => ( | ||
<li> | ||
<a href={'/posts/' + post.slug.current} class="post-link"> | ||
{post.title} | ||
</a> | ||
</li> | ||
))} | ||
</body> | ||
</html> | ||
</ul> | ||
</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
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,29 @@ | ||
/** | ||
* A dynamic Newsbar that fetches content live from Sanity. | ||
* | ||
*/ | ||
import { useState, useEffect, useCallback } from "react"; | ||
import { sanityClient } from "sanity:client"; | ||
|
||
export function NewsBar() { | ||
const [news, setNews] = useState({ message: "Loading news…" }); | ||
const client = sanityClient; | ||
const getNews = useCallback(async () => { | ||
const response = await client.fetch( | ||
`*[_type == "sanityIoSettings"][0].banner` | ||
); | ||
setNews(response || { message: "no news" }); | ||
}, [client]); | ||
|
||
useEffect(() => { | ||
getNews(); | ||
}, [getNews]); | ||
|
||
return ( | ||
<marquee style={{ background: "blue", padding: "1em" }}> | ||
<a style={{ color: "white" }} href={`https://www.sanity.io/${news.link}`}> | ||
{news.message} | ||
</a> | ||
</marquee> | ||
); | ||
} |
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,21 +1,21 @@ | ||
--- | ||
import imageUrlBuilder from "@sanity/image-url"; | ||
import {useSanityClient} from "@sanity/astro" | ||
import { sanityClient } from "sanity:client"; | ||
const client = useSanityClient() | ||
const builder = imageUrlBuilder(client) | ||
const builder = imageUrlBuilder(sanityClient) | ||
const {node} = Astro.props | ||
const { width = 960 } = Astro.props | ||
// See https://www.sanity.io/docs/presenting-images for general documentation on | ||
// presenting images, and https://www.sanity.io/docs/image-url for specifics on | ||
// this builder API | ||
const image = builder | ||
const image = node && builder | ||
.image(node) | ||
.width(width) | ||
.fit('max') | ||
.auto('format') | ||
--- | ||
|
||
<img src={image.url()} alt={node.alt || ""} title={node.alt} /> | ||
{image && <img src={image.url()} alt={node.alt || ""} title={node.alt} />} |
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,27 +1,19 @@ | ||
--- | ||
import { useSanityClient } from "@sanity/astro"; | ||
import {sanityClient} from "sanity:client"; | ||
import Layout from "../layouts/Layout.astro"; | ||
const client = useSanityClient(); | ||
const posts = await client.fetch(`*[_type == "post" && defined(publishedAt)] | order(publishedAt desc)`); | ||
const posts = await sanityClient.fetch(`*[_type == "post" && defined(publishedAt)] | order(publishedAt desc)`); | ||
--- | ||
|
||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width" /> | ||
<meta name="generator" content={Astro.generator} /> | ||
<title>Sanity.io blog</title> | ||
</head> | ||
<body> | ||
<Layout title="Sanity.io blog"> | ||
<h1>Sanity.io blog</h1> | ||
<ul> | ||
{posts.map((post: any) => ( | ||
<li>, | ||
<li> | ||
<a href={'/posts/' + post.slug.current} class="post-link"> | ||
{post.title} | ||
</a> | ||
</li> | ||
))} | ||
</body> | ||
</html> | ||
</ul> | ||
</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
Oops, something went wrong.
0e213cb
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:
sanity-astro-example-ssr – ./apps/example-ssr
sanity-astro-example-ssr.sanity.build
sanity-astro-example-ssr-git-main.sanity.build