npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pezak/hui-sanity

v1.0.3

Published

Harry's UI (hui) sanity package. Configures @nuxtjs/sanity under the hood. Provides composables, etc. Depends on hui-i18n for localization of fields.

Downloads

193

Readme

hui-sanity

npm version npm downloads License Nuxt

Harry's UI (hui) sanity package. Configures @nuxtjs/sanity under the hood. Provides composables, etc.

Depends on hui-i18n for localization of fields, so you need to install and configure @pezak/hui-i18n in order to use the sanity module.

✨  Release Notes

Installation

Install the module to your Nuxt application with one command:

npx nuxi module add @pezak/hui-sanity

Sanity Config

In your /config folder create a sanity.config.ts to configure the hui module and @nuxtjs/sanity used behind-the-scenes.

Update id to point to your project and apiVersion to today's date.

export default {
  projectId: "8m33196t",
  apiVersion: "2024-04-01",
  dataset: "production",
};

The package automatically loads this file and does the rest. If you need more custom config you can use the module key huiSanity.

Usage

You can import multiple types from @pezak/hui-sanity/types such as SanityDocument, SanityImage, SanityPage.

Most frequently used queries are provided from @pezak/hui-sanity/query like imageWithAsset

PageContent and sections

In order to use sanity provided sections for page content, create a component /components/PageContent.vue.

Each section component that can be added as page content in Sanity, needs to be added in the components object explicitly. The key matches the sanity doc type.

<script setup lang="ts">
defineProps<{ content: any[] }>();

const components = {
  hero: resolveComponent("Hero"),
};
</script>

<template>
  <component
    :is="components[c._type as keyof typeof components]"
    v-for="c in content"
    :key="c._id"
    v-bind="c"
  ></component>
</template>

Then in your main page [...slug].vue:

<script setup lang="ts">
import type { SanityPage } from "@pezak/hui-sanity/types";
import { pageQuery } from "./page.query";

const { t } = useMessages();

// Handle Page Fetching
const route = useRoute();

const getPageData = async (
  slug: string[],
): Promise<{
  data: globalThis.Ref<SanityPage | null>;
  pending: globalThis.Ref<boolean>;
  type: "page";
}> => {
  // Page is a generic page
  const query = groq`
    *[_type == "page" && slug.current == "${slug ? slug?.join("/") : "/"}"]{
      ${pageQuery}
    }[0]
  `;
  const { data, pending } = await useSanityQueryWithPreview<SanityPage>(query);

  return { data, pending, type: "page" };
};

const page = await getPageData(route.params.slug as string[]);

// Handle Page Seo Meta
useSeo(page.data.value?.seo);

// This is needed for sanity previewing.
useHead({
  link: [{ rel: "canonical", href: getCanonicalUrl(page.data.value) }],
});
</script>

<template>
  <div :key="route.fullPath">
    <!-- 404 Not Found -->
    <NotFound
      :code="404"
      :message="t('pageNotFound')"
      v-if="!page.data?.value"
    />

    <!-- Page -->
    <PageContent
      :content="page.data.value.content"
      v-else-if="page.type === 'page'"
    />
  </div>
</template>

Composables

const { data, pending } = await useSanityQueryWithPreview<SanityPage>(query);

In app.vue

const headerQuery = groq`
  *[_id == "header"]{ ..., links[]{
    ..., page->
  }}[0]
`;
const footerQuery = groq`
  *[_id == "footer"]{ ..., topLinks[]{
      ..., page->
  }}[0]
`;

const { data } = useSanityQuery<{
  header: HeaderProps;
  footer: FooterProps;
}>(
  `{ 
    "header": ${headerQuery},
    "footer": ${footerQuery},
  }`,
);

Contribution

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Release new version
npm run release