Skip to content

Commit

Permalink
docs: fix images (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
paradite authored Jun 1, 2019
1 parent 477ab84 commit c6a5c7c
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/guide/get-device-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ $ adb devices
$ DEVELOPMENT_TEAM_ID=TEAM_ID npm i app-inspector -g
```

![](https://wx1.sinaimg.cn/large/6d308bd9gy1fg7cnt9hf6j20t70h7782.jpg)
![](/app-inspector/assets/6d308bd9gy1fg7cnt9hf6j20t70h7782.jpg)
2 changes: 1 addition & 1 deletion docs/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ You will see the log information like below:
Then open the link http://192.168.10.100:5678 in your browser.

![](https://ww4.sinaimg.cn/large/7dfcf2f7gw1f77ev6csw5g20s50iwe81.gif)
![](/app-inspector/assets/7dfcf2f7gw1f77ev6csw5g20s50iwe81.gif)
2 changes: 1 addition & 1 deletion docs/zh/guide/get-device-id.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ $ adb devices
$ DEVELOPMENT_TEAM_ID=TEAM_ID npm i app-inspector -g
```

![](http://wx1.sinaimg.cn/large/6d308bd9gy1fg7cnt9hf6j20t70h7782.jpg)
![](/app-inspector/assets/6d308bd9gy1fg7cnt9hf6j20t70h7782.jpg)
2 changes: 1 addition & 1 deletion docs/zh/guide/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ $ app-inspector -u YOUR-DEVICE-ID
然后在浏览器里面打开输出的链接:http://192.168.10.100:5678。推荐用 Chrome 浏览器。

![](http://ww4.sinaimg.cn/large/7dfcf2f7gw1f77ev6csw5g20s50iwe81.gif)
![](/app-inspector/assets/7dfcf2f7gw1f77ev6csw5g20s50iwe81.gif)
84 changes: 84 additions & 0 deletions scripts/replace-image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// npm i
// create ./docs/.vuepress/public/assets/ directory
// node ./scripts/replace-image.js docs/

'use strict';

const fs = require('fs');
const path = require('path');
const request = require('request');

const download = function(uri, filename, callback) {
request.head(uri, function(err, res) {
if (err) {
console.log(err);
}
console.log(uri);
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);

request(uri)
.pipe(fs.createWriteStream(filename))
.on('close', callback);
});
};

const prefix = '/app-inspector';

// List all files in a directory in Node.js recursively in a synchronous fashion
const walkSync = function(dir, fileList) {
const files = fs.readdirSync(dir);
fileList = fileList || [];
files.forEach(function(file) {
if (fs.statSync(dir + file).isDirectory()) {
fileList = walkSync(dir + file + '/', fileList);
} else {
fileList.push(path.join(dir, file));
}
});
return fileList;
};

if (process.argv.length <= 2) {
console.log('Usage: ' + __filename + ' path/to/directory');
process.exit(-1);
}

const targetPath = process.argv[2];

const fileList = walkSync(targetPath, []);
const mdList = fileList.filter(file => file.endsWith('.md'));

function replacer(match, p1, p2, p3, p4, p5, p6, p7) {
console.log(p1, p2, p3, p4, p5, p6, p7, match);
download(
match.startsWith('//') ? 'https:' + match : match,
'./docs/.vuepress/public/assets/' + [ p6, p7 ].join('.'),
function() {
console.log(match + ' done');
}
);
return prefix + '/assets/' + [ p6, p7 ].join('.');
}

mdList.forEach(file => {
fs.readFile(file, 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
// console.log(data);
console.log(file);
// const matchRes = data.match(
// /(http(s?):)*\/\/([/.\w\s-])*(sinaimg\.cn\/)(large|square)\/([\w]*)\.(jpg|gif|png)/g
// );
// console.log(matchRes);
const result = data.replace(
/(http(s?):)*\/\/([/.\w\s-])*(sinaimg\.cn\/)(large|square)\/([\w]*)\.(jpg|gif|png)/g,
replacer
);
console.log(result);
fs.writeFile(file, result, 'utf8', function(err) {
if (err) return console.log(err);
});
});
});

0 comments on commit c6a5c7c

Please sign in to comment.