npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

markdown-img-down-site-change

v1.3.3

Published

搜索目标文件夹中的markdown文件,找到目标图片,提供下载,替换链接的功能-通常用于markdown 图片失效

Downloads

47

Readme

markdown-img-down-site-change(下载/替换markdown中的图片)

搜索目标文件夹中的markdown文件,找到目标图片,提供下载图片,替换图片链接的功能-通常用于markdown 图片失效。

简介

这是一个极为轻量的脚本,引用包,设置好参数,通过API即可轻松上手。

解决什么问题?

  1. 集中下载markdown文件中某个域名下的图片到一个文件夹下。
  2. 用新的图片链接替换markdown文件中某个域名的图片链接。
// 1. 下载这两个图片
// ![](https://user-gold-cdn.xitu.io/2019/5/20/图片名字?w=2024&h=1240&f=png&s=339262)
// ![](https://user-gold-cdn.xitu.io/2018/6/16/图片名字)
// 2. 替换成:github的链接
![](https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/图片名字)
// 由于github的参数限制,带了参数就不能正常显示图片 所有这里默认取图片名前部分的:字母或数字或下划线或汉字

安装:

npm i markdown-img-down-site-change

文档:

Github

API

更新日志

数据安全:

刚上手可能不了解脚本的功能,需要调试一番,这时候万一把markdown文件给改坏了,岂不是要哭死?

脚本有两种形式来防止这种情况发生:

  1. 脚本会默认备份你的文件。
  2. 默认开启测试模式,等到调试的差不多了,可以关闭测试模式。
  3. 建议:再不放心的话,可以先用一两个文件来测试一下脚本

插件使用姿势:

我是这样使用的,大家可以做个参考:

  1. 新建一个github项目,专门用于存放图片资源
  2. npm init初始化package.json 文件,下载npm包:npm i markdown-img-down-site-change,
  3. 新建一个handleImg.js文件,参考:example.js
  4. 拷贝你的markdown文件夹到该项目,执行node handleImg.js
  5. 将会搜索所有.md文件,下载匹配到的图片到项目的根目录。
  6. 默认不修改文件,默认开启备份,匹配规则、过滤某些文件夹等更多配置信息参阅:API文档

比如我的github图床:articleImg_src

使用:20行代码不到

在项目中有一个使用栗子,里面加了蛮多注释和空行的,实际代码20行都不到,可以说很简单了,如下:

// npm i markdown-img-down-site-change -S 
const markdownImageDown = require('markdown-img-down-site-change'); // 文件模块

// 传参: 这也是脚本的默认参数,根据情况可以自行修改
let option = {
    replace_image_url: 'https://user-gold-cdn.xitu.io/',
    read_markdown_src: './source', // 要查找markdown文件的文件夹地址
    down_img_src: './juejin', // 下载图片到这个文件夹
    var_number: 3 // url前半部分的变量数量 比如上面的日期: /2019/5/20/、/2018/6/16/
}

// 初始化
const markdownImage = new markdownImageDown(option)

// 下载外链
markdownImage.checkDownImg();

// 上传下载下来的图片文件夹到云端 用户自己操作

// 上传图片之后 
// 脚本会把以前的外链替换成云端地址+拼接一个图片名
markdownImage.updateOption({
    new_image_url: 'https://xxx.com/目录地址/', // 图片上传的地址
    add_end: '?raw=true' // github图片地址有后缀 直接进去是仓库
})

// 替换外链 
// 把replace_image_url的字符串换成new_image_url字符串
markdownImage.replaceMarkdown();

运行:

仔细阅读文本,配置好参数之后

在项目根节点新建一个handleImg.js文件,安装一下脚本,然后用node运行该文件:

npm i markdown-img-down-site-change -S
node handleImg.js

欢迎试用

有需要的小伙伴,赶紧来试试吧!文档写的很全,上手非常轻松,项目将会持续维护,有什么问题,欢迎给我提issue~

如果觉得这个脚本还不错的话,就给项目点个Star吧!