vim-jpのchannel情報をscrapbox json dataに変換
vim-jp slacklog/log-dataにあるchannel情報をscrapbox json dataに変換してみる
/takker-test-vim-jp
code:sh
deno run --allow-write=./channels.json --allow-net=raw.githubusercontent.com -r=https://scrapbox.io/api/code/takker/vim-jpのchannel情報をscrapbox_json_dataに変換/script.ts https://scrapbox.io/api/code/takker/vim-jpのchannel情報をscrapbox_json_dataに変換/script.ts
code:script.ts
import {getChannels} from './mod.ts';
import {getUnixTime, lightFormat} from 'https://deno.land/x/date_fns@v2.15.0/index.js';
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 res = await fetch('https://raw.githubusercontent.com/vim-jp/slacklog/log-data/slacklog_data/channels.json');
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');
}
#2021-07-02 00:25:30
#2021-07-01 19:06:58