README starting the real plugin v0.2
This commit is contained in:
130
README.md
130
README.md
@@ -1,92 +1,80 @@
|
||||
# Obsidian Sample Plugin
|
||||
# Zettelclean
|
||||
|
||||
This is a sample plugin for Obsidian (https://obsidian.md).
|
||||
Keep a Zettelkasten filename's slug in sync with the note's H1 heading.
|
||||
|
||||
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.
|
||||
Zettelclean resolves the "three sources of truth for a title" problem (filename vs H1 vs
|
||||
YAML `title:`) by separating concerns:
|
||||
|
||||
This sample plugin demonstrates some of the basic functionality the plugin API can do.
|
||||
- The **H1 heading** in the note body is the single source of truth for the human title.
|
||||
- The **filename** is a derived machine identity: `TIMEID-slug(H1).md`.
|
||||
- No YAML is written. Files stay pure Markdown.
|
||||
|
||||
- Adds a ribbon icon, which shows a Notice when clicked.
|
||||
- Adds a command "Open modal (simple)" which opens a Modal.
|
||||
- Adds a plugin setting tab to the settings page.
|
||||
- Registers a global click event and outputs a Notice on click.
|
||||
- Registers a global interval which logs 'setInterval' to the console.
|
||||
It is a small, one-way, prefix-gated renamer: edit the H1, and a moment later the filename's
|
||||
slug tail follows. Nothing else is touched.
|
||||
|
||||
## First time developing plugins?
|
||||
## How it works
|
||||
|
||||
Quick starting guide for new plugin devs:
|
||||
- A note is a zettel when its filename starts with a **TIMEID**: a run of 12 to 18 digits
|
||||
(a timestamp), for example `20260728145404-my-note.md`. Files without that prefix are
|
||||
ignored, so plain notes, daily notes, Excalidraw and Kanban files are never renamed.
|
||||
- The TIMEID is minted **once** and never changes. Only the slug tail is regenerated.
|
||||
- When you edit the H1, zettelclean waits about 5 seconds of idle, then renames the file to
|
||||
`TIMEID-slug(H1).md` using Obsidian's own rename (so backlinks are updated). A 10 second
|
||||
cooldown prevents a just-renamed file from being renamed again.
|
||||
- Sync is strictly one-way, H1 to filename. Renaming a file by hand is never fought.
|
||||
- Delete the H1 and the filename collapses back to the bare `TIMEID.md`.
|
||||
|
||||
- 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 `src/main.ts` to `main.js`.
|
||||
- Make changes to `src/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.
|
||||
The slug is lowercase, ASCII, dash-separated: accents are folded (`Ciências` becomes
|
||||
`ciencias`), runs of punctuation and whitespace collapse to a single dash, and leading and
|
||||
trailing dashes are trimmed.
|
||||
|
||||
## Releasing new releases
|
||||
## Creating notes
|
||||
|
||||
- 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.
|
||||
Use Obsidian's built-in **Unique note creator** core plugin to mint the TIMEID:
|
||||
|
||||
> 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. Settings -> Core plugins -> enable "Unique note creator".
|
||||
2. Set "Unique note format" to `YYYYMMDDHHmmss` (14 digits, second precision - avoids
|
||||
same-minute collisions).
|
||||
3. Click the "Create new unique note" ribbon icon. You get `20260728145404.md`; type your
|
||||
`# Title`, and zettelclean takes over from there.
|
||||
|
||||
## Adding your plugin to the community plugin list
|
||||
Zettelclean also accepts an existing 12-digit (`YYYYMMDDHHmm`) vault if you prefer not to
|
||||
change the setting.
|
||||
|
||||
- Check the [plugin guidelines](https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines).
|
||||
- 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.
|
||||
### Retrofitting existing notes
|
||||
|
||||
## How to use
|
||||
Notes created before you adopted this workflow have no TIMEID. Right-click such a note in the
|
||||
file explorer and choose **"Add zettel TIMEID to filename"**. It mints a fresh timestamp,
|
||||
prepends it, and the note is now a zettel that syncs on future H1 edits.
|
||||
|
||||
- Clone this repo.
|
||||
- Make sure your NodeJS is at least v18 (`node --version`).
|
||||
- `npm i` to install dependencies.
|
||||
- `npm run dev` to start compilation in watch mode.
|
||||
## Pretty sidebar (optional)
|
||||
|
||||
## Manually installing the plugin
|
||||
By default the file explorer shows the slugged filename (with dashes). If you want the sidebar,
|
||||
tabs and graph to show the pretty H1 instead - with no YAML in your files - install the
|
||||
**Front Matter Title** community plugin and set its feature templates to:
|
||||
|
||||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`.
|
||||
|
||||
## Improve code quality with eslint
|
||||
|
||||
- [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.
|
||||
- This project already has eslint preconfigured, you can invoke a check by running`npm run lint`
|
||||
- Together with a custom eslint [plugin](https://github.com/obsidianmd/eslint-plugin) for Obsidan specific code guidelines.
|
||||
- A GitHub action is preconfigured to automatically lint every commit on all branches.
|
||||
|
||||
## 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"
|
||||
}
|
||||
```
|
||||
#heading | _basename
|
||||
```
|
||||
|
||||
If you have multiple URLs, you can also do:
|
||||
That reads the first H1 directly and falls back to the filename when there is none.
|
||||
|
||||
```json
|
||||
{
|
||||
"fundingUrl": {
|
||||
"Buy Me a Coffee": "https://buymeacoffee.com",
|
||||
"GitHub Sponsor": "https://github.com/sponsors",
|
||||
"Patreon": "https://www.patreon.com/"
|
||||
}
|
||||
}
|
||||
```
|
||||
## Settings
|
||||
|
||||
## API Documentation
|
||||
None. Zettelclean is zero-config in this version. The 5 second settle and 10 second cooldown
|
||||
are fixed.
|
||||
|
||||
See https://docs.obsidian.md
|
||||
## Development
|
||||
|
||||
- `npm install` (or `pnpm install`).
|
||||
- `npm run dev` - compile in watch mode.
|
||||
- `npm run build` - typecheck and produce `main.js`.
|
||||
- `npm test` - run the slug unit tests on Node's built-in test runner.
|
||||
- `npm run lint` - eslint with the Obsidian ruleset.
|
||||
|
||||
The pure string logic lives in `src/slug.ts` and is unit-tested in isolation; the Obsidian
|
||||
wiring lives in `src/main.ts`.
|
||||
|
||||
## License
|
||||
|
||||
0-BSD.
|
||||
|
||||
Reference in New Issue
Block a user