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

astro-toolkit

v0.2.10

Published

A collection of Astro tools, components, and utilities to streamline your development process.

Downloads

27

Readme

Astro Toolkit

A collection of Astro tools, components, and utilities to streamline your development process.

SEO

Head Component

The BaseHead component in Astro Toolkit simplifies the process of adding essential SEO tags to your HTML's <head> section. This includes OpenGraph, Twitter cards, canonical URLs, and more, saving you from manually configuring these tags for each page.

Usage

To use the BaseHead component, import it from astro-toolkit/seo and customize the SEO tags:

---
import { BaseHead } from 'astro-toolkit/seo'
---

<BaseHead
  title="Your Page Title"
  description="Your page description"
  keywords={["keyword1", "keyword2", "astro-toolkit"]}
  OGImage={{ src: "/path/to/og-image.png", alt: "Image description" }}
  GSVToken="your-google-site-verification-token"
  extend={{
    link: [
      "./path/to/stylesheet.css",
      {
        href: "./path/to/another-stylesheet.css",
        rel: "stylesheet"
      },
      {
        href: "/path/to/font.woff2",
        rel: 'preload',
        as: 'font',
        type: 'font/woff2',
        crossorigin: 'anonymous',
      },
    ],
  }}
/>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Your Page Title</title>
  <link rel="stylesheet" href="./path/to/stylesheet.css">
  <link href="./path/to/another-stylesheet.css" rel="stylesheet">
  <link href="/path/to/font.woff2" rel="preload" as="font" type="font/woff2" crossorigin="anonymous">
  <meta name="keywords" content="keyword1,keyword2,astro-toolkit">
  <meta name="description" content="Your page description">
  <meta name="robots" content="index, follow">
  <link rel="canonical" href="https://yourwebsite.com/page-url/">
  <meta property="og:description" content="Your page description">
  <meta property="og:image" content="/path/to/og-image.png">
  <meta property="og:image:alt" content="Image description">
  <meta property="og:title" content="Your Page Title">
  <meta property="og:site_name" content="Your Site Name">
  <meta property="og:type" content="website">
  <meta property="og:url" content="https://yourwebsite.com/page-url/">
  <meta name="twitter:title" content="Your Page Title">
  <meta name="twitter:image" content="/path/to/og-image.png">
  <meta name="twitter:image:alt" content="Image description">
  <meta name="twitter:description" content="Your page description">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="google-site-verification" content="your-google-site-verification-token">
</head>

Benefits

Using the BaseHead component saves you from manually configuring:

  • OpenGraph tags for better social media sharing
  • Twitter card tags to optimize content sharing on Twitter
  • Canonical URLs to avoid duplicate content issues
  • Google Site Verification tags
  • Customizable link and meta tags through the extend property

Extending Head Component with Slots

You can add additional actions inside the <head> section using slots within the BaseHead component.

<BaseHead ... >
  <script is:inline>
    console.log("This script runs inline")
  </script>
</BaseHead>
type Props = {
  title?: string
  description?: string
  OGImage?: {
    src: string
    alt: string
  }
  keywords?: string | string[]
  sitemap?: boolean
  GSVToken: string
  robots: string
  extend?: {
    link?: Partial<Link>[]
    meta?: Partial<Meta>[]
  }
}

Utils

formatDate

Formats a given date string into a more readable format.

Usage

import { formatDate } from 'astro-toolkit/utils'

// Example usage
formatDate("2024-07-08") // Outputs: July 8, 2024

slugify, unslugify

Converts strings to URL-friendly slugs and back to their original form.

Usage

import { slugify, unslugify } from 'astro-toolkit/utils'

// Convert a string to a slug
slugify("Hello World") // Outputs: hello-world

// Convert a slug back to a string
unslugify("hello-world") // Outputs: Hello World

Flow

For Component

A component that loops through arrays and objects, rendering content for each item.

Note: Don't forget to return your content to be rendered.

Usage

---
import { For } from 'astro-toolkit/flow'
---

<ul>
  <For each={[1, 2, 3]}>
    {(item, index) => (
      <li>{index}: {item}</li>
    )}
  </For>
</ul>

In this example, the For component iterates over the array [1, 2, 3], rendering a list item for each element.

With Object

The For component can also be used to iterate over object properties.

Usage

---
import { For } from 'astro-toolkit/flow'
---

<ul>
  <For each={{ a: 1, b: 2, c: 3 }}>
    {(value, key) => (
      <li>{key}: {value}</li>
    )}
  </For>
</ul>

Actions

Easy-to-use view transition callback function to re-run your scripts when the page changes.

Usage

---
---

<script>
import { action } from 'astro-toolkit/actions'

action(() => {
  console.log("Re-run on page transition change")
})
</script>

In this example, the action function logs a message to the console whenever a page transition occurs.

Additional Information

Installation

To install Astro Toolkit, run the following command in your project directory:

npm install astro-toolkit

Contribution

If you would like to contribute to the Astro Toolkit, please follow the guidelines in the CONTRIBUTING.md