UNPKG

2.41 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const Metatags_1 = __importDefault(require("./Metatags"));
7// @ts-ignore
8function possibleProperty(input, possiblePropertyNames, fallback) {
9 for (const propertyName of possiblePropertyNames) {
10 if (input[propertyName] !== undefined) {
11 return input[propertyName];
12 }
13 }
14 return fallback;
15}
16// @ts-ignore
17function populateMetatagObject(schema, input) {
18 let output = {};
19 for (const item of schema) {
20 // Check the list of propNames and the tag name
21 const value = possibleProperty(input, item.propNames.concat([item.name]), item.fallback);
22 if (value !== undefined) {
23 output[item.name] = value;
24 }
25 }
26 return output;
27}
28function createMetatagsFromConfig(config = {}) {
29 const { web = {} } = config;
30 const { themeColor, meta = {} } = web;
31 const { viewport, googleSiteVerification, apple = {}, twitter = {}, openGraph = {}, microsoft = {}, } = meta;
32 const openGraphMetatags = populateMetatagObject(Metatags_1.default.openGraph, openGraph);
33 const twitterMetatags = populateMetatagObject(Metatags_1.default.twitter, twitter);
34 const microsoftMetatags = populateMetatagObject(Metatags_1.default.microsoft, microsoft);
35 const appleMetatags = {
36 // Disable automatic phone number detection.
37 'format-detection': apple.formatDetection,
38 'apple-touch-fullscreen': apple.touchFullscreen,
39 'mobile-web-app-capable': apple.mobileWebAppCapable,
40 'apple-mobile-web-app-capable': apple.mobileWebAppCapable,
41 'apple-mobile-web-app-status-bar-style': apple.barStyle,
42 'apple-mobile-web-app-title': web.shortName,
43 };
44 const metaTags = Object.assign(Object.assign(Object.assign(Object.assign({ viewport, description: config.description }, openGraphMetatags), microsoftMetatags), twitterMetatags), appleMetatags);
45 if (googleSiteVerification !== undefined) {
46 metaTags['google-site-verification'] = googleSiteVerification;
47 }
48 if (themeColor !== undefined) {
49 metaTags['theme-color'] = themeColor;
50 }
51 return metaTags;
52}
53exports.default = createMetatagsFromConfig;
54//# sourceMappingURL=createMetatagsFromConfig.js.map
\No newline at end of file