@dr.pogodin/react-utils 1.40.11 → 1.40.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,11 @@
1
- import { type ReactNode } from 'react';
1
+ import { type Context as ContextT, type FunctionComponent, type ReactNode } from 'react';
2
2
  type PropsT = {
3
3
  children?: ReactNode;
4
4
  description: string;
5
+ extraMetaTags?: Array<{
6
+ content: string;
7
+ name: string;
8
+ }>;
5
9
  image?: string;
6
10
  siteName?: string;
7
11
  socialDescription?: string;
@@ -10,59 +14,11 @@ type PropsT = {
10
14
  url?: string;
11
15
  };
12
16
  /**
13
- * The `<MetaTags>` component is an auxiliary wrapper around `react-helmet`,
14
- * which helps to inject meta tags (page title, a brief content description,
15
- * and social media thumbnails) into generated pages.
16
- *
17
- * When `<MetaTags>` are nested within the app's component tree, meta tags
18
- * content injected by components encountered down the tree overrides tags
19
- * injected by previously encountered `<MetaTags>` components.
20
- *
21
- * **Children:** `<MetaTags>` children, if any, are rendered at the component's
22
- * location. The context passes down all meta tag properties of parent
23
- * `<MetaTag>` instances. These properties can fetched within children
24
- * hierarchy in the following way, thus facilitating tags modification by
25
- * children:
26
- * ```jsx
27
- * import { useContext } from 'react';
28
- * import { MetaTags } from '@dr.pogodin/react-utils';
29
- * export default function SampleComponent() {
30
- * const { title, description, ...rest } = useContext(MetaTags.Context);
31
- * // Do something with these props here, e.g. prefix the page title with
32
- * // the component name:
33
- * return (
34
- * <MetaTags title={`Sample component - ${title}`} />
35
- * );
36
- * }
37
- * ```
38
- * @param [props]
39
- * @param [props.description] Page description to use in
40
- * the `description` meta tag, and as a default description of Open Graph Tags.
41
- * @param [props.image] The absolute URL of thumbnail image to use
42
- * in Open Graph Tags (`twitter:image`, and `og:image`). By default these tags
43
- * are not injected.
44
- *
45
- * **BEWARE:** It must be a complete, absolute URL, including the correct
46
- * website domain and HTTP schema.
47
- *
48
- * @param [props.siteName]: The site name to use in `twitter:site`,
49
- * and `og:sitename` tags. By default these tags are not injected.
50
- *
51
- * @param [props.socialDescription] The site description to use in
52
- * `twitter:description` and `og:description` meta tags. By default the value of
53
- * `description` prop is used.
54
- * @param [props.socialTitle] The page title to use in
55
- * `twitter:title`, `og:title`, and `og:image:alt` tags. By default the value of
56
- * `title` prop is used. Also the `og:image:alt` tag is only injected if `image`
57
- * prop is present.
58
- *
59
- * @param props.title: The page name to use in the `<title>` tag.
60
- * It is also used as the default value of `socialTitle` prop.
61
- *
62
- * @param [props.url] The page URL to use in `og:url` tag.
63
- * By default the tag is not injected.
17
+ * Auxiliary wrapper around "react-helmet", which helps to inject meta tags
18
+ * (page title, a brief content description, and social media thumbnails) into
19
+ * generated pages.
64
20
  */
65
- declare const MetaTags: React.FunctionComponent<PropsT> & {
66
- Context: React.Context<PropsT>;
21
+ declare const MetaTags: FunctionComponent<PropsT> & {
22
+ Context: ContextT<PropsT>;
67
23
  };
68
24
  export default MetaTags;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.40.11",
2
+ "version": "1.40.12",
3
3
  "bin": {
4
4
  "react-utils-build": "bin/build.js",
5
5
  "react-utils-setup": "bin/setup.js"
@@ -113,7 +113,7 @@
113
113
  "react-refresh": "^0.14.2",
114
114
  "regenerator-runtime": "^0.14.1",
115
115
  "resolve-url-loader": "^5.0.0",
116
- "sass": "^1.80.6",
116
+ "sass": "^1.80.7",
117
117
  "sass-loader": "^16.0.3",
118
118
  "sitemap": "^8.0.0",
119
119
  "source-map-loader": "^5.0.0",
@@ -1,9 +1,20 @@
1
- import { type ReactNode, createContext, useMemo } from 'react';
1
+ import {
2
+ type Context as ContextT,
3
+ type FunctionComponent,
4
+ type ReactNode,
5
+ createContext,
6
+ useMemo,
7
+ } from 'react';
8
+
2
9
  import { Helmet } from 'react-helmet';
3
10
 
4
11
  type PropsT = {
5
12
  children?: ReactNode;
6
13
  description: string;
14
+ extraMetaTags?: Array<{
15
+ content: string;
16
+ name: string;
17
+ }>;
7
18
  image?: string;
8
19
  siteName?: string;
9
20
  socialDescription?: string;
@@ -18,63 +29,16 @@ const Context = createContext<PropsT>({
18
29
  });
19
30
 
20
31
  /**
21
- * The `<MetaTags>` component is an auxiliary wrapper around `react-helmet`,
22
- * which helps to inject meta tags (page title, a brief content description,
23
- * and social media thumbnails) into generated pages.
24
- *
25
- * When `<MetaTags>` are nested within the app's component tree, meta tags
26
- * content injected by components encountered down the tree overrides tags
27
- * injected by previously encountered `<MetaTags>` components.
28
- *
29
- * **Children:** `<MetaTags>` children, if any, are rendered at the component's
30
- * location. The context passes down all meta tag properties of parent
31
- * `<MetaTag>` instances. These properties can fetched within children
32
- * hierarchy in the following way, thus facilitating tags modification by
33
- * children:
34
- * ```jsx
35
- * import { useContext } from 'react';
36
- * import { MetaTags } from '@dr.pogodin/react-utils';
37
- * export default function SampleComponent() {
38
- * const { title, description, ...rest } = useContext(MetaTags.Context);
39
- * // Do something with these props here, e.g. prefix the page title with
40
- * // the component name:
41
- * return (
42
- * <MetaTags title={`Sample component - ${title}`} />
43
- * );
44
- * }
45
- * ```
46
- * @param [props]
47
- * @param [props.description] Page description to use in
48
- * the `description` meta tag, and as a default description of Open Graph Tags.
49
- * @param [props.image] The absolute URL of thumbnail image to use
50
- * in Open Graph Tags (`twitter:image`, and `og:image`). By default these tags
51
- * are not injected.
52
- *
53
- * **BEWARE:** It must be a complete, absolute URL, including the correct
54
- * website domain and HTTP schema.
55
- *
56
- * @param [props.siteName]: The site name to use in `twitter:site`,
57
- * and `og:sitename` tags. By default these tags are not injected.
58
- *
59
- * @param [props.socialDescription] The site description to use in
60
- * `twitter:description` and `og:description` meta tags. By default the value of
61
- * `description` prop is used.
62
- * @param [props.socialTitle] The page title to use in
63
- * `twitter:title`, `og:title`, and `og:image:alt` tags. By default the value of
64
- * `title` prop is used. Also the `og:image:alt` tag is only injected if `image`
65
- * prop is present.
66
- *
67
- * @param props.title: The page name to use in the `<title>` tag.
68
- * It is also used as the default value of `socialTitle` prop.
69
- *
70
- * @param [props.url] The page URL to use in `og:url` tag.
71
- * By default the tag is not injected.
32
+ * Auxiliary wrapper around "react-helmet", which helps to inject meta tags
33
+ * (page title, a brief content description, and social media thumbnails) into
34
+ * generated pages.
72
35
  */
73
- const MetaTags: React.FunctionComponent<PropsT> & {
74
- Context: React.Context<PropsT>;
36
+ const MetaTags: FunctionComponent<PropsT> & {
37
+ Context: ContextT<PropsT>;
75
38
  } = ({
76
39
  children,
77
40
  description,
41
+ extraMetaTags,
78
42
  image,
79
43
  siteName,
80
44
  socialDescription,
@@ -103,6 +67,20 @@ const MetaTags: React.FunctionComponent<PropsT> & {
103
67
  url,
104
68
  ]);
105
69
 
70
+ const extra: ReactNode[] = [];
71
+ if (extraMetaTags?.length) {
72
+ for (let i = 0; i < extraMetaTags.length; ++i) {
73
+ const { content, name } = extraMetaTags[i]!;
74
+ extra.push(
75
+ <meta
76
+ content={content}
77
+ name={name}
78
+ key={`extra-meta-tag-${i}`}
79
+ />,
80
+ );
81
+ }
82
+ }
83
+
106
84
  return (
107
85
  <>
108
86
  <Helmet>
@@ -132,6 +110,7 @@ const MetaTags: React.FunctionComponent<PropsT> & {
132
110
  siteName ? (<meta name="og:sitename" content={siteName} />) : null
133
111
  }
134
112
  { url ? (<meta name="og:url" content={url} />) : null }
113
+ {extra}
135
114
  </Helmet>
136
115
  {
137
116
  children ? (