@tryghost/mg-substack 1.3.1 → 1.3.3

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.
Files changed (2) hide show
  1. package/lib/mapper.js +18 -11
  2. package/package.json +3 -3
package/lib/mapper.js CHANGED
@@ -72,19 +72,26 @@ export default async (input, options) => {
72
72
  return new errors.NoContentError({message: 'Input file is empty'});
73
73
  }
74
74
 
75
- // Inline the HTML we have with the CSV data
76
- input.meta.map((post) => {
77
- const thisPostHTML = input.posts.find(item => item.name.includes(post.post_id));
78
- post.html = thisPostHTML?.html ?? '';
79
- return post;
75
+ // Drive from HTML files we have, pulling in CSV metadata for each
76
+ const csvMeta = input.meta;
77
+ input = input.posts.map((htmlPost) => {
78
+ const postId = htmlPost.name.replace(/\.html$/, '');
79
+ const meta = csvMeta.find(item => item.post_id === postId);
80
+ if (meta) {
81
+ meta.html = htmlPost.html;
82
+ }
83
+ return meta;
84
+ }).filter(Boolean);
85
+
86
+ // Preserve consistent ordering (chronological, with numeric ID as tiebreaker)
87
+ input.sort((a, b) => {
88
+ const dateDiff = new Date(a.post_date) - new Date(b.post_date);
89
+ if (dateDiff !== 0) {
90
+ return dateDiff;
91
+ }
92
+ return parseInt(a.post_id) - parseInt(b.post_id);
80
93
  });
81
94
 
82
- // Delete the posts array
83
- delete input.posts;
84
-
85
- // Reassign the CSV array to input var
86
- input = input.meta;
87
-
88
95
  if (!options.posts) {
89
96
  debug(`Ignoring posts`);
90
97
  input = input.filter(data => data.type.toLowerCase() !== `newsletter`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryghost/mg-substack",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/TryGhost/migrate.git",
@@ -29,8 +29,8 @@
29
29
  "html-entities": "2.6.0",
30
30
  "simple-dom": "1.4.0",
31
31
  "srcset": "5.0.3",
32
- "@tryghost/mg-fs-utils": "0.23.1",
33
- "@tryghost/mg-utils": "0.8.1"
32
+ "@tryghost/mg-fs-utils": "0.23.3",
33
+ "@tryghost/mg-utils": "0.8.3"
34
34
  },
35
35
  "scripts": {
36
36
  "dev": "echo \"Implement me!\"",