Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add in-file image one-click upload and replace function & add zh-cn support #151

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"editor.formatOnSave": false
},
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"eslint.packageManager": "yarn",
"typescript.tsdk": "node_modules\\typescript\\lib",
Expand Down
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
!LICENSE
!package.json
!package.nls.json
!package.nls.zh-cn.json
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@

## Features

<details>
<summary>Uploading all local images in the current file and get those links replaced</summary>
<img src="https://s2.loli.net/2024/12/03/tiGcY68V2kjIgPZ.gif" alt="replace.gif">
</details>

<details>
<summary>Generating uploaded version of the document while keeping the original hierarchy(when the option is enabled)</summary>
<img src="https://s2.loli.net/2024/12/03/NKjXSIr1YJHasxf.gif" alt="generate.gif">
</details>

<details>
<summary>Uploading an image from clipboard</summary>
<img src="https://i.loli.net/2019/04/09/5cac17d2d2265.gif" alt="clipboard.gif">
Expand Down
15 changes: 15 additions & 0 deletions assets/TestFolder/A/AA/testAA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../../test.png "picgo logo")

is

<img src="../../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/TestFolder/A/AB/testAB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../../test.png "picgo logo")

is

<img src="../../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/TestFolder/A/testA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../test.png "picgo logo")

is

<img src="../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/TestFolder/B/testB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../test.png "picgo logo")

is

<img src="../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../test.png]]


test file
Empty file removed assets/test.md
Empty file.
16 changes: 16 additions & 0 deletions assets/testRoot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This

![TEST](test.png "picgo logo")
![TEST](<test.png> "picgo logo")

is

<img src="test.png" style="width:30px">

a

<!-- obsidian format -->
![[test.png]]


test file
15 changes: 15 additions & 0 deletions assets/uploadedVersion/TestFolder/A/AA/testAA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../../test.png "picgo logo")

is

<img src="../../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/uploadedVersion/TestFolder/A/AB/testAB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../../test.png "picgo logo")

is

<img src="../../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/uploadedVersion/TestFolder/A/testA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../test.png "picgo logo")

is

<img src="../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/uploadedVersion/TestFolder/B/testB.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](../../test.png "picgo logo")

is

<img src="../../test.png" style="width:30px">

a

<!-- obsidian format -->
![[../../test.png]]


test file
15 changes: 15 additions & 0 deletions assets/uploadedVersion/testRoot.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This

![TEST](test.png "picgo logo")

is

<img src="test.png" style="width:30px">

a

<!-- obsidian format -->
![[test.png]]


