Setting the file. One moment.
Blog Post Build Stage · Rp Target Wix · wix/skills · Skills Docs
ContentsBack to the top of the page 41.10
Multilingual Restore
(opens in a new tab)
lib/ blog-post-build-stage.js
JavaScript · 55 lines · 3 KB
({
projectDir
,
sourcePosts
,
preparedPosts
,
client
,
crosswalk
,
10 pendingMedia , runId , checks = [], transforms = {}, options = {} }) {
11 if ( ! Array. isArray (sourcePosts) || ! Array. isArray (preparedPosts))
12 throw new Error ( 'blog stage needs sourcePosts and preparedPosts arrays' );
13 if ( ! crosswalk || typeof crosswalk.get !== 'function' ||
14 typeof crosswalk.idOwners !== 'function' || typeof crosswalk.set !== 'function' ||
15 typeof crosswalk.recordVerified !== 'function' ) throw new Error ( 'blog stage needs bound crosswalk operations' );
16 if ( ! pendingMedia) throw new Error ( 'blog stage needs pending media state' );
17 const byKey = new Map (sourcePosts. map ( post => [media. postStableKey (post), post]));
18 const preparedByKey = new Map (preparedPosts. map ( post => [post.sourceStableKey, post]));
19 if (byKey.size !== sourcePosts. length || preparedByKey.size !== preparedPosts. length ||
20 preparedPosts. some ( post => ! byKey. has (post.sourceStableKey))) throw new Error ( 'blog stage source keys differ' );
21 const report = await build. runBlogBuild ({ projectDir, posts: preparedPosts, client,
22 crosswalk, checks, transforms, options: { ... options, runId } });
23 const state = ledger. fold (ledger. readRows (projectDir));
24 for ( const row of report.addresses. filter ( item => item.phase === 'verified' )) {
25 if ( ! byKey. has (row.sourceStableKey)) continue ; // a resumed batch may omit earlier verified posts
26 const phase = state.posts. get (row.sourceStableKey)?.phase;
27 if ( ! phase?.postId) throw new Error ( `verified blog post ${ row . sourceStableKey } lacks post id` );
28 await crosswalk. recordVerified (byKey. get (row.sourceStableKey), phase.postId);
29 const prepared = preparedByKey. get (row.sourceStableKey);
30 if (prepared.existingCrosswalk) {
31 await pendingMedia. closeIfCrosswalked (byKey. get (row.sourceStableKey).id,
32 { targetPostId: phase.postId, runId });
33 } else {
34 await pendingMedia. markResolved (byKey. get (row.sourceStableKey).id,
35 { targetPostId: phase.postId, runId, resumed: prepared.mediaResumed === true });
36 }
37 }
38 const pending = await media. summarizePendingBlogMedia ({ state: pendingMedia,
39 crosswalk : key => state.posts. get (key)?.phase?.phase === 'verified' });
40 // A pre-ledger crosswalk hit can have unresolved local media evidence without an
41 // open pending-media row (including an already-resolved historical row). Its build
42 // phase is still a pending post and must count against import completion.
43 const present = new Set (pending.pending. map ( row => row.sourceStableKey));
44 for ( const row of report.pending) {
45 if (present. has (row.sourceStableKey)) continue ;
46 pending.pending. push ({ sourceStableKey: row.sourceStableKey,
47 title: byKey. get (row.sourceStableKey)?.title || null , awaitingWrite: false ,
48 reason: row.reason, media: row.media, existingCrosswalk: Boolean (preparedByKey. get (row.sourceStableKey)?.existingCrosswalk) });
49 present. add (row.sourceStableKey);
50 }
51 pending.pendingMedia = pending.pending. length ;
52 return { report, pending };
53 }
54
55 module . exports = { runBlogBuildStage };