1
- import crypto from 'crypto' ;
2
-
3
1
import chalk from 'chalk' ;
4
2
import config from 'config' ;
5
3
import { Headers } from 'node-fetch' ;
@@ -29,28 +27,27 @@ export default async function pushDoc(
29
27
filepath : string ,
30
28
type : CommandCategories
31
29
) {
32
- const { content, matter, slug } = readDoc ( filepath ) ;
33
- const hash = crypto . createHash ( 'sha1' ) . update ( content ) . digest ( 'hex' ) ;
30
+ const { content, data, hash, slug } = readDoc ( filepath ) ;
34
31
35
- let data : {
32
+ let payload : {
36
33
body ?: string ;
37
34
html ?: string ;
38
35
htmlmode ?: boolean ;
39
36
lastUpdatedHash : string ;
40
- } = { body : matter . content , ... matter . data , lastUpdatedHash : hash } ;
37
+ } = { body : content , ...data , lastUpdatedHash : hash } ;
41
38
42
39
if ( type === CommandCategories . CUSTOM_PAGES ) {
43
40
if ( filepath . endsWith ( '.html' ) ) {
44
- data = { html : matter . content , htmlmode : true , ... matter . data , lastUpdatedHash : hash } ;
41
+ payload = { html : content , htmlmode : true , ...data , lastUpdatedHash : hash } ;
45
42
} else {
46
- data = { body : matter . content , htmlmode : false , ... matter . data , lastUpdatedHash : hash } ;
43
+ payload = { body : content , htmlmode : false , ...data , lastUpdatedHash : hash } ;
47
44
}
48
45
}
49
46
50
47
function createDoc ( ) {
51
48
if ( dryRun ) {
52
49
return `🎭 dry run! This will create '${ slug } ' with contents from ${ filepath } with the following metadata: ${ JSON . stringify (
53
- matter . data
50
+ data
54
51
) } `;
55
52
}
56
53
@@ -65,14 +62,14 @@ export default async function pushDoc(
65
62
) ,
66
63
body : JSON . stringify ( {
67
64
slug,
68
- ...data ,
65
+ ...payload ,
69
66
} ) ,
70
67
} )
71
68
. then ( res => handleRes ( res ) )
72
69
. then ( res => `🌱 successfully created '${ res . slug } ' (ID: ${ res . id } ) with contents from ${ filepath } ` ) ;
73
70
}
74
71
75
- function updateDoc ( existingDoc : typeof data ) {
72
+ function updateDoc ( existingDoc : typeof payload ) {
76
73
if ( hash === existingDoc . lastUpdatedHash ) {
77
74
return `${ dryRun ? '🎭 dry run! ' : '' } \`${ slug } \` ${
78
75
dryRun ? 'will not be' : 'was not'
@@ -81,7 +78,7 @@ export default async function pushDoc(
81
78
82
79
if ( dryRun ) {
83
80
return `🎭 dry run! This will update '${ slug } ' with contents from ${ filepath } with the following metadata: ${ JSON . stringify (
84
- matter . data
81
+ data
85
82
) } `;
86
83
}
87
84
@@ -96,7 +93,7 @@ export default async function pushDoc(
96
93
) ,
97
94
body : JSON . stringify (
98
95
Object . assign ( existingDoc , {
99
- ...data ,
96
+ ...payload ,
100
97
} )
101
98
) ,
102
99
} )
0 commit comments