Skip to content

Commit

Permalink
feat: Adds missing apple tags (#19)
Browse files Browse the repository at this point in the history
* Adds 2 new tags

color-scheme + apple-touch-fullscreen

* Improve error handling

* adds changeset
  • Loading branch information
OllieJT authored Jul 17, 2024
1 parent 610bbdd commit a946503
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-timers-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"schemeta": patch
---

Adds missing apple meta tags
2 changes: 2 additions & 0 deletions src/lib/validator/primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ export const yes_or_no = z.union([z.literal("yes"), z.literal("no")]);
export const num_str = z.number().transform(String);

export const date_iso = z.date().transform((date) => date.toISOString());

export const color_scheme = z.union([z.literal("light"), z.literal("dark")]);
19 changes: 17 additions & 2 deletions src/lib/values.options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
apple,
color_scheme,
date_iso,
hex_color,
msapplication,
Expand Down Expand Up @@ -48,7 +49,7 @@ export const value_option = {
({
element: "script",
attributes: {},
children: JSON.stringify(children),
children: `\n\t${JSON.stringify(children)}\n`,
}) satisfies ValueElement,
),
"application-name": z.string().transform(
Expand Down Expand Up @@ -82,6 +83,13 @@ export const value_option = {
attributes: { name: "theme-color", content },
}) satisfies ValueElement,
),
"color-scheme": color_scheme.transform(
(content) =>
({
element: "meta",
attributes: { name: "color-scheme", content },
}) satisfies ValueElement,
),
"format-detection": z.literal("telephone=no").transform(
(content) =>
({
Expand Down Expand Up @@ -329,6 +337,13 @@ export const value_option = {
attributes: { name: "apple-mobile-web-app-title", content },
}) satisfies ValueElement,
),
"apple-touch-fullscreen": yes_or_no.transform(
(content) =>
({
element: "meta",
attributes: { name: "apple-touch-fullscreen", content },
}) satisfies ValueElement,
),

// OpenGraph - og:*
"og:site_name": z.string().transform(
Expand Down Expand Up @@ -686,7 +701,7 @@ export const value_option = {
attributes: { property: "profile:username", content },
}) satisfies ValueElement,
),
};
} satisfies Record<string, z.ZodTypeAny>;

export type OptionInput = {
[key in keyof typeof value_option]: z.input<(typeof value_option)[key]>;
Expand Down
7 changes: 6 additions & 1 deletion src/schemeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class Metadata {
description: undefined,
canonical: undefined,
"theme-color": undefined,
"apple-touch-fullscreen": undefined,
"color-scheme": undefined,
"msapplication-allowDomainApiCalls": undefined,
"msapplication-allowDomainMetaTags": undefined,
"msapplication-badge": undefined,
Expand Down Expand Up @@ -91,7 +93,10 @@ export class Metadata {
}

add<Key extends keyof OptionInput>(key: Key, input: OptionInput[Key]) {
const output = value_option[key].parse(input);
const validator = value_option[key];
if (!validator) throw new Error(`Unable to validate key: ${key}`);

const output = validator.parse(input);

if (Array.isArray(this.#raw_values[key])) {
// Appending Value
Expand Down

0 comments on commit a946503

Please sign in to comment.