vim-jpのchannel情報をscrapbox json dataに変換
code:sh
code:script.ts
import {getChannels} from './mod.ts';
const pages = (await getChannels()).map(({
name,
created,
topic,
purpose,
}) =>{
return {
title: name,
created: getUnixTime(created),
updated: getUnixTime(created),
lines: [
name,
'Topic',
${topic},
'Purpose',
${purpose},
'',
created at [${lightFormat(created, 'yyyy-MM')}],
'#channel',
],
};
});
await Deno.writeTextFile('channels.json', JSON.stringify({pages}));
説明文中のリンクは置換しておく
code:mod.ts
type Channel = {
id: string;
name: string;
created: number;
is_archived: boolean;
topic: {
value: string;
};
purpose: {
value: string;
};
};
export async function getChannels() {
const channels = (await res.json()) as Channel[];
return channels.map(({
name,
id,
created,
topic,
purpose,
}) =>({
id,
name,
created: new Date(created * 1000),
topic: format(topic.value),
purpose: format(purpose.value),
}));
}
channelへのリンクを置換する
code:mod.ts
function format(text: string) {
return text.replace(/<#\w\d+\|(^>+)>/g, '$1'); }