Skip to content

Commit

Permalink
Enhance: Add license, i18n, and improve settings
Browse files Browse the repository at this point in the history
  • Loading branch information
luxmargos committed Jan 3, 2024
1 parent 9ab7208 commit 414246d
Show file tree
Hide file tree
Showing 38 changed files with 883 additions and 463 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release Obsidian plugin

on:
push:
tags:
- "*"

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18.x"

- name: Build plugin
run: |
npm install
npm run build
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
tag="${GITHUB_REF#refs/tags/}"
gh release create "$tag" \
--title="$tag" \
--draft \
main.js manifest.json styles.css
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 luxmargos (Jinho Yun)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
363 changes: 71 additions & 292 deletions README.md

Large diffs are not rendered by default.

246 changes: 246 additions & 0 deletions docs/ImageMagick_dump.md

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"name": "Image Magician",
"version": "0.1.0",
"minAppVersion": "0.15.0",
"description": "An obsidian.md plugin. Supports view and export of several image formats.",
"description": "Supports viewing and exporting various image formats using ImageMagick.",
"author": "luxmargos",
"authorUrl": "https://github.com/luxmargos/obsidian-image-magician-plugin",
"authorUrl": "https://github.com/luxmargos",
"fundingUrl": "https://www.buymeacoffee.com/luxmargos",
"isDesktopOnly": false
}
26 changes: 22 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
{
"name": "obsidian-psd-support-plugin",
"version": "0.1.0",
"description": "An (https://obsidian.md) plugin. Supports preview and export of photoshop psd file",
"description": "This is a plugin for Obsidian (https://obsidian.md). Supports viewing and exporting various image formats using ImageMagick.",
"main": "main.js",
"scripts": {
"prepare": "npm run build",
"dev": "node esbuild.config.mjs development",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"build": "npm run version && tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json"
},
"keywords": [],
"author": "",
"funding": [
"https://www.buymeacoffee.com/luxmargos"
],
"keywords": [
"obsidian",
"obsidian.md",
"typescript",
"javascript",
"plugin",
"imagemagick",
"renderer",
"image",
"photoshop",
"psd"
],
"author": {
"name": "Jinho Yun",
"url": "https://github.com/luxmargos"
},
"license": "MIT",
"devDependencies": {
"@types/codemirror": "^5.60.15",
Expand Down
45 changes: 21 additions & 24 deletions src/dialogs/export_opt_dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { debug } from "loglevel";
import { findValutFile } from "../vault_util";
import { exportImage } from "../exporter";
import { convertExportSettingsToRuntime } from "../settings/settings_as_func";
import { t } from "../i18n/t";

const ClsGroupMember = "imgk-settings-group-member";
const ClsGroupMemberLast = "imgk-settings-group-member-last";
Expand Down Expand Up @@ -52,9 +53,9 @@ export class ImgkPluginExportDialog extends Modal {
}

if (!this.srcPath) {
this.titleEl.setText("Export settings");
this.titleEl.setText(t("EXPORT_SETTINGS"));
} else {
this.titleEl.setText(`Export options`);
this.titleEl.setText(t("EXPORT_OPTIONS"));
}
}

Expand All @@ -75,23 +76,14 @@ export class ImgkPluginExportDialog extends Modal {

if (expandDetailSets) {
detailSetsToggleBtn?.setIcon("chevron-down");
tipSet.setDesc(
"In general, the plugin efficiently blocks an infinite export loop by using built-in filters \
and including two file extensions in the exported file name. When you want to break these default rules, \
an infinite export loop can occur with exported files having the same file extension, \
for example, 'MyImage.png.export.png.' \
In this circumstance, the auto-export process will continue until the file name exceeds its limit. \
If you find yourself in this situation, please refer to the following details."
);
tipSet.setDesc(t("AUTO_EXPORT_TIP_DESC"));
} else {
detailSetsToggleBtn?.setIcon("chevron-right");
tipSet.setDesc("");
}
};
tipSet = new Setting(this.contentEl)
.setName(
"Tip: Recommended settings to avoid infinity export loop."
)
.setName(t("AUTO_EXPORT_TIP"))
.setHeading()
.addExtraButton((comp) => {
detailSetsToggleBtn = comp;
Expand All @@ -105,21 +97,17 @@ export class ImgkPluginExportDialog extends Modal {

const detailSet1 = new Setting(this.contentEl);
detailSet1
.setDesc(
"1. Set a specific source folder rather than root folder of vault."
)
.setDesc(t("AUTO_EXPORT_TIP_1"))
.settingEl.addClass(ClsGroupMember);

const detailSet2 = new Setting(this.contentEl);
detailSet2
.setDesc("2. Isolate source and exported folder.")
.setDesc(t("AUTO_EXPORT_TIP_2"))
.settingEl.addClass(ClsGroupMember);

const detailSet3 = new Setting(this.contentEl);
detailSet3
.setDesc(
"3. If you have a plan with complex settings, try to use filter."
)
.setDesc(t("AUTO_EXPORT_TIP_3"))
.settingEl.addClass(ClsGroupMemberLast);

detailSets.push(detailSet1, detailSet2, detailSet3);
Expand All @@ -131,7 +119,9 @@ export class ImgkPluginExportDialog extends Modal {
this.exportSettings
);
} else {
new Setting(this.contentEl).setName(`Source: ${this.srcPath}`);
new Setting(this.contentEl).setName(
t("FORMAT_SOURCE").replace("${src}", this.srcPath ?? "")
);
}

let exportPathSetReturns: {
Expand Down Expand Up @@ -180,7 +170,7 @@ export class ImgkPluginExportDialog extends Modal {
const runExportBtnSet = new Setting(this.contentEl);
runExportBtnSet.addButton((comp: ButtonComponent) => {
exportBtn = comp;
comp.setButtonText("Export");
comp.setButtonText(t("EXPORT"));
comp.onClick((evt) => {
if (!srcPath) {
return;
Expand Down Expand Up @@ -216,12 +206,19 @@ export class ImgkPluginExportDialog extends Modal {
path
);

const message = `Exporte successful: "${this.srcPath}" as "${path}"`;
const message = t("FORMAT_EXPORT_SUCCESS")
.replace("${src}", this.srcPath ?? "")
.replace("${dst}", path);
new Notice(message);
})
.catch((err) => {
debug(err);
new Notice(`Export failed: ${this.srcPath}`);
new Notice(
t("FORMAT_EXPORT_FAILED").replace(
"${src}",
this.srcPath ?? ""
)
);
})
.finally(() => {});
}
Expand Down
5 changes: 4 additions & 1 deletion src/engines/imgEngines.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { PluginImageEngine } from "./imgEngine";

const psdEngineExts = new Set(["psd", "psb", "PSD", "PSB"]);

export class PIE {
static magick(): PluginImageEngine {
return this._magick;
Expand All @@ -13,9 +15,10 @@ export class PIE {
static _psd: PluginImageEngine;

static getEngine(ext: string): PluginImageEngine {
if (ext === "psd" || ext === "psb") {
if (psdEngineExts.has(ext)) {
return this.psd();
}

return this.magick();
}
}
2 changes: 2 additions & 0 deletions src/i18n/langType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import en from "./trans/en";
export type Translates = typeof en;
72 changes: 72 additions & 0 deletions src/i18n/t.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { locale } from "moment";
import { Translates } from "./langType";

import en from "./trans/en";
import ko from "./trans/ko";
import ar from "./trans/ar";
import cz from "./trans/cz";
import da from "./trans/da";
import de from "./trans/de";
import enGB from "./trans/en-gb";
import es from "./trans/es";
import fr from "./trans/fr";
import hi from "./trans/hi";
import id from "./trans/id";
import it from "./trans/it";
import ja from "./trans/ja";
import nl from "./trans/nl";
import no from "./trans/no";
import pl from "./trans/pl";
import pt from "./trans/pt";
import ptBR from "./trans/pt-br";
import ro from "./trans/ro";
import ru from "./trans/ru";
import tr from "./trans/tr";
import zhCN from "./trans/zh-cn";
import zhTW from "./trans/zh-tw";

const allLangs: { [key: string]: Partial<Translates> } = {
ar,
cs: cz,
da,
de,
en,
"en-gb": enGB,
es,
fr,
hi,
id,
it,
ja,
ko,
nl,
nn: no,
pl,
pt,
"pt-br": ptBR,
ro,
ru,
tr,
"zh-cn": zhCN,
"zh-tw": zhTW,
};

let currentDict: Partial<Translates>;
// export const setLocale = (locale: keyof Dicts) => {
export const setLocale = (locale: string) => {
if (locale in allLangs) {
currentDict = allLangs[locale] as Translates;
return;
}
currentDict = en;
};

setLocale(locale());

export const t = (key: keyof Translates): string => {
if (key in currentDict) {
return currentDict[key] ?? "";
}

return en[key] ?? key;
};
3 changes: 3 additions & 0 deletions src/i18n/trans/ar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// العربية

export default {};
3 changes: 3 additions & 0 deletions src/i18n/trans/cz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// čeština

export default {};
3 changes: 3 additions & 0 deletions src/i18n/trans/da.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Dansk

export default {};
3 changes: 3 additions & 0 deletions src/i18n/trans/de.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Deutsch

export default {};
3 changes: 3 additions & 0 deletions src/i18n/trans/en-gb.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// British English

export default {};
Loading

0 comments on commit 414246d

Please sign in to comment.