layout: post
title: 七牛云图床存储+Alfread工做流+使用QSHELLjavascript
使用markdown最头疼的问题就是贴图问题。有多种方式来上传图片到图床,并得到外链的方面。而咱们所但愿最便捷以及最天然的方式就是,截取图片,而后粘贴进MarkDown编辑器的时候就自动上传到图床而且完成Markdown图片格式的编写。简单来讲就是但愿粘贴的时候就像粘贴图片到word同样,而后这些图片又是基于外链的,能够在任何有互联网的地方显示出来。html
大致能够分为三个部分:
1.七牛云的配置
2.qshell的配置
3.Alfread的配置java
若是尚未七牛云存储的帐号,能够自行前往官网申请帐号。提供10G的免费存储空间,每月10G的下载流量、10万次PUT/DELETE请求、100万次GET请求。注册你们都会就不说了。shell
在样式里面能够新建多种样式,来控制图片大小,毕竟markdown语法不能控制图片大小
json
在我的面板点击密钥管理
到https://developer.qiniu.com/kodo/tools/1302/qshell下载QSHELL,下载mac版本后重命名为qshell
新建目录用于放置配置文件以及数据文件以下:
修改qshell文件的权限,使他成为可执行文件
chmod 755 /User/apple/Download/qshell
并将qshell文件放置在CLI目录下,并在CLI目录建立conf.json配置文件,内容以下:markdown
{ "src_dir":"/Users/think/QiNiu/Data/",##本地图片数据目录 "bucket":"markdownImage",##七牛云空间名称 "rescan_local":true, "check_exists":true, "check_hash":true, "check_size":true }
配置qshell密钥,在CLI目录下打开终端,使用命令设置密钥app
qshell account [AccessKey] [SecretKey]
例如:qshell account kdajfiaifsanmflkwajfoiwr _fdaskrlakkkdasfanjjjj
编辑器
下载Alfred安装包并安装, 须要购买 Powerpack 才能解锁 workflows 功能,或者自行收索和谐版。
下载工做流:百度云盘 密码:q18a
导入以后修改脚本。
post
脚本内容以下。
property fileTypes : {¬ {«class PNGf», ".png"}, ¬ {JPEG picture, ".jpg"}} on getType() repeat with aType in fileTypes repeat with theInfo in (clipboard info) if (first item of theInfo) is equal to (first item of aType) then return aType end repeat end repeat return missing value end getType set theType to getType() if theType is not missing value then set filePath to "/Users/think/QiNiu/Data/" --这里换成你本身放置图片的路径 set fileName to do shell script "date \"+%Y%m%d%H%M%S\" | md5" --用当前时间的md5值作文件名 if fileName does not end with (second item of theType) then set fileName to (fileName & second item of theType as text) set markdownUrl to "" --这里是你的七牛域名和设置的图片样式 set filePath to filePath & fileName try set imageFile to (open for access filePath with write permission) set eof imageFile to 0 write (the clipboard as (first item of theType)) to imageFile close access imageFile set the clipboard to markdownUrl try tell application "System Events" keystroke "v" using command down end tell end try do shell script "/Users/think/QiNiu/CLI/qshell qupload /Users/think/QiNiu/CLI/conf.json" on error try close access imageFile end try return "" end try else return "" end if
须要修改以下地方
set filePath to "/Users/think/QiNiu/Data/"
--这里换成你本身放置图片的路径
set markdownUrl to ""
--这里是你的七牛域名和设置的图片样式,若没有样式使用set markdownUrl to ""
do shell script "/Users/think/QiNiu/CLI/qshell qupload /Users/think/QiNiu/CLI/conf.json"
修改以后保持,并为工做流添加快捷键。粘贴的时候使用快捷键粘贴便可