• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    TypeScript
  • Created about 2 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

All of the TypeScript definitions for <head>.

zhead

NPM version NPM Downloads GitHub stars

All of the TypeScript definitions for <head>.

Powering Unhead.


Status: Stable
Please report any issues 🐛
Made possible by my Sponsor Program 💖
Follow me @harlan_zw 🐦 • Join Discord for help

Features

  • 💎 Fully typed Head schema
  • 💎 Commented with MDN docs
  • 💎 Fully Augmentable
  • 💎 100+ typed meta's

Installation

npm install --save-dev zhead

# Using yarn
yarn add --dev zhead

Types

Head

Typescript base schema for document <head>.

export interface Head<E extends MergeHead = MergeHead> extends BaseHead {
  /**
   * The <title> HTML element defines the document's title that is shown in a browser's title bar or a page's tab.
   * It only contains text; tags within the element are ignored.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
   */
  title?: string
  /**
   * The <base> HTML element specifies the base URL to use for all relative URLs in a document.
   * There can be only one <base> element in a document.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
   */
  base?: Partial<Merge<E['base'], Base>>
  /**
   * The <link> HTML element specifies relationships between the current document and an external resource.
   * This element is most commonly used to link to stylesheets, but is also used to establish site icons
   * (both "favicon" style icons and icons for the home screen and apps on mobile devices) among other things.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#attr-as
   */
  link?: (Link & DataKeys & DefinedValueOrEmptyObject<E['link']>)[]
  /**
   * The <meta> element represents metadata that cannot be expressed in other HTML elements, like <link> or <script>.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
   */
  meta?: (Meta & DataKeys & DefinedValueOrEmptyObject<E['meta']>)[]
  /**
   * The <style> HTML element contains style information for a document, or part of a document.
   * It contains CSS, which is applied to the contents of the document containing the <style> element.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style
   */
  style?: (Style & DataKeys & DefinedValueOrEmptyObject<E['style']>)[]
  /**
   * The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script
   */
  script?: (Script & DataKeys & DefinedValueOrEmptyObject<E['script']>)[]
  /**
   * The <noscript> HTML element defines a section of HTML to be inserted if a script type on the page is unsupported
   * or if scripting is currently turned off in the browser.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript
   */
  noscript?: (Noscript & DataKeys & DefinedValueOrEmptyObject<E['noscript']>)[]
  /**
   * Attributes for the <html> HTML element.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html
   */
  htmlAttrs?: (HtmlAttributes & DataKeys & DefinedValueOrEmptyObject<E['htmlAttrs']>)
  /**
   * Attributes for the <body> HTML element.
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body
   */
  bodyAttrs?: (BodyAttributes & DataKeys & DefinedValueOrEmptyObject<E['bodyAttrs']>)
}

Flat Meta

See metaFlat.ts for the full list.

// SAMPLE

export interface MetaFlat {
    /**
     * This attribute declares the document's character encoding.
     * If the attribute is present, its value must be an ASCII case-insensitive match for the string "utf-8",
     * because UTF-8 is the only valid encoding for HTML5 documents.
     * <meta> elements which declare a character encoding must be located entirely within the first 1024 bytes
     * of the document.
     *
     * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#attr-charset
     */
    charset: string
    /**
     * Use this tag to provide a short description of the page.
     * In some situations, this description is used in the snippet shown in search results.
     *
     * @see https://developers.google.com/search/docs/advanced/appearance/snippet#meta-descriptions
     */
    description: string
    /**
     * This tag tells the browser how to render a page on a mobile device.
     * Presence of this tag indicates to Google that the page is mobile friendly.
     *
     * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta/name#standard_metadata_names_defined_in_other_specifications
     */
    viewport: string | Partial<{
      /**
       * Defines the pixel width of the viewport that you want the web site to be rendered at.
       */
      width: number | string | 'device-width'
      /**
       * Defines the height of the viewport. Not used by any browser.
       */
      height: number | string | 'device-height'
      /**
       * Defines the ratio between the device width
       * (device-width in portrait mode or device-height in landscape mode) and the viewport size.
       *
       * @minimum 0
       * @maximum 10
       */
      initialScale: number | string
      /**
       * Defines the maximum amount to zoom in.
       * It must be greater or equal to the minimum-scale or the behavior is undefined.
       * Browser settings can ignore this rule and iOS10+ ignores it by default.
       *
       * @minimum 0
       * @maximum 10
       */
      maximumScale: number | string
      /**
       * Defines the minimum zoom level. It must be smaller or equal to the maximum-scale or the behavior is undefined.
       * Browser settings can ignore this rule and iOS10+ ignores it by default.
       *
       * @minimum 0
       * @maximum 10
       */
      minimumScale: number | string
      /**
       * If set to no, the user is unable to zoom in the webpage.
       * The default is yes. Browser settings can ignore this rule, and iOS10+ ignores it by default.
       */
      userScalable: 'yes' | 'no'
      /**
       * The auto value doesn't affect the initial layout viewport, and the whole web page is viewable.
       *
       * The contain value means that the viewport is scaled to fit the largest rectangle inscribed within the display.
       *
       * The cover value means that the viewport is scaled to fill the device display.
       * It is highly recommended to make use of the safe area inset variables to ensure that important content
       * doesn't end up outside the display.
       */
      viewportFit: 'auto' | 'contain' | 'cover'
  }>

