Skip to content

Commit

Permalink
feat: Add an option to allow uploading network images.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaychen1e committed Jan 9, 2022
1 parent 7417ba0 commit 104b6c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
# logseq-plugin-image-uploader

<div align="center">
<img src="./icon.png" style="width:150px" />
</div>


# Usage

## How to use it?

Currently, we only support [PicGo](https://github.com/Molunerfinn/PicGo), so please open PicGo manually.

By default, when you paste any content into a block, after exit editing that block, the plugin will check whether its content contains any images, if it does, the plugin will upload them and replace them with remote URLs. You can turn off this feature in the configuration file.

![example_usage](./example_usage_auto.gif)

Alternatively, if you have inserted any images before, you can right-click any block's dot to show its context menu, and select `Upload image`. All images detected in that block will be uploaded, and replaced with remote URLs.

![example_usage](./example_usage.gif)

### Note

Since we don't have any permission to operate the file system in a logseq plugin, we can't delete the original file saved by logseq. So we create a page named **"Uploaded image file record(created by logseq-plugin-image-uploader)"** to save all the images we uploaded. You can delete them manually. (One image path actually can appear more than once on that page, for example, you use that image many times, and you upload them more than once)

We may provide a script to delete those images in the future.

## Installation

- Download the latest [release](https://github.com/JJAYCHEN1e/logseq-plugin-image-uploader/releases) of the plugin.
Expand All @@ -15,33 +38,16 @@
## Configuration

Currently, we only support turning off auto uploading feature in the configuration file.
Currently, we only support **turning off auto uploading** feature and **allow uploading network images** feature in the configuration file. Note that at present, only network images using Markdown syntax will be uploaded, although the picture link will also be correctly displayed by Logseq.

```json
{
"disabled": false,
"autoUploading": true
"autoUploading": true,
"uploadNetworkImage": false,
}
```

## How to use it?

Currently, we only support [PicGo](https://github.com/Molunerfinn/PicGo), so please open PicGo manually.

By default, when you paste any content into a block, after exit editing that block, the plugin will check whether its content contains any images, if it does, the plugin will upload them and replace them with remote URLs. You can turn off this feature in the configuration file.

![example_usage](./example_usage_auto.gif)

Alternatively, if you have inserted any images before, you can right-click any block's dot to show its context menu, and select `Upload image`. All images detected in that block will be uploaded, and replaced with remote URLs.

![example_usage](./example_usage.gif)

### Note

Since we don't have any permission to operate the file system in a logseq plugin, we can't delete the original file saved by logseq. So we create a page named **"Uploaded image file record(created by logseq-plugin-image-uploader)"** to save all the images we uploaded. You can delete them manually. (One image path actually can appear more than once on that page, for example, you use that image many times, and you upload them more than once)

We may provide a script to delete those images in the future.

# Development

Logseq plugins API: https://logseq.github.io/plugins/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-plugin-image-uploader",
"version": "0.0.4",
"version": "0.0.5",
"main": "dist/index.html",
"scripts": {
"dev": "vite",
Expand Down
3 changes: 2 additions & 1 deletion src/ImageUploadUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export async function checkAndUploadBlock(srcBlock: BlockEntity, graphPath: stri
let match;
while ((match = /\!\[.*?\]\((.*?)\)/g.exec(content))) {
const imageURLText = match[1];
if (imageURLText.startsWith("../")) {
let uploadNetworkImage = logseq.settings?.uploadNetworkImage ?? false;
if (imageURLText.startsWith("../") || uploadNetworkImage) {
// Ensure this is a local image.
const imageURLLocal = graphPath + match[1].replace("..", "");
const imageURLRemote = await uploadImage(imageURLLocal);
Expand Down

0 comments on commit 104b6c5

Please sign in to comment.