@dr.pogodin/react-utils 1.40.11 → 1.40.13
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.
- package/build/development/shared/components/MetaTags.js +18 -52
- package/build/development/shared/components/MetaTags.js.map +1 -1
- package/build/development/web.bundle.js +1 -1
- package/build/production/shared/components/MetaTags.js +4 -52
- package/build/production/shared/components/MetaTags.js.map +1 -1
- package/build/production/web.bundle.js +1 -1
- package/build/production/web.bundle.js.map +1 -1
- package/build/types-code/shared/components/MetaTags.d.ts +10 -54
- package/package.json +6 -7
- package/src/shared/components/MetaTags.tsx +33 -54
|
@@ -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
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
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:
|
|
66
|
-
Context:
|
|
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.
|
|
2
|
+
"version": "1.40.13",
|
|
3
3
|
"bin": {
|
|
4
4
|
"react-utils-build": "bin/build.js",
|
|
5
5
|
"react-utils-setup": "bin/setup.js"
|
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
"@dr.pogodin/babel-plugin-react-css-modules": "^6.13.2",
|
|
13
13
|
"@dr.pogodin/csurf": "^1.14.0",
|
|
14
14
|
"@dr.pogodin/js-utils": "^0.0.12",
|
|
15
|
-
"@dr.pogodin/react-global-state": "^0.17.
|
|
15
|
+
"@dr.pogodin/react-global-state": "^0.17.5",
|
|
16
16
|
"@dr.pogodin/react-themes": "^1.7.0",
|
|
17
17
|
"@jest/environment": "^29.7.0",
|
|
18
18
|
"axios": "^1.7.7",
|
|
19
19
|
"commander": "^12.1.0",
|
|
20
20
|
"compression": "^1.7.5",
|
|
21
21
|
"config": "^3.3.12",
|
|
22
|
-
"cookie": "^1.0.
|
|
22
|
+
"cookie": "^1.0.2",
|
|
23
23
|
"cookie-parser": "^1.4.7",
|
|
24
24
|
"cross-env": "^7.0.3",
|
|
25
25
|
"dayjs": "^1.11.13",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"lodash": "^4.17.21",
|
|
31
31
|
"morgan": "^1.10.0",
|
|
32
32
|
"node-forge": "^1.3.1",
|
|
33
|
-
"qs": "^6.13.
|
|
33
|
+
"qs": "^6.13.1",
|
|
34
34
|
"raf": "^3.4.1",
|
|
35
35
|
"react": "^18.3.1",
|
|
36
36
|
"react-dom": "^18.3.1",
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
"@types/serialize-javascript": "^5.0.4",
|
|
82
82
|
"@types/serve-favicon": "^2.5.7",
|
|
83
83
|
"@types/supertest": "^6.0.2",
|
|
84
|
-
"@types/uuid": "^10.0.0",
|
|
85
84
|
"@types/webpack": "^5.28.5",
|
|
86
85
|
"autoprefixer": "^10.4.20",
|
|
87
86
|
"babel-jest": "^29.7.0",
|
|
@@ -113,7 +112,7 @@
|
|
|
113
112
|
"react-refresh": "^0.14.2",
|
|
114
113
|
"regenerator-runtime": "^0.14.1",
|
|
115
114
|
"resolve-url-loader": "^5.0.0",
|
|
116
|
-
"sass": "^1.
|
|
115
|
+
"sass": "^1.81.0",
|
|
117
116
|
"sass-loader": "^16.0.3",
|
|
118
117
|
"sitemap": "^8.0.0",
|
|
119
118
|
"source-map-loader": "^5.0.0",
|
|
@@ -124,7 +123,7 @@
|
|
|
124
123
|
"tstyche": "^3.0.0",
|
|
125
124
|
"typed-scss-modules": "^8.0.1",
|
|
126
125
|
"typescript": "^5.6.3",
|
|
127
|
-
"typescript-eslint": "^8.
|
|
126
|
+
"typescript-eslint": "^8.15.0",
|
|
128
127
|
"webpack": "^5.96.1",
|
|
129
128
|
"webpack-dev-middleware": "^7.4.2",
|
|
130
129
|
"webpack-hot-middleware": "^2.26.1",
|
|
@@ -1,9 +1,20 @@
|
|
|
1
|
-
import {
|
|
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
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
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:
|
|
74
|
-
Context:
|
|
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 ? (
|