@treely/strapi-slices 7.10.0 → 7.11.0
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/dist/components/SEOTags/SEOTags.d.ts +10 -0
- package/dist/strapi-slices.cjs.development.js +104 -1
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +104 -1
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/SEOTags/SEOTags.tsx +175 -0
|
@@ -885,6 +885,86 @@ var PreviewAlert = function PreviewAlert() {
|
|
|
885
885
|
}));
|
|
886
886
|
};
|
|
887
887
|
|
|
888
|
+
// Helper function to convert SchemaValue to string
|
|
889
|
+
var getTextValue = function getTextValue(value) {
|
|
890
|
+
if (typeof value === 'string') return value;
|
|
891
|
+
if (typeof value === 'object' && value !== null && 'text' in value) {
|
|
892
|
+
return value.text;
|
|
893
|
+
}
|
|
894
|
+
return '';
|
|
895
|
+
};
|
|
896
|
+
// Helper function to safely access properties from a schema
|
|
897
|
+
var getSchemaProperty = function getSchemaProperty(schema, property) {
|
|
898
|
+
return getTextValue(schema[property]) || '';
|
|
899
|
+
};
|
|
900
|
+
// Helper function to get a unique identifier from a schema
|
|
901
|
+
var getSchemaIdentifier = function getSchemaIdentifier(schema) {
|
|
902
|
+
var _offer$price;
|
|
903
|
+
var type = schema['@type'];
|
|
904
|
+
switch (type) {
|
|
905
|
+
case 'Organization':
|
|
906
|
+
return getSchemaProperty(schema, 'name') || 'default';
|
|
907
|
+
case 'Article':
|
|
908
|
+
case 'BlogPosting':
|
|
909
|
+
return getSchemaProperty(schema, 'headline') || 'untitled-article';
|
|
910
|
+
case 'Product':
|
|
911
|
+
return getSchemaProperty(schema, 'name') || 'untitled-product';
|
|
912
|
+
case 'Person':
|
|
913
|
+
return getSchemaProperty(schema, 'name') || 'unnamed-person';
|
|
914
|
+
case 'Event':
|
|
915
|
+
return getSchemaProperty(schema, 'name') || 'untitled-event';
|
|
916
|
+
case 'LocalBusiness':
|
|
917
|
+
return getSchemaProperty(schema, 'name') || 'unnamed-business';
|
|
918
|
+
case 'Service':
|
|
919
|
+
return getSchemaProperty(schema, 'name') || 'unnamed-service';
|
|
920
|
+
case 'Brand':
|
|
921
|
+
return getSchemaProperty(schema, 'name') || 'unnamed-brand';
|
|
922
|
+
case 'FAQPage':
|
|
923
|
+
return 'faq-page';
|
|
924
|
+
case 'HowTo':
|
|
925
|
+
return getSchemaProperty(schema, 'name') || 'untitled-howto';
|
|
926
|
+
case 'BreadcrumbList':
|
|
927
|
+
return 'breadcrumbs';
|
|
928
|
+
case 'Offer':
|
|
929
|
+
var offer = schema;
|
|
930
|
+
return "offer-" + ((_offer$price = offer.price) != null ? _offer$price : 'unknown-price');
|
|
931
|
+
case 'WebPage':
|
|
932
|
+
return getSchemaProperty(schema, 'name') || 'untitled-page';
|
|
933
|
+
default:
|
|
934
|
+
return 'unknown-schema';
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
var validateSchema = function validateSchema(schema) {
|
|
938
|
+
if (Array.isArray(schema)) {
|
|
939
|
+
return schema.every(function (item) {
|
|
940
|
+
return item['@context'] === 'https://schema.org' && '@type' in item;
|
|
941
|
+
});
|
|
942
|
+
}
|
|
943
|
+
return schema['@context'] === 'https://schema.org' && '@type' in schema;
|
|
944
|
+
};
|
|
945
|
+
var DEFAULT_SCHEMA = {
|
|
946
|
+
'@context': 'https://schema.org',
|
|
947
|
+
'@type': 'Organization',
|
|
948
|
+
name: 'Tree.ly',
|
|
949
|
+
url: 'https://tree.ly',
|
|
950
|
+
logo: 'https://cdn.tree.ly/logo.png',
|
|
951
|
+
address: {
|
|
952
|
+
'@type': 'PostalAddress',
|
|
953
|
+
streetAddress: 'Littengasse 2b/c',
|
|
954
|
+
addressLocality: 'Dornbirn',
|
|
955
|
+
postalCode: '6850',
|
|
956
|
+
addressRegion: 'Vorarlberg',
|
|
957
|
+
addressCountry: 'AT'
|
|
958
|
+
},
|
|
959
|
+
contactPoint: {
|
|
960
|
+
'@type': 'ContactPoint',
|
|
961
|
+
telephone: '+43-5572-432015',
|
|
962
|
+
contactType: 'Customer Service',
|
|
963
|
+
areaServed: 'AT',
|
|
964
|
+
availableLanguage: ['English', 'German']
|
|
965
|
+
},
|
|
966
|
+
sameAs: ['https://www.linkedin.com/company/tree-ly', 'https://www.facebook.com/treely', 'https://www.instagram.com/treely']
|
|
967
|
+
};
|
|
888
968
|
var SEOTags = function SEOTags(_ref) {
|
|
889
969
|
var _shareImage$url, _shareImage$alt;
|
|
890
970
|
var title = _ref.title,
|
|
@@ -895,9 +975,24 @@ var SEOTags = function SEOTags(_ref) {
|
|
|
895
975
|
_ref$favicon = _ref.favicon,
|
|
896
976
|
favicon = _ref$favicon === void 0 ? 'https://cdn.tree.ly/favicon.ico' : _ref$favicon,
|
|
897
977
|
_ref$domain = _ref.domain,
|
|
898
|
-
domain = _ref$domain === void 0 ? 'tree.ly' : _ref$domain
|
|
978
|
+
domain = _ref$domain === void 0 ? 'tree.ly' : _ref$domain,
|
|
979
|
+
schemaMarkup = _ref.schemaMarkup;
|
|
899
980
|
var shareImageUrl = (_shareImage$url = shareImage == null ? void 0 : shareImage.url) != null ? _shareImage$url : DEFAULT_SHARE_IMAGE;
|
|
900
981
|
var shareImageAlt = (_shareImage$alt = shareImage == null ? void 0 : shareImage.alt) != null ? _shareImage$alt : DEFAULT_SHARE_ALT;
|
|
982
|
+
var schemas = schemaMarkup || DEFAULT_SCHEMA;
|
|
983
|
+
var isValidSchema = validateSchema(schemas);
|
|
984
|
+
if (schemaMarkup && !isValidSchema) {
|
|
985
|
+
console.warn('Invalid schema markup provided to SEOTags component. Falling back to default schema.', schemaMarkup);
|
|
986
|
+
schemas = DEFAULT_SCHEMA;
|
|
987
|
+
isValidSchema = true;
|
|
988
|
+
}
|
|
989
|
+
var schemaArray = Array.isArray(schemas) ? schemas : [schemas];
|
|
990
|
+
var getSchemaKey = function getSchemaKey(schema, index) {
|
|
991
|
+
var type = schema['@type'];
|
|
992
|
+
var identifier = getSchemaIdentifier(schema);
|
|
993
|
+
// Add index to ensure uniqueness, especially for fallback identifiers
|
|
994
|
+
return type + "-" + identifier + "-" + index;
|
|
995
|
+
};
|
|
901
996
|
return React.createElement(Head, null, React.createElement("title", null, title + " - " + metaTitleSuffix), React.createElement("meta", {
|
|
902
997
|
name: "description",
|
|
903
998
|
content: description
|
|
@@ -943,6 +1038,14 @@ var SEOTags = function SEOTags(_ref) {
|
|
|
943
1038
|
}), React.createElement("meta", {
|
|
944
1039
|
name: "twitter:image:alt",
|
|
945
1040
|
content: shareImageAlt
|
|
1041
|
+
}), isValidSchema && schemaArray.map(function (schema, index) {
|
|
1042
|
+
return React.createElement("script", {
|
|
1043
|
+
key: getSchemaKey(schema, index),
|
|
1044
|
+
type: "application/ld+json",
|
|
1045
|
+
dangerouslySetInnerHTML: {
|
|
1046
|
+
__html: JSON.stringify(schema)
|
|
1047
|
+
}
|
|
1048
|
+
});
|
|
946
1049
|
}));
|
|
947
1050
|
};
|
|
948
1051
|
|