Skip to content

Commit

Permalink
fix: dist
Browse files Browse the repository at this point in the history
  • Loading branch information
canburaks committed May 8, 2023
1 parent 67eb3bc commit 3ea53da
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The plugin allows you to store the text you select on Obsidian which is captured
- You need a Popclip app on your MacOS.
- You need an Obsidian app on your MacOS.

![Obsidian plugin for Popclip](https://www.cbsofyalioglu.com/_next/image/?url=%2Fvideo%2Fpopclip-obsidian.gif&w=1536&q=75)

## How does it work?
There are two part of the workflow.
Expand Down Expand Up @@ -49,11 +50,18 @@ javascript: |
```

## Part II: Installing the Obsidian plugin.
I didn't submit the plugin yet. Therefore, you need to install it manually.
I didn't submit the plugin yet. I'm planning to submit it soon.

Therefore, you need to install it manually:
1. Download GitHub repository of [Obsidian Popclip plugin](https://github.com/canburaks/obsidian-popclip) .
2. Copy the `popclip` folder under `dist` directory.
3. Paste the copied `popclip` folder under your Obsidian plugin folder `.obsidian/plugins`.
4. Restart Obsidian.




I'm planning to submit it soon.

![Obsidian plugin for Popclip](https://www.cbsofyalioglu.com/_next/image/?url=%2Fvideo%2Fpopclip-obsidian.gif&w=1536&q=75)


Special thanks for Nick and EdM for their sharings on this [Popclip forum post](https://forum.popclip.app/t/clip-selection-to-obsidian/359/5)
Binary file modified dist/.DS_Store
Binary file not shown.
43 changes: 30 additions & 13 deletions dist/popclip/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ var DEFAULT_SETTINGS = {
};
var CUSTOM_SETTINGS = {
useFrontmatter: true,
useHeader: true
useHeader: true,
useSlugifyFileName: true,
useTable: true
};
var SETTINGS = {
...DEFAULT_SETTINGS,
Expand All @@ -52,9 +54,7 @@ var MyPlugin = class extends import_obsidian.Plugin {
await this.loadSettings();
this.registerObsidianProtocolHandler(SETTINGS.action, async (ev) => {
if (ev.heading === SETTINGS.actionHeading) {
new FileWriter(this.app).writeToFile(
JSON.parse(ev.data)
);
new FileWriter(this.app).writeToFile(JSON.parse(ev.data));
}
});
}
Expand All @@ -75,18 +75,30 @@ var FileWriter = class {
}
async writeToFile(payload) {
const path = this.normalizePath(payload);
this.app.vault.create((0, import_obsidian.normalizePath)(path), this.setContent(payload));
this.app.vault.adapter.write(
(0, import_obsidian.normalizePath)(path),
this.setContent(payload)
);
}
normalizePath(payload) {
const fileName = payload.title && typeof payload.title === "string" && payload.title.length < 60 ? payload.title : this.normalizeDate();
let filePath = decodeURIComponent(payload.path) || "";
console.log(payload.path, filePath);
const path = slugify(`${filePath.trim()}/${fileName.trim()}`) + ".md";
let fileName = this.normalizedDate();
if (payload.title) {
const title = payload.title.slice(0, 20).trim();
fileName = `${fileName}-${title}`;
}
if (SETTINGS.useSlugifyFileName) {
fileName = slugify(fileName);
}
fileName = fileName + ".md";
let filePath = decodeURIComponent(payload.path);
console.log("parentFolder", filePath);
const path = (0, import_obsidian.normalizePath)(filePath + "/" + fileName);
console.log(payload.path, filePath, path);
return path;
}
normalizeDate() {
normalizedDate() {
const datetime = new Date().toISOString().split(".")[0];
return datetime.replaceAll("-", "").replaceAll(":", "").replace("t", "");
return datetime.replaceAll("-", "").replaceAll(":", "").replace("T", "");
}
setFrontmatter(payload) {
const elements = [
Expand All @@ -99,15 +111,20 @@ var FileWriter = class {
return elements.join("\n");
}
setHeader(payload) {
return `# ${payload == null ? void 0 : payload.title}`;
return `# ${payload == null ? void 0 : payload.title}
`;
}
setTable(payload) {
const currentDate = new Date().toISOString();
const source = (payload == null ? void 0 : payload.source) || "";
}
setContent(payload) {
const elements = [
this.setFrontmatter(payload),
this.setHeader(payload),
payload == null ? void 0 : payload.clipping
];
return elements.join("\n\n");
return elements.join("\n");
}
};
function slugify(str) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
"version": "node version-bump.mjs && git add manifest.json versions.json",
"deploy": "npm run build && cp main.js styles.css manifest.json dist/popclip/",
"deploy:test": "cp main.js styles.css manifest.json ~/Downloads/test/.obsidian/plugins/popclip"
"deploy:test": "npm run build && cp main.js styles.css manifest.json ~/Downloads/test/.obsidian/plugins/popclip"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit 3ea53da

Please sign in to comment.