Skip to content

Commit

Permalink
Merge pull request #3 from dario-baumberger/feature/release-feedback
Browse files Browse the repository at this point in the history
Feature/release feedback
  • Loading branch information
dario-baumberger authored Feb 27, 2024
2 parents fa42ee9 + b29eae6 commit 8c7fd8a
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 52 deletions.
20 changes: 11 additions & 9 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ name: Bug report
about: Create a report to help us improve
title: "[BUG]"
labels: bug
assignees: ''

assignees: ""
---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -24,15 +24,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
3 changes: 1 addition & 2 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: Feature request
about: Suggest an idea for this project
title: "[Feature Request]"
labels: enhancement
assignees: ''

assignees: ""
---

**Is your feature request related to a problem? Please describe.**
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store

# exlude coverage
coverage/
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
![GitHub stars](https://img.shields.io/github/stars/dario-baumberger/obsidian-image-to-text-ocr?style=flat)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/dario-baumberger/obsidian-image-to-text-ocr/blob/master/LICENCE)

# Obsidian Image to Text
# Obsidian Image to text

Recognize Text on images in your notes. Select the image and run the command. The recognized text will be appended to your image or will replace your image - depending on the command

## Commands

| Command | Description |
| -------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Image To Text: Replace Selection | Replace your image with the recognized text. Recognize text based on the language defined in settings |
| Image To Text: Replace Selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection |
| Image To Text: Append Selection | Append the recognized text to your image. Recognize text based on language defined in settings |
| Image To Text: Append Selection - custom language | Append the recognized text to your image. Recognize text based on custom selection |
| Command | Description |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------- |
| Replace selection | Replace your image with the recognized text. Recognize text based on the language defined in settings |
| Replace selection - custom language | Replace your image with the recognized text. Recognize text based on custom selection |
| Append selection | Append the recognized text to your image. Recognize text based on language defined in settings |
| Append selection - custom language | Append the recognized text to your image. Recognize text based on custom selection |

## Example

Expand All @@ -40,10 +40,6 @@ Recognize Text on images in your notes. Select the image and run the command. Th
| URL | `https://www.example.com/example.png` | URL to an image |
| img Tag | `<img src="https://www.example.com/example.png" />` | Img tag with a valid src attribute |

## Supported Devices

Obsidian images are not supported on mobile devices since the file adapter works only on desktop. All other images are available also on mobile.

## Installation

### Community Plugin
Expand Down
6 changes: 3 additions & 3 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const prod = process.argv[2] === "production";

const context = await esbuild.context({
banner: {
js: banner,
js: banner
},
entryPoints: ["src/main.ts"],
bundle: true,
Expand All @@ -30,14 +30,14 @@ const context = await esbuild.context({
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins,
...builtins
],
format: "cjs",
target: "es2018",
logLevel: "info",
sourcemap: prod ? false : "inline",
treeShaking: true,
outfile: "main.js",
outfile: "main.js"
});

if (prod) {
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "image-to-text-ocr",
"name": "Image to Text OCR",
"version": "1.0.1",
"name": "Image to text OCR",
"version": "1.0.2",
"minAppVersion": "0.15.0",
"description": "Convert a image in your note to text.",
"author": "Dario Baumberger",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-image-to-text-ocr",
"version": "1.0.1",
"version": "1.0.2",
"description": "Convert a image in your note to text",
"main": "main.js",
"scripts": {
Expand All @@ -9,7 +9,7 @@
"version": "node version-bump.mjs && git add manifest.json versions.json",
"test": "vitest",
"lint": "npx eslint",
"prettier": "npx prettier .",
"prettier": "npx prettier . --write",
"coverage": "vitest run --coverage"
},
"keywords": [],
Expand Down
2 changes: 1 addition & 1 deletion src/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ export const languages: Record<string, string> = {
uzb: "Uzbek",
uzb_cyrl: "Uzbek - Cyrillic",
vie: "Vietnamese",
yid: "Yiddish",
yid: "Yiddish"
};
33 changes: 14 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Editor, FileSystemAdapter, Notice, Plugin, TFile} from "obsidian";
import {Editor, Notice, Plugin} from "obsidian";
import {ImageToTextOcrPluginSettingTab} from "./settings";
import {
checkFileType,
Expand Down Expand Up @@ -29,8 +29,6 @@ const MESSAGE_FILETYPE =
const MESSAGE_CONTENT =
"Not supported content. Allowed: Obsidian Images, Markdown Images and Urls";
const MESSAGE_PATH = "Could not resolve image path";
const MESSAGE_ADAPTER =
"Error resolving adapter. Obsidian images are not supported on mobile devices.";
const MESSAGE_NOTFOUND = "Image file not found in the vault.";

const MESSAGE_RUNNING = "Recoginition is running...";
Expand All @@ -42,7 +40,7 @@ export default class ImageToTextOcrPlugin extends Plugin {

this.addCommand({
id: "replace",
name: "Image To Text: Replace Selection",
name: "Replace selection",
icon: "image-minus",
editorCallback: async (editor: Editor) => {
const selection = editor.getSelection();
Expand Down Expand Up @@ -77,7 +75,7 @@ export default class ImageToTextOcrPlugin extends Plugin {

this.addCommand({
id: "replace-select-language",
name: "Image To Text: Replace Selection - custom language",
name: "Replace selection - custom language",
icon: "image-minus",
editorCallback: async (editor: Editor) => {
const selection = editor.getSelection();
Expand Down Expand Up @@ -124,7 +122,7 @@ export default class ImageToTextOcrPlugin extends Plugin {

this.addCommand({
id: "append",
name: "Image To Text: Append Selection",
name: "Append selection",
icon: "image-plus",
editorCallback: async (editor: Editor) => {
const selection = editor.getSelection();
Expand Down Expand Up @@ -158,7 +156,7 @@ export default class ImageToTextOcrPlugin extends Plugin {

this.addCommand({
id: "append-select-language",
name: "Image To Text: Append Selection - custom language",
name: "Append selection - custom language",
icon: "image-plus",
editorCallback: async (editor: Editor) => {
const selection = editor.getSelection();
Expand Down Expand Up @@ -225,25 +223,22 @@ export default class ImageToTextOcrPlugin extends Plugin {
* get file path based on filename
*/
async resolveImagePath(fileName: string): Promise<string> {
const files = this.app.vault.getFiles();
const imageFile = files.find((file) => file.name === fileName);
const imageFile = this.app.metadataCache.getFirstLinkpathDest(
fileName,
""
);

if (!imageFile) {
new Notice(MESSAGE_NOTFOUND, 0);
throw new Error(MESSAGE_NOTFOUND);
}

const adapter = this.app.vault.adapter;
if (adapter instanceof FileSystemAdapter) {
const resourcePath = adapter.getResourcePath(imageFile.path);
if (this.settings.devMode) {
console.log(`resourcePath: ${resourcePath}`);
}
return resourcePath;
} else {
new Notice(MESSAGE_ADAPTER, 0);
throw new Error(MESSAGE_ADAPTER);
const resourcePath = this.app.vault.getResourcePath(imageFile);

if (this.settings.devMode) {
console.log(`resourcePath: ${resourcePath}`);
}
return resourcePath;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions version-bump.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFileSync, writeFileSync } from "fs";
import {readFileSync, writeFileSync} from "fs";

const targetVersion = process.env.npm_package_version;

// read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
const { minAppVersion } = manifest;
const {minAppVersion} = manifest;
manifest.version = targetVersion;
writeFileSync("manifest.json", JSON.stringify(manifest, null, "\t"));

Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.0.0": "0.15.0",
"1.0.1": "0.15.0"
"1.0.1": "0.15.0",
"1.0.2": "0.15.0"
}

0 comments on commit 8c7fd8a

Please sign in to comment.