dn-react-router-toolkit 0.1.7 → 0.1.9

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.
@@ -34,250 +34,258 @@ __export(seo_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(seo_exports);
36
36
  var import_react = __toESM(require("react"));
37
+ var import_react_router = require("react-router");
37
38
  function configSEO(config) {
38
- return {
39
- config,
40
- async init(props = {}) {
41
- const canonicalPath = props.canonicalPath;
42
- const url = canonicalPath ? `${config.origin}${canonicalPath}` : `${config.origin}${props.path || ""}`;
43
- const pageTitle = props.title ? `${props.title} | ${config.siteName}` : config.siteName;
44
- const description = props.description || config.description;
45
- const keywords = props.keywords || config.keywords;
46
- const websiteSchemaId = `${config.origin}/#website`;
47
- const websiteSchema = {
48
- "@type": "WebSite",
49
- "@id": websiteSchemaId,
50
- url: config.origin,
51
- name: config.siteName,
52
- alternateName: config.siteName,
53
- description: config.description,
54
- inLanguage: "ko"
39
+ function init(props) {
40
+ const canonicalPath = props.canonicalPath;
41
+ const url = canonicalPath ? `${config.origin}${canonicalPath === "/" ? "" : canonicalPath}` : `${config.origin}${props.path || ""}`;
42
+ const pageTitle = props.title ? `${props.title} | ${config.siteName}` : config.siteName;
43
+ const description = props.description || config.description;
44
+ const keywords = props.keywords || config.keywords;
45
+ const thumbnail = props.thumbnail || (typeof config.thumbnail === "function" ? config.thumbnail() : config.thumbnail);
46
+ return {
47
+ pageTitle,
48
+ type: props.type,
49
+ description,
50
+ keywords,
51
+ url,
52
+ thumbnail
53
+ };
54
+ }
55
+ const meta = ({ loaderData }) => {
56
+ const props = loaderData?.seo || {};
57
+ const { pageTitle, type, description, keywords, url, thumbnail } = props;
58
+ const socialImage = thumbnail ? [
59
+ typeof thumbnail === "string" ? {
60
+ url: thumbnail,
61
+ alt: `${props.title} \uB300\uD45C \uC774\uBBF8\uC9C0`
62
+ } : thumbnail
63
+ ] : [];
64
+ return [
65
+ pageTitle && { title: pageTitle },
66
+ description && { name: "description", content: description },
67
+ keywords && { name: "keywords", content: keywords.join(", ") },
68
+ url && {
69
+ tagName: "link",
70
+ rel: "canonical",
71
+ href: url
72
+ },
73
+ { property: "og:type", content: type || "website" },
74
+ pageTitle && { property: "og:title", content: pageTitle },
75
+ description && { property: "og:description", content: description },
76
+ url && { property: "og:url", content: url },
77
+ { property: "og:site_name", content: config.siteName },
78
+ ...socialImage?.map((file) => ({
79
+ property: "og:image",
80
+ content: file.url
81
+ })),
82
+ {
83
+ property: "twitter:card",
84
+ content: socialImage.length > 0 ? "summary_large_image" : "summary"
85
+ },
86
+ pageTitle && { property: "twitter:title", content: pageTitle },
87
+ description && { property: "twitter:description", content: description },
88
+ ...socialImage?.map((file) => ({
89
+ property: "twitter:image",
90
+ content: file.url
91
+ }))
92
+ ];
93
+ };
94
+ function StructedData() {
95
+ const matches = (0, import_react_router.useMatches)();
96
+ const data = matches.reduce((acc, match) => {
97
+ return {
98
+ ...acc,
99
+ ...match.loaderData?.seo || {}
55
100
  };
56
- const thumbnailSchemaId = `${url}/#thumbnail`;
57
- const thumbnail = props.thumbnail || (typeof config.thumbnail === "function" ? await config.thumbnail() : config.thumbnail);
58
- const thumbnailUrl = thumbnail?.url;
59
- const socialImage = thumbnail ? [
60
- typeof thumbnail === "string" ? {
61
- url: thumbnail,
101
+ }, {});
102
+ const { pageTitle, description, keywords, url, thumbnail } = data;
103
+ const thumbnailUrl = thumbnail?.url;
104
+ const props = data?.seo || {};
105
+ const websiteSchemaId = `${config.origin}/#website`;
106
+ const websiteSchema = {
107
+ "@type": "WebSite",
108
+ "@id": websiteSchemaId,
109
+ url: config.origin,
110
+ name: config.siteName,
111
+ alternateName: config.siteName,
112
+ description: config.description,
113
+ inLanguage: "ko"
114
+ };
115
+ const thumbnailSchemaId = `${url}/#thumbnail`;
116
+ const images = [
117
+ ...thumbnailUrl ? [
118
+ {
119
+ id: thumbnailSchemaId,
120
+ url: thumbnailUrl,
62
121
  alt: `${props.title} \uB300\uD45C \uC774\uBBF8\uC9C0`
63
- } : thumbnail
64
- ] : [];
65
- const images = [
66
- ...thumbnailUrl ? [
67
- {
68
- id: thumbnailSchemaId,
69
- url: thumbnailUrl,
70
- alt: `${props.title} \uB300\uD45C \uC774\uBBF8\uC9C0`
71
- }
72
- ] : [],
73
- ...props.images || [],
74
- ...props.collection?.map((portfolio) => portfolio.thumbnail) || []
75
- ].filter(Boolean);
76
- const image = images.filter((file) => file.id).map((file) => ({
77
- "@type": "ImageObject",
78
- "@id": `${url}/#${file.id}`
79
- }));
80
- const breadcrumbSchemaId = `${url}#breadcrumb`;
81
- const updatedAt = props.updatedAt;
82
- const createdAt = props.createdAt;
83
- const meta = () => {
84
- return [
85
- { title: pageTitle },
86
- { name: "description", content: description },
87
- { name: "keywords", content: keywords?.join(", ") || "" },
88
- {
89
- tagName: "link",
90
- rel: "canonical",
91
- href: url
122
+ }
123
+ ] : [],
124
+ ...props.images || [],
125
+ ...props.collection?.map((portfolio) => portfolio.thumbnail) || []
126
+ ].filter(Boolean);
127
+ const image = images.filter((file) => file.id).map((file) => ({
128
+ "@type": "ImageObject",
129
+ "@id": `${url}/#${file.id}`
130
+ }));
131
+ const breadcrumbSchemaId = `${url}#breadcrumb`;
132
+ const updatedAt = props.updatedAt;
133
+ const createdAt = props.createdAt;
134
+ const additionalStructedData = [
135
+ ...typeof props.structedData === "function" ? props.structedData() : props.structedData || [],
136
+ ...typeof config.structedData === "function" ? config.structedData() : config.structedData || []
137
+ ];
138
+ const collectionMainEntity = props.collection ? {
139
+ "@type": "ItemList",
140
+ numberOfItems: props.collection.length,
141
+ itemListElement: props.collection.map((item, index) => ({
142
+ "@type": "ListItem",
143
+ position: index + 1,
144
+ url: item.url,
145
+ item: {
146
+ "@type": "WebPage",
147
+ "@id": `${item.url}#webpage`,
148
+ url: item.url,
149
+ name: item.title,
150
+ thumbnailUrl: item.thumbnail?.url,
151
+ dateModified: item.updatedAt?.toISOString(),
152
+ dateCreated: item.createdAt?.toISOString(),
153
+ datePublished: item.createdAt?.toISOString()
154
+ }
155
+ }))
156
+ } : void 0;
157
+ const structuredData = {
158
+ "@context": "https://schema.org",
159
+ "@graph": [
160
+ {
161
+ "@type": "WebPage",
162
+ "@id": `${url}#webpage`,
163
+ url,
164
+ name: pageTitle,
165
+ description,
166
+ keywords,
167
+ dateModified: updatedAt?.toISOString(),
168
+ datePublished: createdAt?.toISOString(),
169
+ dateCreated: createdAt?.toISOString(),
170
+ primaryImageOfPage: thumbnail ? {
171
+ "@id": thumbnailSchemaId
172
+ } : void 0,
173
+ isPartOf: {
174
+ "@id": websiteSchemaId
92
175
  },
93
- { property: "og:type", content: props.type || "website" },
94
- { property: "og:title", content: pageTitle },
95
- { property: "og:description", content: description },
96
- { property: "og:url", content: url },
97
- { property: "og:site_name", content: config.siteName },
98
- ...socialImage.map((file) => ({
99
- property: "og:image",
100
- content: file.url
101
- })),
102
- {
103
- property: "twitter:card",
104
- content: socialImage.length > 0 ? "summary_large_image" : "summary"
176
+ inLanguage: "ko",
177
+ breadcrumb: props.breadcrumbs && props.breadcrumbs.length > 0 ? {
178
+ "@id": breadcrumbSchemaId
179
+ } : void 0,
180
+ image,
181
+ mainEntity: collectionMainEntity
182
+ },
183
+ props.article && {
184
+ "@type": "Article",
185
+ "@id": `${url}#article`,
186
+ url,
187
+ name: pageTitle,
188
+ description,
189
+ keywords,
190
+ headline: pageTitle,
191
+ dateModified: updatedAt?.toISOString(),
192
+ datePublished: createdAt?.toISOString(),
193
+ dateCreated: createdAt?.toISOString(),
194
+ isPartOf: {
195
+ "@id": websiteSchemaId
105
196
  },
106
- { property: "twitter:title", content: pageTitle },
107
- { property: "twitter:description", content: description },
108
- ...socialImage.map((file) => ({
109
- property: "twitter:image",
110
- content: file.url
111
- }))
112
- ];
113
- };
114
- const additionalStructedData = [
115
- ...typeof props.structedData === "function" ? await props.structedData() : props.structedData || [],
116
- ...typeof config.structedData === "function" ? await config.structedData() : config.structedData || []
117
- ];
118
- function getStructedData() {
119
- const collectionMainEntity = props.collection ? {
120
- "@type": "ItemList",
121
- numberOfItems: props.collection.length,
122
- itemListElement: props.collection.map((item, index) => ({
123
- "@type": "ListItem",
124
- position: index + 1,
125
- url: item.url,
126
- item: {
127
- "@type": "WebPage",
128
- "@id": `${item.url}#webpage`,
129
- url: item.url,
130
- name: item.title,
131
- thumbnailUrl: item.thumbnail?.url,
132
- dateModified: item.updatedAt?.toISOString(),
133
- dateCreated: item.createdAt?.toISOString(),
134
- datePublished: item.createdAt?.toISOString()
135
- }
136
- }))
137
- } : void 0;
138
- return {
139
- "@context": "https://schema.org",
140
- "@graph": [
141
- {
142
- "@type": "WebPage",
143
- "@id": `${url}#webpage`,
144
- url,
145
- name: pageTitle,
146
- description,
147
- keywords,
148
- dateModified: updatedAt?.toISOString(),
149
- datePublished: createdAt?.toISOString(),
150
- dateCreated: createdAt?.toISOString(),
151
- primaryImageOfPage: thumbnail ? {
152
- "@id": thumbnailSchemaId
153
- } : void 0,
154
- isPartOf: {
155
- "@id": websiteSchemaId
156
- },
157
- inLanguage: "ko",
158
- breadcrumb: props.breadcrumbs && props.breadcrumbs.length > 0 ? {
159
- "@id": breadcrumbSchemaId
160
- } : void 0,
161
- image,
162
- mainEntity: collectionMainEntity
163
- },
164
- props.article && {
165
- "@type": "Article",
166
- "@id": `${url}#article`,
167
- url,
168
- name: pageTitle,
169
- description,
170
- keywords,
171
- headline: pageTitle,
172
- dateModified: updatedAt?.toISOString(),
173
- datePublished: createdAt?.toISOString(),
174
- dateCreated: createdAt?.toISOString(),
175
- isPartOf: {
176
- "@id": websiteSchemaId
177
- },
178
- inLanguage: "ko",
179
- image
180
- },
181
- props.blogPosting && {
182
- "@type": "BlogPosting",
183
- "@id": `${url}/#blogposting`,
184
- url,
185
- headline: pageTitle,
186
- description,
187
- thumbnailUrl,
188
- datePublished: createdAt?.toISOString(),
189
- dateModified: updatedAt?.toISOString(),
190
- isPartOf: { "@id": websiteSchemaId },
191
- image
192
- },
193
- props.creativeWork && {
194
- "@type": "CreativeWork",
195
- "@id": `${url}/#creativework`,
196
- url,
197
- name: pageTitle,
198
- description,
199
- datePublished: createdAt?.toISOString(),
200
- dateModified: updatedAt?.toISOString(),
201
- isPartOf: { "@id": websiteSchemaId },
202
- thumbnailUrl,
203
- image
204
- },
205
- props.visualArtwork && {
206
- "@type": "VisualArtwork",
207
- "@id": `${url}/#visualartwork`,
208
- url,
209
- name: pageTitle,
210
- description,
211
- datePublished: createdAt?.toISOString(),
212
- dateModified: updatedAt?.toISOString(),
213
- isPartOf: { "@id": websiteSchemaId },
214
- thumbnailUrl,
215
- image
216
- },
217
- props.collection && {
218
- "@type": "CollectionPage",
219
- "@id": `${url}/#collectionpage`,
220
- url,
221
- name: pageTitle,
222
- description,
223
- isPartOf: { "@id": websiteSchemaId },
224
- image,
225
- inLanguage: "ko-KR",
226
- breadcrumb: props.breadcrumbs && props.breadcrumbs.length > 0 ? {
227
- "@id": `${url}/#breadcrumb`
228
- } : void 0,
229
- mainEntity: collectionMainEntity
230
- },
231
- websiteSchema,
232
- props.breadcrumbs && props.breadcrumbs.length > 0 && {
233
- "@id": breadcrumbSchemaId,
234
- "@type": "BreadcrumbList",
235
- itemListElement: props.breadcrumbs.map((breadcrumb, index) => ({
236
- "@type": "ListItem",
237
- position: index + 1,
238
- name: breadcrumb.label,
239
- item: `${config.origin}${breadcrumb.href}`
240
- }))
241
- },
242
- ...additionalStructedData,
243
- ...images.map((file) => {
244
- return {
245
- "@type": "ImageObject",
246
- "@id": `${url}/#${file.id}`,
247
- url: file.url,
248
- contentUrl: file.url,
249
- name: file.alt,
250
- description: file.alt,
251
- width: file?.width?.toString(),
252
- height: file?.height?.toString(),
253
- creditText: config.copyright,
254
- license: `${config.origin}/terms`,
255
- copyrightNotice: config.copyright,
256
- acquireLicensePage: `${config.origin}/terms`
257
- };
197
+ inLanguage: "ko",
198
+ image
199
+ },
200
+ props.blogPosting && {
201
+ "@type": "BlogPosting",
202
+ "@id": `${url}/#blogposting`,
203
+ url,
204
+ headline: pageTitle,
205
+ description,
206
+ thumbnailUrl,
207
+ datePublished: createdAt?.toISOString(),
208
+ dateModified: updatedAt?.toISOString(),
209
+ isPartOf: { "@id": websiteSchemaId },
210
+ image
211
+ },
212
+ props.creativeWork && {
213
+ "@type": "CreativeWork",
214
+ "@id": `${url}/#creativework`,
215
+ url,
216
+ name: pageTitle,
217
+ description,
218
+ datePublished: createdAt?.toISOString(),
219
+ dateModified: updatedAt?.toISOString(),
220
+ isPartOf: { "@id": websiteSchemaId },
221
+ thumbnailUrl,
222
+ image
223
+ },
224
+ props.visualArtwork && {
225
+ "@type": "VisualArtwork",
226
+ "@id": `${url}/#visualartwork`,
227
+ url,
228
+ name: pageTitle,
229
+ description,
230
+ datePublished: createdAt?.toISOString(),
231
+ dateModified: updatedAt?.toISOString(),
232
+ isPartOf: { "@id": websiteSchemaId },
233
+ thumbnailUrl,
234
+ image
235
+ },
236
+ props.collection && {
237
+ "@type": "CollectionPage",
238
+ "@id": `${url}/#collectionpage`,
239
+ url,
240
+ name: pageTitle,
241
+ description,
242
+ isPartOf: { "@id": websiteSchemaId },
243
+ image,
244
+ inLanguage: "ko-KR",
245
+ breadcrumb: props.breadcrumbs && props.breadcrumbs.length > 0 ? {
246
+ "@id": `${url}/#breadcrumb`
247
+ } : void 0,
248
+ mainEntity: collectionMainEntity
249
+ },
250
+ websiteSchema,
251
+ props.breadcrumbs && props.breadcrumbs.length > 0 && {
252
+ "@id": breadcrumbSchemaId,
253
+ "@type": "BreadcrumbList",
254
+ itemListElement: props.breadcrumbs.map(
255
+ (breadcrumb, index) => ({
256
+ "@type": "ListItem",
257
+ position: index + 1,
258
+ name: breadcrumb.title,
259
+ item: `${config.origin}${breadcrumb.href}`
258
260
  })
259
- ].filter(Boolean)
260
- };
261
- }
262
- function generateJSONLD() {
263
- const structedData = getStructedData();
264
- return /* @__PURE__ */ import_react.default.createElement(
265
- "script",
266
- {
267
- type: "application/ld+json",
268
- dangerouslySetInnerHTML: {
269
- __html: JSON.stringify(structedData).replace(/</g, "\\u003c")
270
- }
271
- }
272
- );
273
- }
274
- return {
275
- config,
276
- props,
277
- meta,
278
- generateJSONLD
279
- };
280
- }
261
+ )
262
+ },
263
+ ...additionalStructedData,
264
+ ...images.map((file) => {
265
+ return {
266
+ "@type": "ImageObject",
267
+ "@id": `${url}/#${file.id}`,
268
+ url: file.url,
269
+ contentUrl: file.url,
270
+ name: file.alt,
271
+ description: file.alt,
272
+ width: file?.width?.toString(),
273
+ height: file?.height?.toString(),
274
+ creditText: config.copyright,
275
+ license: `${config.origin}/terms`,
276
+ copyrightNotice: config.copyright,
277
+ acquireLicensePage: `${config.origin}/terms`
278
+ };
279
+ })
280
+ ].filter(Boolean)
281
+ };
282
+ return /* @__PURE__ */ import_react.default.createElement("script", { type: "application/ld+json" }, JSON.stringify(structuredData));
283
+ }
284
+ return {
285
+ config,
286
+ init,
287
+ meta,
288
+ StructedData
281
289
  };
282
290
  }
283
291
  // Annotate the CommonJS export names for ESM import in node: