Skip to content

Commit

Permalink
Merge pull request #42 from a-nano-dust/fix-部分功能优化
Browse files Browse the repository at this point in the history
Fix 部分功能优化
  • Loading branch information
a-nano-dust committed Jun 6, 2024
2 parents 3fc06a4 + c972eaf commit f10ceba
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/dist/main.js
/dist/*
75 changes: 47 additions & 28 deletions esbuild.config.mjs
Original file line number Diff line number Diff line change
@@ -1,42 +1,61 @@
import esbuild from "esbuild";
import process from "process";
import builtins from "builtin-modules";
import copyPluginPkg from "@sprout2000/esbuild-copy-plugin";


const {copyPlugin} = copyPluginPkg


const banner =
`/*
`/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
`;

const prod = (process.argv[2] === "production");


const result = await esbuild.build({
bundle: true,
entryPoints: ["src/main.ts"],
outdir: "dist",
jsx: "automatic",
format: "cjs",
target: "es2018",
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
banner: {
js: banner,
},
logLevel: "info",
sourcemap: "inline",
treeShaking: true,
bundle: true,
entryPoints: ["src/main.ts"],
outdir: "dist",
jsx: "automatic",
format: "cjs",
target: "es2018",
external: [
"obsidian",
"electron",
"@codemirror/autocomplete",
"@codemirror/collab",
"@codemirror/commands",
"@codemirror/language",
"@codemirror/lint",
"@codemirror/search",
"@codemirror/state",
"@codemirror/view",
"@lezer/common",
"@lezer/highlight",
"@lezer/lr",
...builtins],
banner: {
js: banner,
},
logLevel: "info",
minify: prod,
sourcemap: prod ? false : "inline",
treeShaking: true,
plugins: [
copyPlugin({
src: "src/css/styles.css",
dest: "dist/styles.css"
}),
copyPlugin({
src: "manifest.json",
dest: "dist/manifest.json"
}),
]
});

console.log(result)
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "dust-calendar",
"name": "Dust Calendar",
"version": "1.2.0",
"version": "1.2.1",
"minAppVersion": "1.5.12",
"description": "更符合中国习惯的日历,可以显示农历、节气、节假日、调休信息,支持月视图和年视图切换,支持关联创建周期性笔记。",
"author": "纳米级尘埃",
Expand Down
38 changes: 34 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 24 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
{
"name": "@nano-dust/dust-obsidian-diary",
"version": "1.0.0",
"description": "Manage periodic notes more elegantly",
"name": "@nano-dust/dust-calendar",
"version": "1.2.1",
"description": "a calendar plugin for obsidian",
"main": "main.js",
"scripts": {
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs"
"dev": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs",
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production"
},
"keywords": [],
"author": "Nano Dust",
"license": "MIT",
"devDependencies": {
"@reduxjs/toolkit": "^2.2.1",
"@types/node": "^16.11.6",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.20.0",
"lucide-react": "^0.356.0",
"luxon": "^3.4.4",
"obsidian": "latest",
"react-redux": "^9.1.0",
"redux": "^5.0.1",
"ts-node": "^10.9.2",
"tslib": "2.4.0",
"typescript": "^4.7.4"
},
"@reduxjs/toolkit": "^2.2.1",
"@sprout2000/esbuild-copy-plugin": "^1.1.14",
"@types/node": "^16.11.6",
"@types/react": "^18.2.55",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
"builtin-modules": "3.3.0",
"esbuild": "0.20.0",
"lucide-react": "^0.356.0",
"luxon": "^3.4.4",
"obsidian": "latest",
"react-redux": "^9.1.0",
"redux": "^5.0.1",
"ts-node": "^10.9.2",
"tslib": "2.4.0",
"typescript": "^4.7.4"
},
"dependencies": {
"@types/luxon": "^3.4.2",
"lunar-typescript": "^1.7.2",
"process": "^0.11.10",
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/Database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import DustCalendarPlugin from "../main";
import PluginSetting from "../entity/PluginSetting";


/**
* 类似于底层数据库,不允许界面直接读写,只能通过 controller 间接控制
*/
export default class Database {

public readonly plugin: DustCalendarPlugin;
Expand Down
3 changes: 3 additions & 0 deletions src/core/NoteController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import ConfirmCreatingNoteModal from "../view/modal/ConfirmCreatingNoteModal";
import DustCalendarPlugin from "../main";


/**
* 封装笔记操作
*/
export default class NoteController {

public readonly plugin: DustCalendarPlugin;
Expand Down
7 changes: 7 additions & 0 deletions src/core/TemplateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import ObsidianTemplateUtil from "../util/ObsidianTemplateUtil";
import TemplaterUtil from "../util/TemplaterUtil";


/**
* 封装模板操作
*/
export default class TemplateController {

public readonly plugin: DustCalendarPlugin;
Expand All @@ -22,6 +25,10 @@ export default class TemplateController {
return this.plugin.database.setting.templatePlugin;
}

public isTemplatePluginEnable(): boolean {
return this.templateUtil.isEnable();
}

public updateTemplatePlugin(templatePlugin: TemplatePlugin): void {
this.plugin.database.setting.templatePlugin = templatePlugin;
if (templatePlugin === TemplatePlugin.OBSIDIAN) {
Expand Down
3 changes: 3 additions & 0 deletions src/core/ViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import DustCalendarPlugin from "../main";
import {FontSizeChangeMode, QuarterNameMode} from "../base/enum";


/**
* 封装界面所需的操作
*/
export default class ViewController {

public readonly plugin: DustCalendarPlugin;
Expand Down
4 changes: 4 additions & 0 deletions src/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
opacity: 0.2;
}

.d-color-accent {
color: var(--text-accent);
}

.d-color-error {
color: var(--text-error);
}
Expand Down
13 changes: 13 additions & 0 deletions src/util/TemplateUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import DustCalendarPlugin from "../main";
import Path from "./Path";


/**
* 模板工具的基类,用于统一不同模板插件的行为
*/
export default class TemplateUtil {

public readonly plugin: DustCalendarPlugin;
Expand All @@ -11,14 +14,24 @@ export default class TemplateUtil {
this.plugin = plugin;
}

/**
* 判断指定的模板插件是否启用了
*/
public isEnable(): boolean {
return false;
}

/**
* 获取模板文件夹
*/
public getTemplateFolder(): Path {
return new Path("");
}

/**
* 向指定的文件中插入模板
* @param templateFile
*/
public insertTemplateImpl(templateFile: TAbstractFile) {

}
Expand Down
6 changes: 6 additions & 0 deletions src/view/setting/MainSettingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,16 @@ export default class MainSettingTab extends PluginSettingTab {
<NotePattern plugin={this.plugin} noteType={noteType}/>
);

// 是否选择了模板插件
if (this.plugin.templateController.getTemplatePlugin() === TemplatePlugin.NONE) {
return;
}

// 指定的模板插件是否启用
if (!this.plugin.templateController.isTemplatePluginEnable()) {
return;
}

let noteTemplateElement = new Setting(containerEl);
noteTemplateElement.settingEl.empty();
noteTemplateRoot = createRoot(noteTemplateElement.settingEl);
Expand Down
6 changes: 4 additions & 2 deletions src/view/setting/NotePattern.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ export default function NotePattern({plugin, noteType}: { plugin: DustCalendarPl
</div>
<div className="setting-item-description">
<div>请使用&nbsp;<a
href="src/view/setting/DailyNotePattern#/formatting?id=table-of-tokens">luxon语法</a>&nbsp;指定笔记文件的生成路径。
href="https://moment.github.io/luxon/#/formatting?id=table-of-tokens">luxon语法</a>&nbsp;指定笔记文件的生成路径。
</div>
{notePattern.length === 0
? <div className="d-color-error">尚未配置文件命名规则,Dust Calendar 将无法为您创建笔记文件。</div>
: <div>规则应用后的文件路径为(基于当前日期):{text}</div>
: <div>规则应用后的文件路径为(基于当前日期):<b className="d-color-accent">{text}</b></div>
}
<div><b>注意:</b>使用单引号可以进行转义,例如:yyyy 'year' MM 'month' dd 'day'
格式化结果为 {DateTime.now().toFormat("yyyy 'year' MM 'month' dd 'day'")}</div>
</div>
</div>
<div className="setting-item-control">
Expand Down
Loading

0 comments on commit f10ceba

Please sign in to comment.