Skip to content

Commit 2a2de55

Browse files
committed
fix: misc bugs
1 parent a746bbe commit 2a2de55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+546
-471
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
1-
name: Release
1+
name: Release Obsidian plugin
22

33
on:
44
push:
55
tags:
6-
- "*.*.*"
6+
- "*"
77

88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11-
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-node@v2
14-
with:
15-
node-version: "18"
1611

17-
- name: install dependencies
18-
run: npm ci
12+
steps:
13+
- uses: actions/checkout@v3
1914

20-
- name: test
21-
run: npm test
15+
- name: Use Node.js
16+
uses: actions/setup-node@v3
17+
with:
18+
node-version: "18.x"
2219

23-
- name: build
24-
run: npm run build
20+
- name: Build plugin
21+
run: |
22+
npm install
23+
npm run build
2524
26-
- name: create release
27-
uses: softprops/action-gh-release@v1
28-
if: startsWith(github.ref, 'refs/tags/')
29-
with:
30-
files: |
31-
temp/vault/.obsidian/plugins/labeled-annotations/main.js
32-
temp/vault/.obsidian/plugins/labeled-annotations/styles.css
33-
manifest.json
34-
draft: true
35-
prerelease: true
25+
- name: Create release
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
run: |
29+
tag="${GITHUB_REF#refs/tags/}"
30+
31+
gh release create "$tag" \
32+
--title="$tag" \
33+
--draft \
34+
manifest.json temp/vault/.obsidian/plugins/enhanced-annotations/main.js temp/vault/.obsidian/plugins/enhanced-annotations/styles.css

.lintstagedrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"*.{js,jsx,ts,tsx,css, svelte}": [
2+
"*.{js,jsx,ts,tsx, svelte}": [
33
"prettier --write",
44
"eslint --fix"
55
]

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Enhanced Annotations
2+
An obsidian plugin that extends the functionality of comments and highlights.
3+
4+
![](./docs/media/screenshot.png)
5+
6+
## Features
7+
- Explore comments/highlights of the active file using a sidebar view.
8+
- Create notes from comments/highlights using the editor context menu.
9+
- Copy comments/highlights of selected files from the file explorer context menu.
10+
- Assign custom styles to different types of comments/highlights based on their label (e.g., `<!--title: ...-->`, `<!--todo: ...-->`).
11+
- Use a trigger phrase to insert a labeled comment (e.g., `//todo` to insert `<!--todo: -->`).
12+
13+
14+
15+
16+

docs/media/screenshot.png

115 KB
Loading

esbuild.config.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import esbuild from "esbuild";
2-
import process from "process";
3-
import builtins from "builtin-modules";
4-
import esbuildSvelte from "esbuild-svelte";
5-
import sveltePreprocess from "svelte-preprocess";
6-
import inlineWorkerPlugin from "esbuild-plugin-inline-worker";
1+
import esbuild from 'esbuild';
2+
import process from 'process';
3+
import builtins from 'builtin-modules';
4+
import esbuildSvelte from 'esbuild-svelte';
5+
import sveltePreprocess from 'svelte-preprocess';
6+
import inlineWorkerPlugin from 'esbuild-plugin-inline-worker';
77

88
const banner = `/*
99
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
@@ -40,7 +40,7 @@ const context = await esbuild.context({
4040
logLevel: "info",
4141
sourcemap: prod ? false : "inline",
4242
treeShaking: true,
43-
outfile: "temp/vault/.obsidian/plugins/labeled-annotations/main.js",
43+
outfile: "temp/vault/.obsidian/plugins/enhanced-annotations/main.js",
4444
plugins: [
4545
inlineWorkerPlugin(),
4646
esbuildSvelte({
@@ -61,7 +61,7 @@ const context = await esbuild.context({
6161
const cssContext = await esbuild.context({
6262
entryPoints: ["src/styles.css"],
6363
bundle: true,
64-
outfile: "temp/vault/.obsidian/plugins/labeled-annotations/styles.css"
64+
outfile: "temp/vault/.obsidian/plugins/enhanced-annotations/styles.css"
6565
});
6666

6767
if (prod) {

manifest.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
2-
"id": "labeled-annotations",
3-
"name": "Labeled Annotations",
2+
"id": "enhanced-annotations",
3+
"name": "Enhanced Annotations",
44
"version": "0.1.0",
55
"minAppVersion": "0.15.0",
6-
"description": "",
6+
"description": "Adds features to comments and highlights.",
77
"author": "ycnmhd",
8-
"authorUrl": "https://github.com/ycnmhd/labeled-annotations",
98
"isDesktopOnly": true
109
}

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "labeled-annotations",
2+
"name": "enhanced-annotations",
33
"version": "0.1.0",
44
"description": "",
5-
"main": "main.js",
65
"scripts": {
76
"dev": "node esbuild.config.mjs",
87
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
@@ -35,7 +34,6 @@
3534
"prettier": "3.0.3",
3635
"svelte": "4.2.1",
3736
"svelte-preprocess": "5.0.4",
38-
"tailwindcss": "3.3.5",
3937
"tslib": "2.4.0",
4038
"typescript": "4.7.4",
4139
"vitest": "0.34.5",

src/clipboard/helpers/annotations-to-text.spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ const samples: {
1111
input: [
1212
[
1313
{
14-
path: 'folder a',
15-
name: 'note 1',
14+
folder: 'folder a',
15+
basename: 'note 1',
16+
path: 'folder a/note 1.md',
1617
annotations: [
1718
{
1819
text: 'some highlight',
@@ -54,8 +55,9 @@ const samples: {
5455
isHighlight: true,
5556
},
5657
],
57-
name: 'Third-order intercept point',
58-
path: 'clipboard/other',
58+
basename: 'Third-order intercept point',
59+
folder: 'clipboard/other',
60+
path: 'clipboard/other/Third-order intercept point.md',
5961
},
6062
{
6163
annotations: [
@@ -70,8 +72,9 @@ const samples: {
7072
isHighlight: true,
7173
},
7274
],
73-
name: 'Intermodulation',
74-
path: 'clipboard',
75+
basename: 'Intermodulation',
76+
folder: 'clipboard',
77+
path: 'clipboard/Intermodulation.md',
7578
},
7679
{
7780
annotations: [
@@ -81,8 +84,9 @@ const samples: {
8184
isHighlight: false,
8285
},
8386
],
84-
name: 'Second-order intercept point',
85-
path: 'clipboard',
87+
basename: 'Second-order intercept point',
88+
folder: 'clipboard',
89+
path: 'clipboard/Second-order intercept point.md',
8690
},
8791
],
8892
{
@@ -109,8 +113,9 @@ const samples: {
109113
input: [
110114
[
111115
{
112-
path: 'folder a',
113-
name: 'note 1',
116+
folder: 'folder a',
117+
basename: 'note 1',
118+
path: 'folder a/note 1.md',
114119
annotations: [
115120
{
116121
text: 'some comment',

src/clipboard/helpers/annotations-to-text.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ export const annotationsToText = (
4848
});
4949
const annotationsText: string[] = [];
5050
if (front.trim()) annotationsText.push(front);
51-
for (const { annotations: fileAnnotations, name, path } of annotations) {
51+
for (const {
52+
annotations: fileAnnotations,
53+
basename,
54+
folder,
55+
} of annotations) {
5256
const fileText: string[] = [];
5357
const header = applyVariablesToTemplate({
5458
template: templates.header,
55-
variables: { note_folder: path, note_name: name } as Record<
59+
variables: { note_folder: folder, note_name: basename } as Record<
5660
HeaderVariables[number],
5761
string
5862
>,

src/clipboard/helpers/copy-annotations-to-clipboard.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Notice, TAbstractFile } from 'obsidian';
22
import LabeledAnnotations from '../../main';
33
import { parseAnnotationsFromFiles } from './parse-annotations-from-files';
44
import { pluralize } from '../../helpers/pluralize';
5-
import { clipboard } from 'electron';
65
import { annotationsToText } from './annotations-to-text';
76

87
export const copyAnnotationsToClipboard = async (
@@ -14,9 +13,17 @@ export const copyAnnotationsToClipboard = async (
1413
: [abstractFiles];
1514
const root = abstractFilesArray[0].parent?.path as string;
1615

17-
const content = await parseAnnotationsFromFiles(abstractFilesArray, plugin);
18-
const nOfFiles = Object.keys(content).length;
19-
const nOfAnnotations = content.map((c) => c.annotations).flat().length;
16+
const unsortedAnnotations = await parseAnnotationsFromFiles(
17+
abstractFilesArray,
18+
plugin,
19+
);
20+
const sortedAnnotations = unsortedAnnotations.sort((a, b) =>
21+
a.folder.localeCompare(b.folder),
22+
);
23+
const nOfFiles = Object.keys(sortedAnnotations).length;
24+
const nOfAnnotations = sortedAnnotations
25+
.map((c) => c.annotations)
26+
.flat().length;
2027
if (nOfAnnotations) {
2128
new Notice(
2229
`Copied ${pluralize(
@@ -26,7 +33,9 @@ export const copyAnnotationsToClipboard = async (
2633
)} from ${pluralize(nOfFiles, 'file', 'files')} to clipboard`,
2734
);
2835
const templates = plugin.settings.getValue().clipboard.templates;
29-
clipboard.writeText(annotationsToText(content, templates, root));
36+
await navigator.clipboard.writeText(
37+
annotationsToText(sortedAnnotations, templates, root),
38+
);
3039
} else {
3140
new Notice(`No annotations found`);
3241
}

0 commit comments

Comments
 (0)