|
1 |
| -# Joplin Plugin |
| 1 | +# Slash Commands: Datetime & More |
2 | 2 |
|
3 |
| -This is a template to create a new Joplin plugin. |
| 3 | +This plugin is a collection of utility commands that can be executed by typing corresponding keywords, which start with a slash ('/'). Current version only supports two type of commands but more might be added in the future. |
4 | 4 |
|
5 |
| -The main two files you will want to look at are: |
6 | 5 |
|
7 |
| -- `/src/index.ts`, which contains the entry point for the plugin source code. |
8 |
| -- `/src/manifest.json`, which is the plugin manifest. It contains information such as the plugin a name, version, etc. |
| 6 | + |
9 | 7 |
|
10 |
| -## Building the plugin |
11 | 8 |
|
12 |
| -The plugin is built using Webpack, which creates the compiled code in `/dist`. A JPL archive will also be created at the root, which can use to distribute the plugin. |
| 9 | +## Usage |
| 10 | +### String Command |
| 11 | +- String commands simply replace a keyword with one of the predefined strings. |
| 12 | +- **Built-in**: `/greet`, `/task`, `todotxt` |
| 13 | +- **Definition**: `[ "string" , "<keyword>", ["<string1>", "<string2" ] ]` |
13 | 14 |
|
14 |
| -To build the plugin, simply run `npm run dist`. |
| 15 | +### Datetime Command |
| 16 | +- Datetime commands print out the current now with one of the predefined datestring format. Optionally you can offset the time by day, hour, and minutes |
| 17 | +- **Built-in**: `/now`, `/date`, `/time`, `/todoa`, `/todob`, `/todoc`, `/todod`, `/todoe` |
| 18 | +- **Offset examples**: adding `/now+d-H:M`, subtracting `/now-d-H:M` |
| 19 | +- **Offset formats**: `d-H:M`, `d-H`, `H:M`, `d` |
| 20 | +- **Definition**: `[ "string" , "<keyword>", ["<format1>", "<format2>" ] ]` |
| 21 | +- This command uses [Javascript Date Format](https://blog.stevenlevithan.com/archives/date-time-format) to parse datestring. You can check the original library on how to form your own `format`. |
15 | 22 |
|
16 |
| -The project is setup to use TypeScript, although you can change the configuration to use plain JavaScript. |
| 23 | +### Customization |
| 24 | +Even though there is only several types of commands, you can create many useful commands to serve your needs by setting the command definitions in the plugin setting by yourself. The commands definitions is an array of array but due to some awkwardness with Javascript and JSON string parse you need to carefully escape it. |
17 | 25 |
|
18 |
| -## Updating the plugin framework |
| 26 | +``` |
| 27 | +[ |
| 28 | + ["datetime", "now", [ "dd/mm/yyyy HH:MM", "yyyy-mm-dd\"T\"HH:MM:ss" ] ], |
| 29 | + ["datetime", "date", [ "dd/mm/yyyy", "yyyy-mm-dd" ] ], |
| 30 | + ["datetime", "time", [ "HH:MM", "HH:MM:ss" ] ], |
| 31 | + ["string", "greet", [ "Hello World" ] ], |
| 32 | + ["string", "task", [ "- [ ] " ] ], |
| 33 | + ["string", "todotxt", [ "```todotxt sort:default\n\n```" ] ], |
| 34 | + ["datetime", "todoa", [ "\"(A)\" yyyy-mm-dd " ] ], |
| 35 | + ["datetime", "todob", [ "\"(B)\" yyyy-mm-dd " ] ], |
| 36 | + ["datetime", "todoc", [ "\"(C)\" yyyy-mm-dd " ] ], |
| 37 | + ["datetime", "todod", [ "\"(D)\" yyyy-mm-dd " ] ], |
| 38 | + ["datetime", "todoe", [ "\"(E)\" yyyy-mm-dd " ] ] |
| 39 | +] |
| 40 | +``` |
19 | 41 |
|
20 |
| -To update the plugin framework, run `npm run update`. |
| 42 | +There is another awkwardness with Joplin Plugin Setting that only accept a single line value so you need to minify it like this. |
21 | 43 |
|
22 |
| -In general this command tries to do the right thing - in particular it's going to merge the changes in package.json and .gitignore instead of overwriting. It will also leave "/src" as well as README.md untouched. |
| 44 | +``` |
| 45 | +[["datetime", "now", [ "dd/mm/yyyy HH:MM", "yyyy-mm-dd\"T\"HH:MM:ss" ] ], ["datetime", "date", [ "dd/mm/yyyy", "yyyy-mm-dd" ] ], ["datetime", "time", [ "HH:MM", "HH:MM:ss" ] ], ["string", "greet", [ "Hello World" ] ], ["string", "task", [ "- [ ] " ] ], ["string", "todotxt", [ "```todotxt sort:default\n\n```" ] ], ["datetime", "todoa", [ "\"(A)\" yyyy-mm-dd " ] ], ["datetime", "todob", [ "\"(B)\" yyyy-mm-dd " ] ], ["datetime", "todoc", [ "\"(C)\" yyyy-mm-dd " ] ], ["datetime", "todod", [ "\"(D)\" yyyy-mm-dd " ] ], ["datetime", "todoe", [ "\"(E)\" yyyy-mm-dd " ] ] ] |
| 46 | +``` |
23 | 47 |
|
24 |
| -The file that may cause problem is "webpack.config.js" because it's going to be overwritten. For that reason, if you want to change it, consider creating a separate JavaScript file and include it in webpack.config.js. That way, when you update, you only have to restore the line that include your file. |
| 48 | +I will try to improve the configuration process when I find a better solution. If you messed with the setting and the plugin is no longer work, try paste the above definitions to your setting. |
| 49 | + |
| 50 | +## Acknowledgements |
| 51 | +- Many thanks to @roman-r-m for the great [Quick Link](https://github.com/roman-r-m/joplin-plugin-quick-links) plugin which I used a lot and also a reference for this plugin |
| 52 | +- And Steven Levithan for a simple and easy-to-use [JavaScript Date Format Library](https://blog.stevenlevithan.com/archives/date-time-format) |
| 53 | + |
| 54 | +## License |
| 55 | + |
| 56 | +[MIT](https://raw.githubusercontent.com/hieuthi/joplin-plugin-slash-commands/main/LICENSE) |
0 commit comments