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

@binz/visor

v0.3.1

Published

Full-coverage `<head>` gear for your Astro app.

Downloads

237

Readme

Visor

Full-coverage <head> gear for your Astro app.

Visor automatically generates the necessary HTML tags for global metadata, including:

  • <meta> tags for charset, viewport, theme color, and description.
  • <link> tags for favicon and canonical URL.
  • <meta> tags for OpenGraph and Twitter tags, including title, description, image, and more.
  • <meta> tag for the generator (Astro version).

You can customize the values of these tags by passing the appropriate props to the component.

Installation

To install Visor, run one of the following commands in your Astro project:

pnpm install @binz/visor sharp sharp-ico
npm install @binz/visor sharp sharp-ico
yarn add @binz/visor sharp sharp-ico

Currently, Visor requires the sharp and sharp-ico packages to be installed in your project.

Usage

Import the component from the Visor package and use it in your Astro Layout component:

// src/layouts/default.astro
---
import {Visor} from '@binz/visor';
import logoSvgSrc from '../images/Logo.svg';

interface Props {
  title: string;
}

const { title: pageTitle } = Astro.props;
const canonicalUrl = Astro.url;
---
<!doctype html>
<html lang="en">
  <Visor
    author={{
      name: "Joe Bloggs",
      twitterHandle: "@joe_blogs"
    }}
    canonicalURL={canonicalUrl}
    description="Built with visor"
    defaultKeywords={[]}
    siteName="Example Site"
    siteFaviconSvg={logoSvgSrc}
    socialImagePath="/social.png"
    title="Example Site"
  />
  <body>
    <!-- Your content here -->
  </body>
</html>

Site Favicon Generation

Visor simplifies dynamic favicon generation with a pre-configured favicon.ico file.

Create a new API route at pages/favicon.ico to generate the favicon:

// pages/favicon.ico
import path from "node:path";
import type {APIRoute} from "astro";
import Favicon from "@binz/visor/favicon";

const faviconSrc = path.resolve("src/images/Logo.svg");

export const GET: APIRoute = Favicon({faviconSrc});

PWA Support

Visor also supports Progressive Web App (PWA) features.

In addition to generating the necessary tags for PWA support, Visor can also be used to generate a manifest.json file for PWA support using Astro’s Static File Endpoints feature.

Add the pwa prop to the component in your Astro layout:

<Head
  title="Example Site"
  {'...'}
+ pwa
/>

Finally create a new API route to generate the manifest.json file:

// pages/manifest.json.ts
import type {APIRoute} from "astro";
import Manifest from "@binz/visor/manifest";

import favicon from "./../images/Logo.svg";

const faviconPngSizes = [192, 512];

export const GET: APIRoute = Manifest({
  name: "Example Site",
  background_color: "#FFFFFF",
  description: "An example site",
  display: "standalone",
  favicon: {
    src: favicon,
    faviconSizes: faviconPngSizes,
  },
  id: "example-com",
  short_name: "Example",
  start_url: "/",
  theme_color: "#B9FF66",
});

Example

A more detailed example of how to use Visor in an Astro layout is shown below:

// src/layouts/default.astro
---
import {Visor} from '@binz/visor';
import logoSvgSrc from '../images/Logo.svg';

const SITE_NAME = 'Example Site';

interface Props {
  title: string;
  description: string;
  socialImagePath?: string;
  socialImageAltText?: string;
  keywords?: string[];
}

const {
  title: pageTitle,
  description,
  socialImagePath: socialImage = '/social.png',
  socialImageAltText = pageTitle,
  keywords,
} = Astro.props;

const canonicalUrl = Astro.url;

const title = `${pageTitle} | ${SITE_NAME}`;
---
<html lang="en">
  <Visor
    author={{{
      name: "Joe Bloggs",
      twitterHandle: "@joe_blogs"
    }}}
    canonicalURL={canonicalUrl}
    description={description}
    defaultKeywords={[ SITE_NAME, 'example' ]}
    keywords={keywords}
    siteName="Example Site"
    siteFaviconSvg={logoSvgSrc}
    siteLocale="en_US"
    siteTwitterHandle="@example_dot_com"
    socialImagePath={socialImage}
    socialImageAltText={socialImageAltText}
		socialTwitterCardType='summary_large_image'
    siteThemeColour={'#883aea'}
		contentType='website'
    title={title}
    pwa
  >
    <!-- Add custom head tags -->
    <link rel="stylesheet" href="/styles/global.css" />
  </Visor>
  <body>
    <!-- Your content here -->
  </body>
</html>

License

This Astro Head component is open source and available under the MIT License.