Skip to content

Commit

Permalink
feat(hiccup-html): add meta & link variations
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jun 30, 2020
1 parent 8acfcf0 commit 42fb113
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion packages/hiccup-html/src/head.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,78 @@ export interface MetaAttribs extends Attribs {
| "set-cookie"
| "x-ua-compatible"
>;
name: AttribVal<string>;
name: AttribVal<
| "application-name"
| "author"
| "color-scheme"
| "creator"
| "description"
| "generator"
| "googlebot"
| "keywords"
| "publisher"
| "referrer"
| "robots"
| "theme-color"
| "viewport"
>;
}

export const meta = defElement<Partial<MetaAttribs>, never>("meta");

export interface ViewportOpts {
width: number;
height: number;
min: number;
max: number;
init: number;
user: boolean;
fit: "auto" | "cover" | "contain";
}

export const metaViewport = (opts: Partial<ViewportOpts> = {}) =>
meta({
name: "viewport",
content: [
opts.width &&
`width=${opts.width < 0 ? "device-width" : opts.width}`,
opts.height &&
`width=${opts.height < 0 ? "device-height" : opts.height}`,
`initial-scale=${opts.init || 1}`,
opts.min && `minimum-scale=${opts.min}`,
opts.max && `maximum-scale=${opts.max}`,
`user-scalable=${opts.user !== false ? "yes" : "no"}`,
opts.fit != null && `viewport-fit=${opts.fit}`,
]
.filter((x) => !!x)
.join(","),
});

export const metaRobots = (
type:
| "index"
| "noindex"
| "follow"
| "nofollow"
| "none"
| "noarchive"
| "nosnippet"
| "noimageindex"
| "nocache"
) => meta({ name: "robots", content: type });

export const metaReferrer = (
type:
| "no-referrer-when-downgrade"
| "no-referrer"
| "origin-when-cross-origin"
| "origin"
| "same-origin"
| "strict-origin-when-cross-origin"
| "strict-origin"
| "unsafe-URL"
) => meta({ name: "referrer", content: type });

export interface LinkAttribs
extends Attribs,
CORSAttribs,
Expand Down Expand Up @@ -65,6 +132,8 @@ export interface LinkAttribs

export const link = defElement<Partial<LinkAttribs>, never>("link");

export const linkCSS = (href: string) => link({ href, rel: "stylesheet" });

export interface StyleAttribs extends Attribs {
media: AttribVal<string>;
nonce: AttribVal<string>;
Expand Down

0 comments on commit 42fb113

Please sign in to comment.