分享一款将 LeetCode 中 AC 的题目转化为 MarkDown 表格的插件 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
muyunyun
V2EX    分享创造

分享一款将 LeetCode 中 AC 的题目转化为 MarkDown 表格的插件

  •  
  •   muyunyun
    MuYunyun 2020-09-30 13:17:18 +08:00 2491 次点击
    这是一个创建于 1836 天前的主题,其中的信息可能已经有所发展或是发生改变。

    背景: 写博客的时候每当新增 LeetCode 题解时都需要在 https://github.com/MuYunyun/blog/blob/master/LeetCode/README.md 手动更新表格, 非常费劲。因此构思了该插件实现自动化同步更新 leetcode ac 题解为 markdown table 。

    crd-leetcode-cli

    crd-leetcode-cli 提供将 leetcode 中已 AC 的题目转化为 markdown 表格的能力。

    Install

    执行 yarn add crd-leetcode-cli -g, 国内用户可以执行 cnpm install crd-leetcode-cli -g

    Usage

    leetcode download // 增量拉取 AC 题目(若无登录, 则会先执行登录逻辑) leetcode download -a // 全量拉取 AC 题目 leetcode login // 登录 leetcode logout // 登出 

    接入项目示例

    Render Markdown Table Customly

    插件提供了自定义渲染 markdown table 的能力。

    const transform_markdown_table = (dataArr) => { const beforeDescription = `The markdown table is generated by [crd-leetcode-cli]( https://github.com/MuYunyun/create-react-doc/tree/master/packages/leetcode-cli)`; let result = beforeDescription + '\n' + '| # | Title | Explanation | Difficulty | Type |' + '\n' + '|:---:|:---:|:---:|:---:|:---:|'; for (let i = 0; i < dataArr.length; i++) { result += `\n| ${dataArr[i].questionId} | [${dataArr[i].title }]( https://leetcode.com/problems/${dataArr[i].titleSlug }/) | [Analyze]( https://github.com/MuYunyun/blog/blob/master/LeetCode/${dataArr[i].questionId }.${dataArr[i].title.split(' ').join('_')}.md) | ${dataArr[i].difficulty } | ${dataArr[i].topicTags} |`; } return result; }; module.exports = { transform_markdown_table } 

    通过自定义 transform_markdown_table 函数, 便可得到如下 markdown table:

    Technology Details

    6 条回复    2020-10-06 18:16:00 +08:00
    jiangshanmeta
        1
    jiangshanmeta  
       2020-09-30 15:58:21 +08:00
    题主 为了完成同样的事情,我只用了一个[node 脚本]( https://github.com/jiangshanmeta/meta/blob/master/scripts/generate.js)
    muyunyun
        2
    muyunyun  
    OP
       2020-09-30 18:31:26 +08:00
    @jiangshanmeta 神奇, 调用 restful 接口不用 cookie 就能访问么。。我这边多了一步登陆操作, 成本其实相差不大, 后续涉及到编辑的接口也能访问了。
    muyunyun
        3
    muyunyun  
    OP
       2020-09-30 18:34:15 +08:00
    asanelder
        4
    asanelder  
       2020-09-30 19:22:11 +08:00
    挺好,不错,鼓励,给个赞
    xrr2016
        5
    xrr2016  
       2020-10-01 07:33:57 +08:00 via iPhone
    标记
    muyunyun
        6
    muyunyun  
    OP
       2020-10-06 18:16:00 +08:00
    @asanelder 谢啦
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     2851 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 00:23 PVG 08:23 LAX 17:23 JFK 20:23
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86