Skip to content

Commit

Permalink
release: 1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Hananoshika Yomaru committed Nov 3, 2023
1 parent e3c8034 commit 1a858ec
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 383 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# vscode
.vscode
.vscode

# Intellij
*.iml
Expand All @@ -20,3 +20,4 @@ data.json

# Exclude macOS Finder (System Explorer) View States
.DS_Store
dist
110 changes: 23 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,37 @@
# Obsidian Sample Plugin (Yomaru)
# Obsidian Publish Url

- ✅ husky
- ✅ bun
- ✅ bun github release workflow
- ✅ extended obsidian typescript api
This plugin helps you to copy and open your publish url quickly.

This is a sample plugin for Obsidian (https://obsidian.md).
Demo:

This project uses Typescript to provide type checking and documentation.
The repo depends on the latest plugin API (obsidian.d.ts) in Typescript Definition format, which contains TSDoc comments describing what it does.
## Features

**Note:** The Obsidian API is still in early alpha and is subject to change at any time!
1. simple set up, just require your domain name
2. respect the permalink
3. copy/open the publish url of current view
4. copy theog.io link

This sample plugin demonstrates some of the basic functionality the plugin API can do.
- Adds a ribbon icon, which shows a Notice when clicked.
- Adds a command "Open Sample Modal" which opens a Modal.
- Adds a plugin setting tab to the settings page.
- Registers a global click event and output 'click' to the console.
- Registers a global interval which logs 'setInterval' to the console.
## How to install?

## First time developing plugins?
### Through obsidian community plugin

Quick starting guide for new plugin devs:
waiting for approval:

- Check if [someone already developed a plugin for what you want](https://obsidian.md/plugins)! There might be an existing plugin similar enough that you can partner up with.
- Make a copy of this repo as a template with the "Use this template" button (login to GitHub if you don't see it).
- Clone your repo to a local development folder. For convenience, you can place this folder in your `.obsidian/plugins/your-plugin-name` folder.
- Install NodeJS, then run `npm i` in the command line under your repo folder.
- Run `npm run dev` to compile your plugin from `main.ts` to `main.js`.
- Make changes to `main.ts` (or create new `.ts` files). Those changes should be automatically compiled into `main.js`.
- Reload Obsidian to load the new version of your plugin.
- Enable plugin in settings window.
- For updates to the Obsidian API run `npm update` in the command line under your repo folder.
### Through BRAT

## Releasing new releases
1. install the BRAT plugin
2. go to the plugin option, add beta plugin, copy and paste the link of this repo.
3. the plugin will automatically appear in the list of installed community plugins, enabled this plugin

- Update your `manifest.json` with your new version number, such as `1.0.1`, and the minimum Obsidian version required for your latest release.
- Update your `versions.json` file with `"new-plugin-version": "minimum-obsidian-version"` so older versions of Obsidian can download an older version of your plugin that's compatible.
- Create new GitHub release using your new version number as the "Tag version". Use the exact version number, don't include a prefix `v`. See here for an example: https://github.com/obsidianmd/obsidian-sample-plugin/releases
- Upload the files `manifest.json`, `main.js`, `styles.css` as binary attachments. Note: The manifest.json file must be in two places, first the root path of your repository and also in the release.
- Publish the release.
### Manual installation

> You can simplify the version bump process by running `npm version patch`, `npm version minor` or `npm version major` after updating `minAppVersion` manually in `manifest.json`.
> The command will bump version in `manifest.json` and `package.json`, and add the entry for the new version to `versions.json`
1. cd to .obsidian/plugins
2. git clone this repo
3. cd obsidian-3d-graph && bun install && bun run build
4. there you go 🎉

## Adding your plugin to the community plugin list
## Say thank you

- Check https://github.com/obsidianmd/obsidian-releases/blob/master/plugin-review.md
- Publish an initial version.
- Make sure you have a `README.md` file in the root of your repo.
- Make a pull request at https://github.com/obsidianmd/obsidian-releases to add your plugin.
If you are enjoying this plugin then please support my work and enthusiasm by sponsoring me on Github or buying me a coffee on <https://www.buymeacoffee.com/yomaru>.

## How to use

- Clone this repo.
- Make sure your NodeJS is at least v16 (`node --version`).
- `npm i` or `yarn` to install dependencies.
- `npm run dev` to start compilation in watch mode.

## Manually installing the plugin

- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.

## Improve code quality with eslint (optional)
- [ESLint](https://eslint.org/) is a tool that analyzes your code to quickly find problems. You can run ESLint against your plugin to find common bugs and ways to improve your code.
- To use eslint with this project, make sure to install eslint from terminal:
- `npm install -g eslint`
- To use eslint to analyze this project use this command:
- `eslint main.ts`
- eslint will then create a report with suggestions for code improvement by file and line number.
- If your source code is in a folder, such as `src`, you can use eslint with this command to analyze all files in that folder:
- `eslint .\src\`

## Funding URL

You can include funding URLs where people who use your plugin can financially support it.

The simple way is to set the `fundingUrl` field to your link in your `manifest.json` file:

```json
{
"fundingUrl": "https://buymeacoffee.com"
}
```

If you have multiple URLs, you can also do:

```json
{
"fundingUrl": {
"Buy Me a Coffee": "https://buymeacoffee.com",
"GitHub Sponsor": "https://github.com/sponsors",
"Patreon": "https://www.patreon.com/"
}
}
```

## API Documentation

See https://github.com/obsidianmd/obsidian-api
<a href="https://www.buymeacoffee.com/yomaru" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 30px !important;width: 105px !important;" ></a> [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/hananoshikayomaru)
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "publish-url",
"name": "Publish url",
"version": "1.0.1",
"version": "1.0.2",
"minAppVersion": "0.15.0",
"description": "Obsidian Publish url to the clipboard",
"author": "Hananoshika Yomaru",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-publish-url",
"version": "1.0.1",
"version": "1.0.2",
"description": "Get the publish url",
"main": "main.js",
"scripts": {
Expand Down
11 changes: 11 additions & 0 deletions src/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { NoticeManager } from "@/NoticeManager";
import type { Notice, Plugin as _Plugin } from "obsidian";
export interface ISettingManager<SettingType = unknown> {
/**
* save settings
Expand All @@ -23,3 +25,12 @@ export interface ISettingManager<SettingType = unknown> {
*/
loadSettings(): Promise<SettingType>;
}

export interface Plugin extends _Plugin {
settingManager: ISettingManager;
noticeManager: NoticeManager;
createNotice: (
message: string | DocumentFragment,
duration?: number | undefined
) => Notice;
}
19 changes: 19 additions & 0 deletions src/NoticeManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Notice, Plugin } from "obsidian";

export class NoticeManager {
plugin: Plugin;
constructor(plugin: Plugin) {
this.plugin = plugin;
}

createNotice = (
message: string | DocumentFragment,
duration?: number | undefined
): Notice => {
const notice = new Notice(
`${this.plugin.manifest.name}: ${message}`,
duration
);
return notice;
};
}
40 changes: 5 additions & 35 deletions src/SettingManager.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ISettingManager } from "@/Interfaces";
import { AsyncQueue } from "@/util/AsyncQueue";
import { SettingSchema } from "@/SettingsSchemas";
import { createNotice } from "@/util/createNotice";
import { State } from "@/util/State";
import { Plugin } from "obsidian";
import { Plugin } from "@/Interfaces";
import { z } from "zod";

// the setting of slider
Expand All @@ -14,38 +13,8 @@ export const nodeSize = {
default: 3,
};

// export type BaseFilterSettings = Prettify<
// z.TypeOf<typeof BaseFilterSettingsSchema>
// >;

// export type LocalFilterSetting = Prettify<
// z.TypeOf<typeof LocalFilterSettingSchema>
// >;

// export type GroupSettings = Prettify<z.TypeOf<typeof GroupSettingsSchema>>;

// export type BaseDisplaySettings = Prettify<
// z.TypeOf<typeof BaseDisplaySettingsSchema>
// >;

// export type LocalDisplaySettings = Prettify<
// z.TypeOf<typeof LocalDisplaySettingsSchema>
// >;

// export type GlobalGraphSettings = Prettify<
// z.TypeOf<typeof GlobalGraphSettingsSchema>
// >;

// export type LocalGraphSettings = Prettify<
// z.TypeOf<typeof LocalGraphSettingsSchema>
// >;

// export type SavedSetting = Prettify<z.TypeOf<typeof SavedSettingSchema>>;

export type Setting = Prettify<z.TypeOf<typeof SettingSchema>>;

// export type GraphSetting = Exclude<SavedSetting["setting"], undefined>;

const corruptedMessage =
"The setting is corrupted. You will not be able to save the setting. Please backup your data.json, remove it and reload the plugin. Then migrate your old setting back.";

Expand Down Expand Up @@ -108,7 +77,7 @@ export class MySettingManager implements ISettingManager<Setting> {
const result = SettingSchema.safeParse(loadedData);
// the data schema is wrong or the data is corrupted, then we need to initialize the data
if (!result.success) {
createNotice(corruptedMessage);
this.plugin.createNotice(corruptedMessage);
console.warn("parsed loaded data failed", result.error.flatten());
this.isLoaded = false;
this.setting.value = DEFAULT_SETTING;
Expand All @@ -130,7 +99,7 @@ export class MySettingManager implements ISettingManager<Setting> {
const result = SettingSchema.safeParse(this.setting.value);

if (!result.success) {
createNotice(corruptedMessage);
this.plugin.createNotice(corruptedMessage);
console.warn(
"parsed loaded data failed",
result.error.flatten()
Expand All @@ -146,5 +115,6 @@ export class MySettingManager implements ISettingManager<Setting> {
}

export const DEFAULT_SETTING: Setting = {
test: "test",
publishDomain: "",
theogTemplate: 3,
};
3 changes: 2 additions & 1 deletion src/SettingsSchemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from "zod";

export const SettingSchema = z.object({
test: z.string().default("test"),
publishDomain: z.string().default(""),
theogTemplate: z.number().default(3),
});
Loading

0 comments on commit 1a858ec

Please sign in to comment.