Skip to content

Commit 0ab656a

Browse files
Fix gitignore
1 parent 59f4363 commit 0ab656a

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# vscode
2+
.vscode
3+
4+
# Intellij
5+
*.iml
6+
.idea
7+
8+
# npm
9+
node_modules
10+
11+
12+
# Exclude sourcemaps
13+
*.map
14+
15+
# obsidian
16+
data.json
17+
18+
# Exclude macOS Finder (System Explorer) View States
19+
.DS_Store

main.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const obsidian = require('obsidian');
2+
3+
module.exports = class FolderContextMenuPlugin extends obsidian.Plugin {
4+
async onload() {
5+
// Register the command
6+
this.addCommand({
7+
id: 'copy-folder-contents',
8+
name: 'Copy Folder Contents',
9+
checkCallback: (checking) => {
10+
const activeFile = this.app.workspace.getActiveFile();
11+
const activeFolder = activeFile ? activeFile.parent : null;
12+
13+
if (activeFolder) {
14+
if (!checking) {
15+
this.copyFolderContents(activeFolder);
16+
}
17+
return true;
18+
}
19+
return false;
20+
}
21+
});
22+
23+
// Add the context menu item
24+
this.registerEvent(
25+
this.app.workspace.on('file-menu', (menu, file) => {
26+
if (file instanceof obsidian.TFolder) {
27+
menu.addItem((item) => {
28+
item
29+
.setTitle('Copy contents')
30+
.setIcon('files')
31+
.onClick(() => this.copyFolderContents(file));
32+
});
33+
}
34+
})
35+
);
36+
}
37+
38+
async copyFolderContents(folder) {
39+
const content = await this.recursiveCopyMdFiles(folder);
40+
await navigator.clipboard.writeText(content);
41+
new obsidian.Notice(`Copied Markdown from ${folder.name} to clipboard`);
42+
}
43+
44+
async recursiveCopyMdFiles(folder) {
45+
let content = '';
46+
for (const child of folder.children) {
47+
if (child instanceof obsidian.TFile && child.extension === 'md') {
48+
content += `File: ${child.path}\n\n`;
49+
content += await this.app.vault.read(child);
50+
content += '\n\n---\n\n';
51+
} else if (child instanceof obsidian.TFolder) {
52+
content += await this.recursiveCopyMdFiles(child);
53+
}
54+
}
55+
return content;
56+
}
57+
}

0 commit comments

Comments
 (0)