gt-sanity 4.0.16 → 4.0.17

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/index.d.ts CHANGED
@@ -219,6 +219,7 @@ export declare type GTFieldLevelLocalizationConfig = {
219
219
  declare type GTFile = {
220
220
  documentId: string;
221
221
  versionId?: string;
222
+ fileName?: string;
222
223
  };
223
224
 
224
225
  /**
package/dist/index.js CHANGED
@@ -1362,12 +1362,21 @@ function getTranslationStrategyForType(type) {
1362
1362
  function getTranslationStrategy(document2) {
1363
1363
  return getTranslationStrategyForType(document2._type);
1364
1364
  }
1365
+ function getDocumentFileName(document2) {
1366
+ const slug = document2.slug?.current, label = [document2.title, document2.name, slug].find(
1367
+ (value) => typeof value == "string" && value.trim() !== ""
1368
+ )?.trim() ?? getDocumentPublishedId(document2);
1369
+ return `sanity/${document2._type}/${label}`;
1370
+ }
1371
+ function resolveFileName(info) {
1372
+ return info.fileName ?? `sanity/${info.documentId}`;
1373
+ }
1365
1374
  async function uploadFiles(documents, secrets) {
1366
1375
  return overrideConfig(secrets), await api.uploadSourceFiles(
1367
1376
  documents.map(({ info, serializedDocument }) => ({
1368
1377
  source: {
1369
1378
  content: serializedDocument.content,
1370
- fileName: `sanity/${info.documentId}`,
1379
+ fileName: resolveFileName(info),
1371
1380
  fileId: info.documentId,
1372
1381
  fileFormat: "HTML",
1373
1382
  locale: gt.sourceLocale || libraryDefaultLocale,
@@ -1577,7 +1586,7 @@ async function uploadTranslations(documents, secrets) {
1577
1586
  withTranslations.map(({ info, serializedDocument, translations }) => ({
1578
1587
  source: {
1579
1588
  content: serializedDocument.content,
1580
- fileName: `sanity/${info.documentId}`,
1589
+ fileName: resolveFileName(info),
1581
1590
  fileId: info.documentId,
1582
1591
  fileFormat: "HTML",
1583
1592
  locale: sourceLocale,
@@ -1585,7 +1594,7 @@ async function uploadTranslations(documents, secrets) {
1585
1594
  },
1586
1595
  translations: translations.map(({ locale, content }) => ({
1587
1596
  content,
1588
- fileName: `sanity/${info.documentId}`,
1597
+ fileName: resolveFileName(info),
1589
1598
  fileId: info.documentId,
1590
1599
  fileFormat: "HTML",
1591
1600
  locale,
@@ -2097,7 +2106,8 @@ const useTranslations = () => {
2097
2106
  return {
2098
2107
  info: {
2099
2108
  documentId: getDocumentPublishedId(doc),
2100
- versionId: doc._rev
2109
+ versionId: doc._rev,
2110
+ fileName: getDocumentFileName(doc)
2101
2111
  },
2102
2112
  serializedDocument: strategy.serialize(
2103
2113
  cleanDoc,
@@ -2775,7 +2785,7 @@ const useTranslations = () => {
2775
2785
  ] }) })
2776
2786
  }
2777
2787
  ) : null;
2778
- var version = "4.0.16";
2788
+ var version = "4.0.17";
2779
2789
  function buildDebugInfo({
2780
2790
  secrets,
2781
2791
  preferences,