-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_info.php
73 lines (65 loc) · 1.95 KB
/
post_info.php
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
<?php
$contents_all = json_decode(file_get_contents('typecho_contents.json'), true)[2]['data'];
$metas_all = json_decode(file_get_contents('typecho_metas.json'), true)[2]['data'];
$relationships_all = json_decode(file_get_contents('typecho_relationships.json'), true)[2]['data'];
$post_sort = [];//文章数据合集
$pid_list = [];//文章id合集
//文章基础信息载入
foreach ($contents_all as $value) {
$pid = $value['cid'];
$type = $value['type'];
if ($type == 'post_draft') {
$type = 'post';
}
if($type != "post" && $type != "page") continue;
$time = date('Y-m-d H:i:s', $value['created']);
array_push($pid_list, $pid);
$post_sort[$pid] = array(
"pid" => $pid,
"title" => $value['title'],
"type" => $value['type'],
"tag" => [],
"category" => [],
);
}
//metas基础信息载入
$metas_sort = [];//metas数据合集
foreach ($metas_all as $value) {
$mid = $value['mid'];
$name = $value['name'];
$slug = $value['slug'];
$type = $value['type'];
$description = $value['description'];
$metas_sort[$mid] = array(
"mid" => $mid,
"name" => $name,
"slug" => $slug,
"type" => $type,
"description" => $description,
);
}
//处理tag和category
foreach ($relationships_all as $value) {
$pid = $value['cid'];
$mid = $value['mid'];
if (!in_array($pid, $pid_list)) continue;
$metas_now = $metas_sort[$mid];
array_push($post_sort[$pid][$metas_now['type']], $metas_now['slug']);
}
$out = [];
//开始写出文件
foreach ($post_sort as $value) {
$category = "";
if (count($value['category']) != 0) {
$category = $value['category'][0];
}
$out[$value['pid']] = array(
"category" => $category,
"type" => $value['type']
);
echo "Complete: ".$value['title']."\n";
}
echo "All files processed!";
//写入文件
$file = fopen("./post_info.json", "w");
fwrite($file, json_encode($out));