-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
94 lines (91 loc) · 2.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
var USER_ID = 2;
var USER_ROLE = 3;
var USER_EMAIL = hexo.config.email || '[email protected]';
var postAndPageGenerator = function(post, isPage, published) {
return {
id: post._id,
title: post.title,
slug: post.slug,
markdown: post._content,
html: post.content,
image: null,
featured: 0,
page: isPage,
status: post.published ? 'published' : 'draft', //or draft
language: '',
meta_title: null,
meta_description: null,
author_id: USER_ID,
created_at: +post.date,
created_by: USER_ID,
updated_at: +post.updated,
updated_by: USER_ID,
published_at: +post.date,
published_by: USER_ID,
allow_comment: post.comment
};
};
var postGenerator = function(post) { return postAndPageGenerator(post, 0, post.published); }
var pageGenerator = function(page) { return postAndPageGenerator(page, 1, true); }
var ghost = {
meta: {
exported_on: Date.now(),
version: '008'
},
data: {
posts: [],
tags: [],
posts_tags: [],
categories: [],
posts_categories: [],
users: [{
id: USER_ID,
slug: hexo.config.author,
name: hexo.config.author,
email: USER_EMAIL
}],
role_users: [{
user_id: USER_ID,
role_id: USER_ROLE
}]
}
};
hexo.extend.generator.register('json-content2', function(locals) {
if( locals.posts.length ) {
ghost.data.posts = locals.posts.sort('-date').map(function(post) {
ghost.data.categories = ghost.data.categories.concat(post.categories.map(function(category) {
ghost.data.posts_categories.push({
category_id: category._id,
post_id: post._id
});
return {
id: category._id,
name: category.name,
slug: category.slug,
parent: category.parent,
description: ''
};
}));
ghost.data.tags = ghost.data.tags.concat(post.tags.map(function(tag) {
ghost.data.posts_tags.push({
tag_id: tag._id,
post_id: post._id
});
return {
id: tag._id,
name: tag.name,
slug: tag.slug,
description: ''
}
}));
return postGenerator(post);
});
}
if( locals.pages.length ) {
ghost.data.posts = ghost.data.posts.concat(locals.pages.sort('-date').map(pageGenerator));
}
return {
path: hexo.config.exportFileName || 'export.json',
data: JSON.stringify(ghost, null, '\t')
};
});