test file
4 changes: 3 additions & 1 deletion esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ const resultHandler = async (result) => {
const outdir = './dist'

// clean old built files
fse.rmdirSync(outdir, { recursive: true })
if (fse.existsSync(outdir)) {
fse.rmdirSync(outdir, { recursive: true })
}

/** @type {import('esbuild').BuildOptions} */
const commonOptions = {
Expand Down
49 changes: 45 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"image upload",
"picture upload"
],
"version": "2.1.6",
"version": "2.2.1",
"publisher": "Spades",
"engines": {
"vscode": "^1.60.0"
Expand All @@ -29,6 +29,8 @@
"onCommand:picgo.uploadImageFromInputBox",
"onCommand:picgo.webviewDemo",
"onCommand:picgo.webviewPicGoControlPanel",
"onCommand:picgo.generateUploadedImageVersionMarkdown",
"onCommand:picgo.uploadAndReplaceAllImageLinksInTheCurrentFile",
"workspaceContains:vs-picgo-auto-launch.txt"
],
"main": "./dist/extension",
Expand Down Expand Up @@ -58,6 +60,16 @@
"command": "picgo.webviewPicGoControlPanel",
"title": "%command.webview.picGoControlPanel.title%",
"category": "PicGo"
},
{
"command": "picgo.generateUploadedImageVersionMarkdown",
"title": "%command.generate.uploadedImageVersionMarkdown.title%",
"category": "PicGo"
},
{
"command": "picgo.uploadAndReplaceAllImageLinksInTheCurrentFile",
"title": "%command.uploadedImageVersionMarkdownInTheSameFile.title%",
"category": "PicGo"
}
],
"keybindings": [
Expand All @@ -75,12 +87,27 @@
"command": "picgo.uploadImageFromInputBox",
"key": "ctrl+alt+O",
"mac": "cmd+alt+O"
},
{
"command": "picgo.generateUploadedImageVersionMarkdown",
"key": "ctrl+alt+G",
"mac": "ctrl+alt+G"
},
{
"command": "picgo.uploadAndReplaceAllImageLinksInTheCurrentFile",
"key": "ctrl+alt+R",
"mac": "ctrl+alt+R"
}
],
"configuration": {
"type": "object",
"title": "%config.title%",
"properties": {
"picgo.useUploadVersionFolder": {
"type": "boolean",
"default": false,
"description": "Whether to save uploaded version files in a separate 'uploadVersion' folder"
},
"picgo.configPath": {
"type": "string",
"markdownDescription": "%config.configPath.description%",
Expand Down Expand Up @@ -310,9 +337,22 @@
"default": ""
}
}
}
},
"localizations": [{
"languageId": "zh-cn",
"languageName": "Chinese (Simplified)",
"localizedLanguageName": "中文(简体)",
"translations": [
{
"id": "vs-picgo",
"path": "./package.nls.zh-cn.json"
}
]
}]
},
"extensionKind": ["ui"],
"extensionKind": [
"ui"
],
"scripts": {
"vscode:prepublish": "yarn && yarn build:prod",
"build": "node esbuild.mjs",
Expand Down Expand Up @@ -426,5 +466,6 @@
"react-use": "17.3.1",
"redux": "4.1.1"
},
"license": "MIT"
"license": "MIT",
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
5 changes: 4 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"config.picBed.github.description": "GitHub configuration.",
"config.picBed.github.repo.description": "`Username/Repo`. For example, PicGo/Images",
"config.picBed.aliyun.description": "Aliyun OSS configuration.",
"config.picBed.imgur.description": "Imgur picBed configuration."
"config.picBed.imgur.description": "Imgur picBed configuration.",
"config.useUploadVersionFolder.description": "Whether to save uploaded version files in a separate 'uploadVersion' folder",
"command.generate.uploadedImageVersionMarkdown.title": "Generate uploaded image version markdown",
"command.uploadedImageVersionMarkdownInTheSameFile.title": "Upload and replace all image links in the current file"
}
29 changes: 29 additions & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"ext.displayName": "PicGo",
"ext.description": "基于 PicGo 的 VSCode 图片上传插件。支持多种图片格式(png, jpg, gif等)和多个图床服务(sm.ms、七牛云、imgur等)!",
"command.upload.clipboard.title": "从剪贴板上传",
"command.upload.explorer.title": "从资源管理器上传",
"command.upload.inputBox.title": "从输入框上传",
"command.generate.uploadedImageVersionMarkdown.title": "生成已上传图片的版本markdown",
"command.uploadedImageVersionMarkdownInTheSameFile.title": "上传并替换同一文件中的所有图片链接",
"command.webview.demo.title": "打开演示页面",
"command.webview.picGoControlPanel.title": "打开 PicGo 控制面板",
"config.title": "PicGo",
"config.configPath.description": "PicGo-Core 配置文件的路径。如果未指定,PicGo 将使用 `#picgo.picBed#`。更多配置文件相关信息请参考 [PicGo-Core 文档](https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#%E9%BB%98%E8%AE%A4%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6) 和 [PicGo 文档](https://picgo.github.io/PicGo-Doc/zh/guide/config.html#%E5%9B%BE%E5%BA%8A%E5%8C%BA)",
"config.dataPath.description": "数据文件的路径,包含所有已上传图片的信息。如果未指定,PicGo 将使用 `your_home_dir/vs-picgo-data.json`",
"config.customUploadName.description": "自定义上传图片的名称,图片将在上传前重命名。\n- `${fileName}`: 原始图片的名称,不包含扩展名。\n **注意:如果在上传前选择了文本,选中的文本将作为上传图片的 `fileName`。**\n- `${extName}`: 原始图片的扩展名。\n- `${mdFileName}`: 当前编辑的 markdown 文件名。\n- `${date}`: YY-MM-DD 格式的日期。\n- `${dateTime}`: YY-MM-DD-hh-mm-ss 格式的日期时间。\n\n示例:\n- `${fileName}-${date}${extName}` -> `picName-2016-07-25.jpg`\n- `${mdFileName}-${dateTime}${extName}` -> `markdownName-2017-04-12-22-28-10.jpg`",
"config.customOutputFormat.description": "自定义上传图片的输出格式。\n- `${url}`: 上传后的图片URL。\n- `${uploadedName}`: 上传后的图片名称(不含扩展名),参见 `#picgo.customUploadName#`,注意即使在 `#picgo.customUploadName#` 中使用了 `${extName}`,输出中仍然不会包含扩展名。\n\n示例:\n- `![${uploadedName}](${url})` -> `![picName-2016-07-25](https://example.com/xxx.jpg)`\n- `<img src=\"${url}\" alt=\"${uploadedName}\">` -> `<img src=\"https://example.com/xxx.jpg\" alt=\"picName-2016-07-25\">`",
"config.picBed.uploader": "请参考 [`picBed.uploader`](https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#picbed-uploader)",
"config.picBed.current": "请参考 [`picBed.current`](https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#picbed-current)",
"config.picBed.proxy": "请求的代理设置,更多详情请参考 [`picBed.proxy`](https://picgo.github.io/PicGo-Core-Doc/zh/guide/config.html#picbed-proxy)",
"config.picBed.smms.description": "SM.MS 图床配置",
"config.picBed.weibo.description": "微博图床配置",
"config.picBed.qiniu.description": "七牛云图床配置",
"config.picBed.upyun.description": "又拍云图床配置",
"config.picBed.tcyun.description": "腾讯云 COS 图床配置",
"config.picBed.github.description": "GitHub 配置",
"config.picBed.github.repo.description": "`用户名/仓库名`。例如: PicGo/Images",
"config.picBed.aliyun.description": "阿里云 OSS 配置",
"config.picBed.imgur.description": "Imgur 图床配置",
"config.useUploadVersionFolder.description": "是否将上传版本文件保存在单独的 'uploadVersion' 文件夹中"
}
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ export async function activate(context: vscode.ExtensionContext) {
'picgo.uploadImageFromInputBox',
async () => await CommandManager.commandManager.uploadImageFromInputBox()
),
vscode.commands.registerCommand(
'picgo.generateUploadedImageVersionMarkdown',
async () =>
await CommandManager.commandManager.generateUploadedImageVersionMarkdown(
false
)
),
vscode.commands.registerCommand(
'picgo.uploadAndReplaceAllImageLinksInTheCurrentFile',
async () =>
await CommandManager.commandManager.generateUploadedImageVersionMarkdown(
true
)
),

vscode.commands.registerCommand('picgo.webviewDemo', () =>
panelManager.createOrShowWebviewPanel('Demo')
Expand Down
Loading