MCPcopy Create free account
hub / github.com/decaporg/decap-cms / processUnpublishedEntry

Method processUnpublishedEntry

packages/decap-cms-core/src/backend.ts:1026–1108  ·  view source on GitHub ↗
(
    collection: Collection,
    entryData: UnpublishedEntry,
    withMediaFiles: boolean,
  )

Source from the content-addressed store, hash-verified

1024 }
1025
1026 async processUnpublishedEntry(
1027 collection: Collection,
1028 entryData: UnpublishedEntry,
1029 withMediaFiles: boolean,
1030 ) {
1031 const { slug } = entryData;
1032 let extension: string;
1033 if (collection.get('type') === FILES) {
1034 const file = collection.get('files')!.find(f => f?.get('name') === slug);
1035 extension = extname(file.get('file'));
1036 } else {
1037 extension = selectFolderEntryExtension(collection);
1038 }
1039
1040 const mediaFiles: MediaFile[] = [];
1041 if (withMediaFiles) {
1042 const nonDataFiles = entryData.diffs.filter(d => !d.path.endsWith(extension));
1043 const files = await Promise.all(
1044 nonDataFiles.map(f =>
1045 this.implementation!.unpublishedEntryMediaFile(
1046 collection.get('name'),
1047 slug,
1048 f.path,
1049 f.id,
1050 ),
1051 ),
1052 );
1053 mediaFiles.push(...files.map(f => ({ ...f, draft: true })));
1054 }
1055
1056 const dataFiles = sortBy(
1057 entryData.diffs.filter(d => d.path.endsWith(extension)),
1058 f => f.path.length,
1059 );
1060
1061 const formatData = (data: string, path: string, newFile: boolean) => {
1062 const entry = createEntry(collection.get('name'), slug, path, {
1063 raw: data,
1064 isModification: !newFile,
1065 label: collection && selectFileEntryLabel(collection, slug),
1066 mediaFiles,
1067 updatedOn: entryData.updatedAt,
1068 author: entryData.pullRequestAuthor,
1069 status: entryData.status,
1070 meta: { path: prepareMetaPath(path, collection) },
1071 });
1072
1073 const entryWithFormat = this.entryWithFormat(collection)(entry);
1074 return entryWithFormat;
1075 };
1076
1077 const readAndFormatDataFile = async (dataFile: UnpublishedEntryDiff) => {
1078 const data = await this.implementation.unpublishedEntryDataFile(
1079 collection.get('name'),
1080 entryData.slug,
1081 dataFile.path,
1082 dataFile.id,
1083 );

Callers 2

unpublishedEntriesMethod · 0.95
unpublishedEntryMethod · 0.95

Calls 11

selectEntryPathFunction · 0.90
hasI18nFunction · 0.90
getI18nDataFilesFunction · 0.90
groupEntriesFunction · 0.90
getMethod · 0.80
findMethod · 0.80
filterMethod · 0.80
mapMethod · 0.80
getEntryMethod · 0.45

Tested by

no test coverage detected