  // ...
}

API

defineHead

Use this decorator for a simple fully-typed head schema.

import { defineHead } from 'zhead'

const head = defineHead({
  title: 'My Page',
})

// {
//    title: 'My Page',
// }

Sponsors

License

MIT License © 2022-PRESENT Harlan Wilton

More Repositories

1

unlighthouse

Scan your entire site with Google Lighthouse in 2 minutes (on average). Open source, fully configurable with minimal setup.
JavaScript
3,840
star
2

nuxt-seo

The complete SEO solution for Nuxt.
TypeScript
1,053
star
3

nuxt-delay-hydration

Delayed hydration for progressively enhanced apps. Reduced blocking time and improved Google Lighthouse scores. ⚡️
TypeScript
369
star
4

request-indexing

Find your missing on pages Google and request them to be indexed using the Web Search Indexing API.
TypeScript
313
star
5

nuxt-webpack-optimisations

Make your Nuxt.js webpack builds faster ⚡
TypeScript
269
star
6

nuxt-og-image

Enlightened runtime images generated with Vue templates.
TypeScript
268
star
7

harlanzw.com

My personal website built with Nuxt 3 and Nuxt Content 2.
Vue
195
star
8

nuxt-simple-sitemap

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
TypeScript
166
star
9

nuxt-schema-org

The quickest and easiest way to build Schema.org graphs for Nuxt.
TypeScript
145
star
10

nuxt-simple-robots

(Migrated to @nuxtjs/robots) Tame the robots crawling and indexing your Nuxt site.
TypeScript
114
star
11

nuxt-link-checker

Find and magically fix links that may be negatively effecting your Nuxt sites SEO.
TypeScript
87
star
12

nuxt-seo-utils

SEO utilities to improve your Nuxt sites discoverability and shareability.
TypeScript
75
star
13

unrouted

Unrouted is a minimal, composable router built for speed, portability and DX
TypeScript
67
star
14

nuxt-site-config

Unifying site config with powerful and flexible APIs, for module authors and users.
TypeScript
65
star
15

harlanzw.com-vitepress

My personal blog built using VitePress and TailwindCSS
Vue
44
star
16

vue-cli-plugin-import-components

🔌 Automatically import components in your Vue CLI apps.
TypeScript
39
star
17

packrup

Simple utils to pack arrays, objects and strings to a flat object (and back again).
TypeScript
17
star
18

schema-org-graph

Build Schema.org graphs for JavaScript Runtimes (Browser, Node, etc). Improve your sites SEO with quick and easy Rich Results.
TypeScript
16
star
19

laradock-cli

[Unmaintained] Your new best friend for Laradock.
Dockerfile
16
star
20

changelogd

🪵 Aggressively find a packages changelog (or releases) between versions.
TypeScript
9
star
21

wp-keystone

A Wordpress Boilerplate combining the best libraries and practices
PHP
8
star
22

laravel-swiftype

Swiftype Integration for Laravel
PHP
7
star
23

nuxt-mycelium

🍄 TBA 🤫
TypeScript
7
star
24

to-vite-and-beyond-a-history-and-future-of-bundling

Vue
6
star
25

WP-Development-Environment

WorldPress Plugin - Development Environment
PHP
5
star
26

nuxt-seo-ui

Deprecated - Nuxt components with Schema.org and SEO integrations
TypeScript
5
star
27

talk-supercharged-head-management

NuxtNation 2022 Talk - VueUse Head v1
Vue
3
star
28

laravel-modern-mail

TBA
PHP
2
star
29

static

TypeScript
1
star
30

blockfolio-php

Blockfolio SDK for PHP - Unofficial
PHP
1
star
31

penguin-pass

Laravel / PHP Package for kid friendly passwords
PHP
1
star
32

nuxt-og-image-playground

Testing out nitro deployments with nuxt-og-imge.
Vue
1
star