Blog pictures fail? Use npm Tools download / replace all failed pictures of foreign chains

Foreword

About a month ago, the picture outside the chain microblogging failure, as well as problems in Denver because Daolian 2019/06/06decided to open the security chain , the impact is: quote personal blog site, these pictures outside the chain can not be displayed .

Currently microblogging Nuggets and shield, we are in the CSDN and segmentfault can be displayed, and only affects personal blog .

For example, some time ago my blog: http://obkoro1.com quoted on the microblogging picture can not show up.

Because I write a blog more frequently, blocked a few pictures, one certainly can not replace the manual, the investigation did not find a lot of ready-made solution, made a scripting tool, and wrote out a document to open it.

markdown-img-down-site-change (download / replace markdown pictures)

markdown file search destination folder, find the target picture, download pictures, replacing the image links function - commonly used markdown picture fail.

Brief introduction

This is an extremely lightweight script that references the package, set the parameters, you can easily get started through the API.

Solve the problem?

  1. Download pictures focused at markdown file a domain name to a folder.
  2. Links to replace image link markdown file a domain name with the new picture.
// 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/图片名字?w=2024&h=1240&f=png&s=339262)
![](https://raw.githubusercontent.com/OBKoro1/articleImg_src/master/juejin/图片名字)

installation:

npm i markdown-img-down-site-change -S

Documents:

Github

API

Update Log

Data Security:

Just get started function may not understand the script, debugging may be required, this time the case markdownfile to change the bad, are we going to Kusi?

There are two forms of script to prevent this from happening:

  1. The script will default to back up your files.
  2. Enabled by default test mode , until almost debugging, test mode can be turned off.
  3. Recommendation: do not worry, you can start with one or two files to test scripts

Use: less than 20 lines of code

There in the project use a chestnut , which add find many comments and blank lines, 20 rows less than the actual code, can be very simple, as follows:

// 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();

run:

After carefully reading the text, configure parameters

In the project root node to create a new handleImg.jsfile, installed at the script, and then noderun the file:

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

Function / Parameter Description:

  • checkDownImg(): Download found picture
  • replaceMarkdown(): Replace the image link to a new image link
  • replace_image_url: To replace the address of the picture
  • new_image_url: Pictures of the new address
  • test: Test mode.
  • var_number: Matching image links url before the picture name, is the number of variables
  • is_link: Matches link.
  • write_file_time: How often modify markdown image link
  • read_markdown_src: To find the markdown file folder address
  • down_img_src: Download pictures to this address at
  • copy_item_data: Backup Project
  • filter_item: Filter some folders, do not look for markdown.
  • add_end: Add a suffix suffix in the picture behind link

Welcome to the beta

There is a need of a small partner, hurry to try it! Documents written in a very full, very easy to get started, the project will continue to maintain, what questions, please give me Issue ~

If you think this script is not bad, then give the project the point of a Star of it!

Blog , the front end of the accumulation of documents , the public number , wx: OBkoro1, E-mail: [email protected]

More 2019.06.04

Guess you like

Origin www.cnblogs.com/OBkoro1/p/10978670.html