Using now() to generate dates
You can use now()
in GROQ queries to get the current date and time (ISO string). Ideas:
💡 Idea: Use this to create a simple content calendar with a publishTime
field in articles.
Ideas on how to use Sanity.io to its best. Have one you'd like to share or something is unclear?
Reach out at @hdorodev 😉
You can use now()
in GROQ queries to get the current date and time (ISO string). Ideas:
💡 Idea: Use this to create a simple content calendar with a publishTime
field in articles.
If you want custom fine-grained ordering for your GROQ query, you can use `select` and conditionals to generate a priority/ranking number. Ideas:
💡 Surface most important support tickets
💡 Show in-season products before others
💡 Featured items before others
Document-wide validations can provide context-aware checking for better content. Ideas:
💡 prevent publishing if no keyword is found in headline
💡 make sure a featured product has at least 3 testimonials
💡 run a sentiment analysis & alert if disparate from style guide
You can use read-only fields with custom components to display information to editors
💡 Onboard editors with tooltips
💡 Let them know about a specific aspect of the document they're in
💡 Display data to inform their decisions
Changing field values, formats and/or types across multiple documents? You can skip manual editing without writing code with @sanity/client
.
Use sanity documents create updated-data.json --replace
for quick data manipulation.
For complex content structures, "namespacing" schema _types is proving to be super helpful for clarity and maintainability!
📃 Blog example: blog.post
, blog.author
, blog.category
🔊 Podcast example: podcast.episode
, podcast.sponsor
, etc.
If you use VS Code to write your code, you can speed up your workflow with the Sanity snippets extension.
No more tedious typing of name: "field", type: "string"
... Unlock the power of tab tab tab tab
Add descriptive names to text styles in the rich text editor to make it easier for editors to pick between them.
Besides better on-boarding, this will improve the accessibility and SEO of your content ✨
Credit goes to Ryan Murray @3200pro for the inspiration 🙌
If you access the Sanity.io website on a regular basis to check on documentation/tools/guides, your life will get a bit easier now:
🔍 Search the entire Sanity.io website from your browser's address bar in seconds (works on Chromium & Firefox browsers). Demo with Brave here.
For chromium browsers, you'll need to open the website at least once. Then, next time you type http://sanity.io in your address bar, press tab to turn that into a site search.
For Firefox, the process is a bit different, follow the video here.
Guide and warn editors without removing their freedom with Rule.custom(...).warning()
.
💡 Letting them know page content should finish with a newsletter form
💡 Warn when a given content combination doesn't work
💡 Fetch competitors' prices from API and warn if too high or too low
If you dislike Sanity's default way of writing schemas, you have alternatives! A couple of community packages to check out:
Simeon Griggs's quick fields: https://www.sanity.io/plugins/quick-fields
Rupert Dunk's sanity-schema-builder: https://www.npmjs.com/package/sanity-schema-builder
Espen Hovlandsdal's GraphQL schema: https://www.sanity.io/plugins/graphql-schema (thanks to Knut for the pointer on this)
Display images hosted in Sanity using auto=format
for better performance. Sanity will automatically pick the best format for that image given the user's browser capability. ✨
Eventually all of your images will be upgraded to AVIFF with no effort on your end!
Use Sanity environments in sanity.json
for differentiating between your development build and production.
💡 Enable the Vision plugin only in development
💡 Use a different dataset in production
💡 Different styles for each to prevent confusions
📚 Learn more in the docs for configuration environments.
When using the vision plugin to run queries, you can press CTRL/CMD + SPACE to open an autocomplete dialog to get a list of documents and objects implemented in your schema.
💡 Remember how you spelled a given document type
💡 Explore a schema you aren't familiar with
When developing two different Sanity projects, you can use sanity start --port 4444
to open another studio at the same time.
This is helping me a ton as I do plugin development, record tutorials & work on my own studio, hope it helps!
When getting a subset of documents in GROQ, beware of the dots!
[0..1]
is different than [0...1]
They determine whether or not to include the last item in the list. *Inclusive* slices will return it, whereas *non-inclusive* slices won't.
Play around with it in my interactive GROQ guide.
When customizing Sanity's default Portable Text rendering of blocks, you don't need to re-make the default serializer if using one of the official PT libraries (see code below)
💡 Easily add a centralized text paragraph style
💡 Add anchors to headings
💡 Style blockquotes
You can use JSX in field descriptions to add interactive & contextual documentation in @sanity_io
💡 Link to edit related documents
💡 (optional) videos w/ in-depth explanations
💡 Support chat widget
Credits to Rob Pyon for teaching me this!