Skip to content

批量修改文章和其他地方的图片链接 #6465

Answered by guqing
junyangfan asked this question in Q&A
Discussion options

You must be logged in to vote

还有个办法就是从 console 导出一个备份然后解压

const fs = require('fs');

function decodeBase64(base64String) {
  return decodeURIComponent(escape(atob(base64String)));
}

function encodeBase64(str) {
  return btoa(unescape(encodeURIComponent(str)));
}

function replaceInJsonData(jsonArray, searchString, replaceString) {
  jsonArray.forEach(item => {
    if (item.data) {
      const decodedData = decodeBase64(item.data);
      
      const replacedData = decodedData.replace(new RegExp(searchString, 'g'), replaceString);
      
      item.data = encodeBase64(replacedData);
    }
  });
  return jsonArray;
}

function processJsonFile(inputFilePath, outputFilePath, searchString, replaceString) {
  fs.readFile(i…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@junyangfan
Comment options

@JohnNiang
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by guqing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants