Skip to content

Commit

Permalink
release: 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
HananoshikaYomaru committed Nov 21, 2023
1 parent 06111fe commit 224ec99
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
@@ -0,0 +1,2 @@
github: [hananoshikayomaru]
custom: https://www.buymeacoffee.com/yomaru
Binary file modified bun.lockb
Binary file not shown.
7 changes: 5 additions & 2 deletions manifest.json
@@ -1,11 +1,14 @@
{
"id": "md-image-caption",
"name": "Markdown Image Caption",
"version": "1.0.4",
"version": "1.0.5",
"minAppVersion": "0.15.0",
"description": "Generate image caption",
"author": "Hananoshika Yomaru",
"authorUrl": "https://yomaru.dev",
"fundingUrl": "https://www.buymeacoffee.com/yomaru",
"fundingUrl": {
"buymeacoffee": "https://www.buymeacoffee.com/yomaru",
"Github Sponsor": "https://github.com/sponsors/HananoshikaYomaru"
},
"isDesktopOnly": false
}
109 changes: 54 additions & 55 deletions package.json
@@ -1,57 +1,56 @@
{
"name": "obsidian-md-image-caption",
"version": "1.0.4",
"description": "Generate markdown based image captions for Obsidian",
"main": "main.js",
"scripts": {
"dev": "bun esbuild.config.mjs",
"build": "bun esbuild.config.mjs production",
"version": "bun version-bump.mjs && git add manifest.json versions.json",
"prepare": "husky install",
"typecheck": "tsc --noEmit"
},
"keywords": [
"obsidian",
"plugin",
"dataview",
"markdown",
"generator",
"javascript"
],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/diff-match-patch": "^1.0.34",
"@types/js-yaml": "^4.0.6",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"bun-types": "^1.0.3",
"esbuild": "0.17.3",
"husky": "^8.0.3",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "^5.0.5"
},
"dependencies": {
"diff-match-patch": "^1.0.5",
"js-yaml": "^4.1.0",
"mdast-util-from-markdown": "^1.2.0",
"mdast-util-gfm-footnote": "^1.0.1",
"mdast-util-gfm-task-list-item": "^1.0.1",
"mdast-util-math": "^2.0.1",
"micromark-extension-gfm-footnote": "^1.0.4",
"micromark-extension-gfm-task-list-item": "^1.0.3",
"micromark-extension-math": "^2.0.2",
"micromark-util-combine-extensions": "^1.0.0",
"quick-lru": "^6.1.1",
"ts-dedent": "^2.2.0",
"ts-pattern": "^5.0.5",
"unist-util-visit": "^4.1.2",
"@total-typescript/ts-reset": "^0.5.1",
"obsidian-dataview": "^0.5.59",
"safe-eval": "^0.4.1",
"zod": "^3.22.2"
}
"name": "obsidian-md-image-caption",
"version": "1.0.5",
"description": "Generate markdown based image captions for Obsidian",
"main": "main.js",
"scripts": {
"dev": "bun esbuild.config.mjs",
"build": "bun esbuild.config.mjs production",
"version": "bun version-bump.mjs && git add manifest.json versions.json",
"prepare": "husky install",
"release": "bash ./release.sh",
"typecheck": "tsc --noEmit"
},
"keywords": [
"obsidian",
"plugin",
"dataview",
"markdown",
"generator",
"javascript"
],
"author": "",
"license": "MIT",
"devDependencies": {
"@types/diff-match-patch": "^1.0.34",
"@types/js-yaml": "^4.0.6",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"bun-types": "^1.0.3",
"esbuild": "0.17.3",
"husky": "^8.0.3",
"obsidian": "latest",
"tslib": "2.4.0",
"typescript": "^5.0.5"
},
"dependencies": {
"diff-match-patch": "^1.0.5",
"js-yaml": "^4.1.0",
"mdast-util-from-markdown": "^1.2.0",
"mdast-util-gfm-footnote": "^1.0.1",
"mdast-util-gfm-task-list-item": "^1.0.1",
"mdast-util-math": "^2.0.1",
"micromark-extension-gfm-footnote": "^1.0.4",
"micromark-extension-gfm-task-list-item": "^1.0.3",
"micromark-extension-math": "^2.0.2",
"micromark-util-combine-extensions": "^1.0.0",
"quick-lru": "^6.1.1",
"ts-dedent": "^2.2.0",
"unist-util-visit": "^4.1.2",
"@total-typescript/ts-reset": "^0.5.1",
"obsidian-dataview": "^0.5.59",
"zod": "^3.22.2"
}
}
66 changes: 66 additions & 0 deletions release.sh
@@ -0,0 +1,66 @@
#!/bin/bash

# Set the default update type
UPDATE_TYPE="patch"

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-m | --minor)
UPDATE_TYPE="minor"
shift
;;
-M | --major)
UPDATE_TYPE="major"
shift
;;
*)
echo "Unknown option: $key"
exit 1
;;
esac
done

# Get the version number from manifest.json
MANIFEST_VERSION=$(jq -r '.version' manifest.json)

# Get the version number from package.json
PACKAGE_VERSION=$(node -p -e "require('./package.json').version")

# Ensure the version from package.json matches the version in manifest.json
if [ "$PACKAGE_VERSION" != "$MANIFEST_VERSION" ]; then
echo "Version mismatch between package.json and manifest.json"
exit 1
fi

# Increment the version based on the specified update type
if [ "$UPDATE_TYPE" = "minor" ]; then
NEW_VERSION=$(semver $PACKAGE_VERSION -i minor)
elif [ "$UPDATE_TYPE" = "major" ]; then
NEW_VERSION=$(semver $PACKAGE_VERSION -i major)
else
NEW_VERSION=$(semver $PACKAGE_VERSION -i patch)
fi

echo "Current version: $PACKAGE_VERSION"
echo "New version: $NEW_VERSION"

# Update the version in package.json
jq --arg version "$NEW_VERSION" '.version = $version' package.json >tmp.json && mv tmp.json package.json
echo "Changed package.json version to $NEW_VERSION"

# Print the updated version of manifest.json using 'bun'
bun run version
echo "Updated version of manifest using bun. The current version of manifest.json is $(jq -r '.version' manifest.json)"

# Create a git commit and tag
git add . && git commit -m "release: $NEW_VERSION"
git tag -a "$NEW_VERSION" -m "release: $NEW_VERSION"
echo "Created tag $NEW_VERSION"

# Push the commit and tag to the remote repository
git push origin "$NEW_VERSION"
echo "Pushed tag $NEW_VERSION to the origin branch $NEW_VERSION"
git push
echo "Pushed to the origin master branch"
61 changes: 15 additions & 46 deletions src/main.ts
@@ -1,12 +1,18 @@
import { Editor, MarkdownView, Plugin, TFile } from "obsidian";
import { getDataFromTextSync, writeFile } from "./utils/obsidian";
import {
getDataFromTextSync,
isMarkdownFile,
writeFile,
} from "./utils/obsidian";
import { extractImagesFromPattern } from "./extractImagesFromPattern";
import { getNewTextFromResults } from "./getNewTextFromResults";

export default class ImageCaptionPlugin extends Plugin {
private previousSaveCommand: (() => void) | undefined;

runFileSync(file: TFile, editor: Editor) {
runFileSync(checking: boolean, editor: Editor, ctx: MarkdownView) {
if (!ctx.file) return;
if (checking) {
return isMarkdownFile(ctx.file);
}
const data = getDataFromTextSync(editor.getValue());
// recognise the patterns

Expand All @@ -23,48 +29,11 @@ export default class ImageCaptionPlugin extends Plugin {
}
}

registerEventsAndSaveCallback() {
const saveCommandDefinition =
this.app.commands.commands["editor:save-file"]!;
this.previousSaveCommand = saveCommandDefinition.callback;

if (typeof this.previousSaveCommand === "function") {
saveCommandDefinition.callback = () => {
// get the editor and file
const editor =
this.app.workspace.getActiveViewOfType(
MarkdownView
)?.editor;
const file = this.app.workspace.getActiveFile();
if (!editor || !file) return;
const data = getDataFromTextSync(editor.getValue());
// if (isFileIgnored(this.settings, file, data)) return;

// this cannot be awaited because it will cause the editor to delay saving
this.runFileSync(file, editor);

// run the previous save command
if (this.previousSaveCommand) this.previousSaveCommand();

// defines the vim command for saving a file and lets the linter run on save for it
// accounts for https://github.com/platers/obsidian-linter/issues/19
const that = this;
window.CodeMirrorAdapter.commands.save = () => {
that.app.commands.executeCommandById("editor:save-file");
};
};
}
}
unregisterEventsAndSaveCallback() {
const saveCommandDefinition =
this.app.commands.commands["editor:save-file"]!;
saveCommandDefinition.callback = this.previousSaveCommand;
}
async onload() {
this.registerEventsAndSaveCallback();
}

onunload() {
this.unregisterEventsAndSaveCallback();
this.addCommand({
id: "run-file",
name: "Generate image captions for current file",
editorCheckCallback: this.runFileSync.bind(this),
});
}
}
4 changes: 0 additions & 4 deletions src/utils/regex.ts
Expand Up @@ -36,10 +36,6 @@ export const urlRegex =
export const anchorTagRegex = /<a[\s]+([^>]+)>((?:.(?!<\/a>))*.)<\/a>/g;
export const wordRegex = /[\p{L}\p{N}\p{Pc}\p{M}\-'’`]+/gu;
// regex from https://stackoverflow.com/a/26128757/8353749
export const htmlEntitiesRegex = /&[^\s]+;$/im;

export const smartDoubleQuoteRegex = /[“”„«»]/g;
export const smartSingleQuoteRegex = /[‘’‚‹›]/g;

export const templaterCommandRegex = /<%[^]*?%>/g;
// checklist regex
Expand Down
2 changes: 1 addition & 1 deletion version-bump.mjs
@@ -1,6 +1,6 @@
import { readFileSync, writeFileSync } from "fs";

const targetVersion = process.env.npm_package_version;
const targetVersion = JSON.parse(readFileSync("package.json", "utf8")).version;

// read minAppVersion from manifest.json and bump version to target version
let manifest = JSON.parse(readFileSync("manifest.json", "utf8"));
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Expand Up @@ -3,5 +3,6 @@
"1.0.1": "0.15.0",
"1.0.2": "0.15.0",
"1.0.3": "0.15.0",
"1.0.4": "0.15.0"
"1.0.4": "0.15.0",
"1.0.5": "0.15.0"
}

0 comments on commit 224ec99

Please sign in to comment.