mirror of
https://github.com/moyf/easy-copy.git
synced 2026-07-22 05:43:47 +00:00
Add dotenv support and update VAULT_PATH configuration
This commit is contained in:
parent
d511d8c263
commit
b2870dc9a2
5 changed files with 31 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -26,3 +26,6 @@ Thumbs.db
|
|||
|
||||
# Exclude zip
|
||||
*.zip
|
||||
|
||||
# env
|
||||
.env
|
||||
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -8,6 +8,9 @@
|
|||
"name": "obsidian-sample-plugin",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
|
|
@ -1005,6 +1008,17 @@
|
|||
"node": ">=6.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/dotenv": {
|
||||
"version": "16.4.7",
|
||||
"resolved": "https://registry.npmmirror.com/dotenv/-/dotenv-16.4.7.tgz",
|
||||
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://dotenvx.com"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.17.3",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.3.tgz",
|
||||
|
|
|
|||
|
|
@ -22,5 +22,8 @@
|
|||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,21 @@ import { copyFile, mkdir } from 'fs/promises';
|
|||
import { existsSync } from 'fs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
// 获取当前文件的目录
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const rootDir = join(__dirname, '..');
|
||||
|
||||
// 这里定义你的 Obsidian 库路径
|
||||
const VAULT_PATH = 'V:\\Code\\CodeRepos\\plugin-dev-vault';
|
||||
// 加载 .env 文件中的环境变量
|
||||
dotenv.config();
|
||||
// 获取 VAULT_PATH 环境变量
|
||||
const VAULT_PATH = process.env.VAULT_PATH;
|
||||
if (!VAULT_PATH) {
|
||||
throw new Error(
|
||||
'VAULT_PATH is not defined. Please create a .env file in the project root and add the line: VAULT_PATH=/path/to/your/vault'
|
||||
);
|
||||
}
|
||||
const pluginDir = join(VAULT_PATH, '.obsidian', 'plugins', 'easy-copy');
|
||||
|
||||
async function copyToVault() {
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ export default class EasyCopy extends Plugin {
|
|||
const filename = file.basename;
|
||||
|
||||
// 1. 检查是否是标题行
|
||||
if (curLine.startsWith('#')) {
|
||||
if (/^#+\s/.test(curLine)) {
|
||||
this.copyHeadingLink(curLine, filename);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue