Skip to content

Commit

Permalink
Merge pull request #5 from RyoJerryYu/feat-move-file-into-package
Browse files Browse the repository at this point in the history
feat: move file into package
  • Loading branch information
RyoJerryYu authored May 26, 2024
2 parents 3e2d7de + 8f97610 commit 3976692
Show file tree
Hide file tree
Showing 62 changed files with 183 additions and 106 deletions.
41 changes: 41 additions & 0 deletions README-ZH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Obsidian Memos Sync Plugin

中文 | [English](README.md)

这是一个用于 [Obsidian](https://obsidian.md) 的插件。

这个插件提供了一些命令,可以将来自 [Memos](https://github.com/usememos/memos) 服务器账号里的记录同步到你的 Obsidian 笔记库的每日笔记中。如果每日笔记不存在,它还会根据规则创建一个。

## 兼容性

这个插件与官方的 [Daily Notes 插件](https://help.obsidian.md/Plugins/Daily+notes)[Calendar 插件](https://github.com/liamcain/obsidian-calendar-plugin)[Periodic Notes 插件](https://github.com/liamcain/obsidian-periodic-notes) 完全兼容。

这个插件兼容 Memos API 的各个版本,包括 v0.22.0 之后新版以及之前的旧版。

## 命令

### 同步每日 Memos

这个命令将从 Memos 服务器增量同步记录到每日笔记。
这个插件会记住上次同步的时间,并且只同步那个时间之后的记录。

### 强制同步每日 Memos

这个命令将重新同步 Memos 服务器上的所有的记录。

### 强制同步当前每日 Memos

这个命令将为光标所在的当前每日笔记重新同步 Memos 服务器上的记录。
当你想要为特定一天同步记录时,这个命令非常有用。

## 配置

| Key | 描述 | 例子 |
| ------------------ | ------------------------------------------------------------------------- | --------------------------------- |
| Daily Memos Header | 每日笔记中的标题, Memos 记录会替换这个章节下的内容。 | `Memos` |
| Attachment Folder | 存储附件的文件夹。 | `attachments/memos_daily` |
| Memos API Version | Memos 服务器的版本。 | `after v0.22.x`, `before v0.21.x` |
| Memos API URL | Memos API的URL。 | `http://localhost:5230` |
| Memos API Token | Memos API的令牌。你可以在 Memos 页面 -> 设置 -> 我的账户 界面上创建一个。 | |


39 changes: 33 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
# Obsidian Memos Sync Plugin

This is a sample plugin for Obsidian (https://obsidian.md).
[中文](README-ZH.md) | English

This plugin provides a few commands to sync memos from a [memos](https://github.com/usememos/memos) server to daily notes in your Obsidian vault.
This is a plugin for Obsidian (https://obsidian.md).

This plugin is fully compatible with official Daily Notes plugin, [Calendar plugin](https://github.com/liamcain/obsidian-calendar-plugin) and [Periodic Notes plugin](https://github.com/liamcain/obsidian-periodic-notes).
This plugin provides a few commands to sync memos from a [Memos](https://github.com/usememos/memos) server to daily notes in your Obsidian vault. It will also create a daily note if it does not exist.

## Compatibility

This plugin is fully compatible with official [Daily Notes plugin](https://help.obsidian.md/Plugins/Daily+notes), [Calendar plugin](https://github.com/liamcain/obsidian-calendar-plugin) and [Periodic Notes plugin](https://github.com/liamcain/obsidian-periodic-notes).

This plugin is compatible with each version of Memos API, both for that after v0.22.0 and before.

## Commands

- Sync daily memos
- Force sync daily memos
- Force sync current daily memos
### Sync daily memos

This command will sync memos from the Memos server incrementally to the daily notes.
This plugin will remember the last sync time and only sync memos after that time.

### Force sync daily memos

This command will resync all memos from the Memos server.

### Force sync current daily memos

This command will resync memos from the Memos server for the current daily note that cursor is on.
Useful when you want to sync memos for a specific day.

## Configuration

| Key | Description | Example |
| ------------------ | ------------------------------------------------------------------------------------- | --------------------------------- |
| Daily Memos Header | The header in daily notes, where memos will be replaced in. | `Memos` |
| Attachment Folder | The folder to store attachments. | `attachments/memos_daily` |
| Memos API Version | Which version the Memos Server is. | `after v0.22.x`, `before v0.21.x` |
| Memos API URL | The URL of the Memos API. | `http://localhost:5230` |
| Memos API Token | The token for the Memos API. You can create one on Memos UI -> Settings -> My Account | |

2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const context = await esbuild.context({
banner: {
js: banner,
},
entryPoints: ["main.tsx"],
entryPoints: ["src/main.ts"],
bundle: true,
external: [
"obsidian",
Expand Down
2 changes: 1 addition & 1 deletion gen-proto.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cd ./api/memos-proto-v0.22.0/
cd ./src/api/memos-proto-v0.22.0/
buf generate
14 changes: 7 additions & 7 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "ryo-usememos-sync",
"id": "obsidian-memos-sync",
"name": "Memos Sync",
"version": "1.0.0",
"version": "0.3.0",
"minAppVersion": "0.15.0",
"description": "Syncing Memos to Obsidian daily note. Fully compatible with official Daily Notes plugin, Calendar plugin and Periodic Notes plugin.",
"author": "Obsidian",
"authorUrl": "https://obsidian.md",
"fundingUrl": "https://obsidian.md/pricing",
"isDesktopOnly": false
"description": "Syncing memos from a [Memos](https://github.com/usememos/memos) server to Obsidian daily note. Fully compatible with official Daily Notes plugin, Calendar plugin and Periodic Notes plugin.",
"author": "RyoJerryYu",
"authorUrl": "https://github.com/RyoJerryYu",
"isDesktopOnly": true,
"js": "main.js"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-memos-sync",
"version": "1.0.0",
"version": "0.3.0",
"description": "Syncing Memos to Obsidian daily note.",
"main": "main.js",
"scripts": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion api/memos-v0.19.1.ts → src/api/memos-v0.19.1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios, { AxiosInstance } from "axios";
import * as log from "utils/log";
import * as log from "@/utils/log";

export type ResourceType = {
name?: string;
Expand Down
File renamed without changes.
111 changes: 58 additions & 53 deletions main.tsx → src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,23 @@ import {
Plugin,
PluginSettingTab,
Setting,
SliderComponent,
setTooltip,
} from "obsidian";
import * as React from "react";
import { createRoot } from "react-dom/client";
import { DailyMemos } from "services/DailyMemos/DailyMemos";
import { PluginSettings } from "types/PluginSettings";
import { DailyMemos } from "@/services/DailyMemos/DailyMemos";
import { PluginSettings } from "@/types/PluginSettings";
import { appHasDailyNotesPluginLoaded } from "obsidian-daily-notes-interface";

// Remember to rename these classes and interfaces!

const DEFAULT_SETTINGS: PluginSettings = {
dailyMemosHeader: "Memos",
usememosAPI: "https://usememos.com/api/v1",
usememosToken: "",
attachmentFolder: "Attachments",
memosAPIVersion: "v0.19.1",
memosAPIURL: "https://usememos.com",
memosAPIToken: "",
attachmentFolder: "Attachments",
};

export default class MyPlugin extends Plugin {
Expand Down Expand Up @@ -74,23 +77,8 @@ export default class MyPlugin extends Plugin {
};
}

class SampleModal extends Modal {
constructor(app: App) {
super(app);
}

onOpen() {
const { contentEl } = this;
contentEl.setText("Woah!");
}

onClose() {
const { contentEl } = this;
contentEl.empty();
}
}

class SampleSettingTab extends PluginSettingTab {
app: App;
plugin: MyPlugin;

constructor(app: App, plugin: MyPlugin) {
Expand All @@ -108,7 +96,24 @@ class SampleSettingTab extends PluginSettingTab {

display(): void {
this.containerEl.empty();
this.containerEl.createEl("h3", { text: "Settings for My Plugin." });
const dailyNotesEnabled = appHasDailyNotesPluginLoaded();
if (!dailyNotesEnabled) {
this.containerEl.createEl("h3", {
text: "Attention: Daily Notes is not enabled.",
attr: {
style: "color: red",
}
});
this.containerEl.createEl("p", {
text: "Daily Notes feature is not enabled. Please enable the official Daily Notes plugin or daily notes feature in Periodic Notes plugin. Otherwise, this plugin will not work properly.",
attr: {
style: "color: red",
}
})

}

this.containerEl.createEl("h3", { text: "Settings for Memos Sync" });

new Setting(this.containerEl)
.setName("Daily Memos Header")
Expand All @@ -122,58 +127,58 @@ class SampleSettingTab extends PluginSettingTab {
});
});
});

new Setting(this.containerEl)
.setName("Memos API Version")
.setDesc("Memos API Version")
.addDropdown((dropDown)=>{
dropDown.addOptions({
"v0.19.1": "before v0.21.x",
"v0.22.0": "after v0.22.x",
});
dropDown.setValue(this.plugin.settings.memosAPIVersion);
dropDown.onChange((value) => {
this.saveSettings({
memosAPIVersion: value as "v0.19.1" | "v0.22.0",
});
})
})

new Setting(this.containerEl)
.setName("Usememos API URL")
.setDesc("Usememos API URL, e.g. http://localhost:5230")
.setName("Attachment Folder")
.setDesc("The folder for attachments.")
.addText((textfield) => {
textfield.setPlaceholder(DEFAULT_SETTINGS.usememosAPI);
textfield.setValue(this.plugin.settings.usememosAPI);
textfield.setPlaceholder(DEFAULT_SETTINGS.attachmentFolder);
textfield.setValue(this.plugin.settings.attachmentFolder);
textfield.onChange((value) => {
this.saveSettings({
usememosAPI: value,
attachmentFolder: value,
});
});
});

new Setting(this.containerEl)
.setName("Memos API Version")
.setDesc("Memos API Version")
.addDropdown((dropDown) => {
dropDown.addOptions({
"v0.19.1": "before v0.21.x",
"v0.22.0": "after v0.22.x",
});
dropDown.setValue(this.plugin.settings.memosAPIVersion);
dropDown.onChange((value) => {
this.saveSettings({
memosAPIVersion: value as "v0.19.1" | "v0.22.0",
});
});
});

new Setting(this.containerEl)
.setName("Usememos Token")
.setDesc("Usememos token.")
.setName("Memos API URL")
.setDesc("Memos API URL, e.g. http://localhost:5230")
.addText((textfield) => {
textfield.setPlaceholder(DEFAULT_SETTINGS.usememosToken);
textfield.setValue(this.plugin.settings.usememosToken);
textfield.setPlaceholder(DEFAULT_SETTINGS.memosAPIURL);
textfield.setValue(this.plugin.settings.memosAPIURL);
textfield.onChange((value) => {
this.saveSettings({
usememosToken: value,
memosAPIURL: value,
});
});
});

new Setting(this.containerEl)
.setName("Attachment Folder")
.setDesc("The folder for attachments.")
.setName("Memos API Token")
.setDesc("Memos API token.")
.addText((textfield) => {
textfield.setPlaceholder(DEFAULT_SETTINGS.attachmentFolder);
textfield.setValue(this.plugin.settings.attachmentFolder);
textfield.setPlaceholder(DEFAULT_SETTINGS.memosAPIToken);
textfield.setValue(this.plugin.settings.memosAPIToken);
textfield.onChange((value) => {
this.saveSettings({
attachmentFolder: value,
memosAPIToken: value,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
} from "obsidian-daily-notes-interface";
import type { Moment } from "moment";
import { App, MarkdownView, TFile, normalizePath } from "obsidian";
import { PluginSettings } from "types/PluginSettings";
import * as log from "utils/log";
import { PluginSettings } from "@/types/PluginSettings";
import * as log from "@/utils/log";
import { MemosPaginator } from "./MemosPaginator";
import { DailyNoteModifier } from "./DailyNoteModifier";
import { MemosResourceFetcher } from "./MemosResourceFetcher";
Expand Down Expand Up @@ -46,7 +46,7 @@ export class DailyMemos {
private memosResourceFetcher: MemosResourceFetcher;

constructor(app: App, settings: PluginSettings) {
if (!settings.usememosAPI) {
if (!settings.memosAPIURL) {
log.error(
"Please set the usememosAPI setting in the plugin settings."
);
Expand All @@ -58,7 +58,7 @@ export class DailyMemos {

this.memosFactory = new MemosAbstractFactory(this.settings);

this.localKey = `periodic-para-daily-record-last-time-${this.settings.usememosToken}`;
this.localKey = `periodic-para-daily-record-last-time-${this.settings.memosAPIToken}`;
const lastTime = window.localStorage.getItem(this.localKey) || "";
this.memosPaginator = this.memosFactory.createMemosPaginator(lastTime);
this.memosResourceFetcher = this.memosFactory.createResourceFetcher();
Expand Down Expand Up @@ -122,7 +122,7 @@ export class DailyMemos {
* Download resources to attachments folder.
*/
private downloadResource = async (): Promise<void> => {
const { origin } = new URL(this.settings.usememosAPI);
const { origin } = new URL(this.settings.memosAPIURL);
const data = await this.memosResourceFetcher.listResources();

if (!data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as log from "utils/log";
import * as log from "@/utils/log";

/**
* Generates a regular expression for matching a header in a daily note.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DailyRecordType, MemosClient0191 } from "api/memos-v0.19.1";
import * as log from "utils/log";
import { MemoCli } from "api/memos-v0.22.0";
import { Memo } from "api/memos-proto-v0.22.0/gen/api/v1/memo_service";
import { DailyRecordType, MemosClient0191 } from "@/api/memos-v0.19.1";
import * as log from "@/utils/log";
import { MemoCli } from "@/api/memos-v0.22.0";
import { Memo } from "@/api/memos-proto-v0.22.0/gen/api/v1/memo_service";
import {
APIResource,
convert0220ResourceToAPIResource,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resource } from "api/memos-proto-v0.22.0/gen/api/v1/resource_service";
import { Resource } from "@/api/memos-proto-v0.22.0/gen/api/v1/resource_service";

export type APIResource = {
name?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MemosClient0191 } from "api/memos-v0.19.1";
import * as log from "utils/log";
import { ResourceCli, newClients } from "api/memos-v0.22.0";
import { MemosClient0191 } from "@/api/memos-v0.19.1";
import * as log from "@/utils/log";
import { ResourceCli, newClients } from "@/api/memos-v0.22.0";
import { APIResource, convert0220ResourceToAPIResource } from "./MemosResource";

export type MemosResourceFetcher = {
Expand Down
Loading

0 comments on commit 3976692

Please sign in to comment.