Skip to content

Commit d1a8cfe

Browse files
authored
Merge pull request #11 from lqllife/master
修改图片地址正则,支持 ![[image.png|alt]] 格式链接
2 parents 9906719 + d420431 commit d1a8cfe

3 files changed

Lines changed: 57 additions & 48 deletions

File tree

.github/workflows/build-test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test Build Plugin
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
workflow_dispatch:
9+
10+
env:
11+
PLUGIN_NAME: custom-image-auto-uploader-modified
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: pnpm/action-setup@v4
21+
with:
22+
run_install: false
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version-file: ".node-version"
28+
cache: "pnpm"
29+
30+
- name: Build
31+
run: |
32+
pnpm install
33+
pnpm run build
34+
35+
mkdir ${{ env.PLUGIN_NAME }}
36+
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}
37+
38+
- name: Upload Test Artifact ✅
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: obsidian-plugin-test-build
42+
path: |
43+
main.js
44+
manifest.json
45+
styles.css

.github/workflows/release.yml

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
name: Build plugin
1+
name: Release plugin
22

33
on:
44
push:
55
tags:
66
- "*"
7+
workflow_dispatch:
78

89
env:
9-
PLUGIN_NAME: custom-image-auto-uploader
10+
PLUGIN_NAME: custom-image-auto-uploader-modified
1011

1112
jobs:
1213
build:
1314
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
1417

1518
steps:
1619
- uses: actions/checkout@v4
20+
1721
- uses: pnpm/action-setup@v4
1822
with:
1923
run_install: false
@@ -32,10 +36,10 @@ jobs:
3236
mkdir ${{ env.PLUGIN_NAME }}
3337
cp main.js manifest.json styles.css ${{ env.PLUGIN_NAME }}
3438
zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }}
35-
ls
36-
echo "::set-output name=tag_name::$(git tag --sort version:refname | tail -n 1)"
39+
40+
echo "tag_name=$(git describe --tags --abbrev=0)" >> $GITHUB_OUTPUT
41+
3742
- name: Create Release
38-
id: create_release
3943
uses: actions/create-release@v1
4044
env:
4145
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -44,43 +48,3 @@ jobs:
4448
release_name: ${{ github.ref }}
4549
draft: false
4650
prerelease: false
47-
- name: Upload zip file
48-
id: upload-zip
49-
uses: actions/upload-release-asset@v1
50-
env:
51-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52-
with:
53-
upload_url: ${{ steps.create_release.outputs.upload_url }}
54-
asset_path: ./${{ env.PLUGIN_NAME }}.zip
55-
asset_name: ${{ env.PLUGIN_NAME }}-${{ steps.build.outputs.tag_name }}.zip
56-
asset_content_type: application/zip
57-
- name: Upload main.js
58-
id: upload-main
59-
uses: actions/upload-release-asset@v1
60-
env:
61-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62-
with:
63-
upload_url: ${{ steps.create_release.outputs.upload_url }}
64-
asset_path: ./main.js
65-
asset_name: main.js
66-
asset_content_type: text/javascript
67-
- name: Upload manifest.json
68-
id: upload-manifest
69-
uses: actions/upload-release-asset@v1
70-
env:
71-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72-
with:
73-
upload_url: ${{ steps.create_release.outputs.upload_url }}
74-
asset_path: ./manifest.json
75-
asset_name: manifest.json
76-
asset_content_type: application/json
77-
- name: Upload styles.css
78-
id: upload-css
79-
uses: actions/upload-release-asset@v1
80-
env:
81-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82-
with:
83-
upload_url: ${{ steps.create_release.outputs.upload_url }}
84-
asset_path: ./styles.css
85-
asset_name: styles.css
86-
asset_content_type: application/json

src/main.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { imageDown, imageUpload, statusCheck, replaceInText, hasExcludeDomain, a
44
import { DownTask, UploadTask } from "./interface"
55
import { $ } from "./lang"
66

7-
const mdImageRegex = /!\[([^\]]*)\][\(|\[](.*?)\s*("(?:.*[^"])")?\s*[\)|\]]|!\[\[([^\]]*)\]\]/g
7+
const mdImageRegex = /!\[([^\]]*)\][\(|\[](.*?)\s*("(?:.*[^"])")?\s*[\)|\]]|!\[\[([^\]|]*)\|?([^\]]*)\]\]/g
88

99
export default class CustomImageAutoUploader extends Plugin {
1010
settingTab: SettingTab
@@ -150,7 +150,7 @@ export default class CustomImageAutoUploader extends Plugin {
150150
continue
151151
}
152152

153-
let imageAlt = match[3] ? match[3] : match[1] ? match[1] : ""
153+
let imageAlt = match[3] ? match[3] : match[1] ? match[1] : match[5] ? match[5] : ""
154154
imageAlt = imageAlt.replaceAll('"', "")
155155
downloadTasks.push({
156156
matchText: match[0],
@@ -221,7 +221,7 @@ export default class CustomImageAutoUploader extends Plugin {
221221
let readfile = await getAttachmentUploadPath(file, this)
222222
if (!readfile) continue
223223

224-
const imageAlt = match[3] ? match[3] : match[1] ? match[1] : file
224+
const imageAlt = match[3] ? match[3] : match[1] ? match[1] : match[5] ? match[5] : file
225225
uploadTasks.push({
226226
matchText: match[0],
227227
imageAlt,

0 commit comments

Comments
 (0)