Skip to content

Commit

Permalink
docs(doc): add artalk migration support
Browse files Browse the repository at this point in the history
fix #81
  • Loading branch information
lizheming committed Dec 22, 2020
1 parent b305af2 commit a4548a9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
66 changes: 66 additions & 0 deletions docs/.vuepress/components/MigrationTool.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<option value="disqus">Disqus</option>
<option value="twikoo">Twikoo</option>
<option value="typecho">Typecho</option>
<option value="artalk">Artalk</option>
</select>
</div>
<div class="input-group">
Expand Down Expand Up @@ -42,6 +43,8 @@
</form>
</template>
<script>
import marked from 'marked';
const m = {
valine: {
wcloudbase: lc2tcb,
Expand All @@ -55,6 +58,69 @@ const m = {
wsql(data) {
return lc2csv(tk2lc(data));
}
},
artalk: {
wleancloud: artalk2lc,
wcloudbase(data) {
return lc2tcb(artalk2lc(data))
},
wsql(data) {
return lc2csv(artalk2lc(data))
}
}
}
//artalk 数据结构转 leancloud
function artalk2lc(input) {
input = JSON.parse(input);
function parseKey(key) {
const anchor = document.createElement('a');
anchor.href = key;
return anchor.pathname || key;
}
const idMap = {};
for(let i = 0; i < input.length; i++) {
idMap[ input[i].id ] = input[i].rid;
}
const rootIdMap = {};
for(let i = 0; i < input.length; i++) {
if(!input[i].rid) {
continue;
}
let rid = input[i].rid;
while(idMap[rid]) {
rid = idMap[rid];
}
rootIdMap[ input[i].id ] = rid;
}
return {
results: input.map(({content, date, email, id, ip, link, nick, page_key, rid, ua}) => {
const time = new Date(date.replace(/-/g, '/')).toISOString();
const url = parseKey(page_key);
return {
objectId: id,
QQAvatar: '',
comment: marked(content),
insertedAt: {
__type: 'Date',
iso: time
},
createdAt: time,
updatedAt: time,
ip: ip,
link: link,
nick: nick,
ua: ua,
url: url,
pid: rid ? rid : '',
rid: rootIdMap[id] || '',
status: 'approved'
};
})
}
}
//twikoo 数据结构转 leancloud
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"conventional-changelog-cli": "^2.1.1",
"cz-conventional-changelog": "^3.3.0",
"husky": "^4.3.0",
"marked": "^1.2.5",
"vuepress": "^1.7.1"
},
"config": {
Expand Down

0 comments on commit a4548a9

Please sign in to comment.