From 2c25d8a5a7d875ac84db22089d0f4abdf16d30f0 Mon Sep 17 00:00:00 2001 From: SilentVoid13 <51264226+SilentVoid13@users.noreply.github.com> Date: Sun, 8 Nov 2020 17:36:50 +0100 Subject: [PATCH] Adding new internal_plugins --- README.md | 29 ++++++++++++++++------------- manifest.json | 2 +- package.json | 3 ++- src/internal_templates.ts | 21 ++++++++++++++++++++- tsconfig.json | 1 + 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 0b135c56..7d7a7715 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ I invite everyone to contribute to this plugin development by adding new interna Here is the complete list of all the available internal command templates: -| Internal Command Template | Description | Example Output | -| ------------------------- | -------------------------------------------------------- | ------------------------- | -| `{{note_title}}` | This command template retrieves the active file name. | `MyFile` | -| `{{note_content}}` | This command template retrieves the active file content. | `This is my note content` | +| Internal Command Template | Description | Example Output | +| ------------------------- | ---------------------------------- | ------------------------- | +| `{{note_title}}` | Retrieves the active file name. | `MyFile` | +| `{{note_content}}` | Retrieves the active file content. | `This is my note content` | ##### 2. Create template files @@ -55,18 +55,21 @@ I invite everyone to contribute to this plugin development by adding new interna | Internal Template | Description | Example Output | | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ | -| `{{templater_title}}` | This template retrieves the active file name. | `MyFile` | -| `{{templater_daily_quote}}` | This template retrieves and parse the daily quote from the API https://quotes.rest/. | ![templater_daily_quote](https://raw.githubusercontent.com/SilentVoid13/Templater/master/imgs/templater_daily_quote.png) | -| `{{templater_random_image}}` | This template gets a random image from https://source.unsplash.com/random | `![image](https://images.unsplash.com/photo-1602583019685-26371425dc0f)` | +| `{{templater_title}}` | Retrieves the active file name. | `MyFile` | +| `{{templater_today}}` | Retrieves today's date in the `YYYY-MM-DD` format. | `2020-11-06` | +| `{{templater_yesterday}}` | Retrieves yesterday's date in the `YYYY-MM-DD` format. | `2020-11-05` | +| `{{templater_tomorrow}}` | Retrieves tomorrow's date in the `YYYY-MM-DD` format. | `2020-11-07` | +| `{{templater_daily_quote}}` | Retrieves and parse the daily quote from the API https://quotes.rest/. | ![templater_daily_quote](https://raw.githubusercontent.com/SilentVoid13/Templater/master/imgs/templater_daily_quote.png) | +| `{{templater_random_image}}` | Gets a random image from https://source.unsplash.com/random | `![image](https://images.unsplash.com/photo-1602583019685-26371425dc0f)` | ## User Configuration example -| Template pattern | Linux / Mac OS command | Example Output | -| ---------------- | ------------------------------------- | -------------------------- | -| `{{today}}` | `date +"%A, %d %B %Y"` | `Friday, 06 November 2020` | -| `{{yesterday}}` | `date --date "1 day ago" +"%Y-%m-%d"` | `2020-11-05` | -| `{{tomorrow}}` | `date --date "1 day" +"%Y-%m-%d"` | `2020-11-07` | -| `{{weather}}` | `curl "wttr.in/Paris?format=3"` | `Paris: ☀️ +12°C` | +| Template pattern | Windows command | Linux / Mac OS command | Example Output | +| ---------------- | ------------------------------------------- | ------------------------------------- | -------------------------- | +| `{{today}}` | `echo %date:~10,4%-%date:~4,2%-%date:~7,2%` | `date +"%A, %d %B %Y"` | `Friday, 06 November 2020` | +| `{{yesterday}}` | N / A | `date --date "1 day ago" +"%Y-%m-%d"` | `2020-11-05` | +| `{{tomorrow}}` | N / A | `date --date "1 day" +"%Y-%m-%d"` | `2020-11-07` | +| `{{weather}}` | N / A | `curl "wttr.in/Paris?format=3"` | `Paris: ☀️ +12°C` | ## Installation diff --git a/manifest.json b/manifest.json index bf4150b9..0a3d34ac 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "templater-obsidian", "name": "Templater", - "version": "0.3.0", + "version": "0.3.1", "description": "Create and use templates", "author": "SilentVoid", "authorUrl": "https://github.com/SilentVoid13", diff --git a/package.json b/package.json index af58753d..7d4ab31b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "templater-obsidian", - "version": "0.3.0", + "version": "0.3.1", "description": "Create and use templates", "main": "main.js", "scripts": { @@ -30,6 +30,7 @@ "axios": "^0.21.0", "child_process": "^1.0.2", "debug": "^4.2.0", + "moment": "^2.29.1", "obsidian-sample-plugin": "https://github.com/obsidianmd/obsidian-api/tarball/master", "supports-color": "^7.2.0" } diff --git a/src/internal_templates.ts b/src/internal_templates.ts index ba89c54e..63f9d712 100644 --- a/src/internal_templates.ts +++ b/src/internal_templates.ts @@ -1,5 +1,6 @@ import { App } from 'obsidian'; import axios from 'axios'; +import moment from 'moment'; // Check https://github.com/SilentVoid13/Templater/blob/master/INTERNAL_TEMPLATES.md to see how to develop your own internal template @@ -10,9 +11,12 @@ import axios from 'axios'; // Hashmap where the template pattern is the key and the associated function is the value. // Just add them here to add your internal template to the plugin. export const internal_templates_map: {[id: string]: Function} = { + "{{templater_title}}": templater_title, + "{{templater_today}}": templater_today, + "{{templater_tomorrow}}": templater_tomorrow, + "{{templater_yesterday}}": templater_yesterday, "{{templater_daily_quote}}": templater_daily_quote, "{{templater_random_picture}}": templater_random_picture, - "{{templater_title}}": templater_title, }; export async function replace_internal_templates(app: App, content: string) { @@ -50,3 +54,18 @@ async function templater_title(app: App): Promise { let activeLeaf = app.workspace.activeLeaf; return activeLeaf.getDisplayText(); } + +async function templater_today(app: App): Promise { + let today = moment().format("YYYY-MM-DD"); + return today; +} + +async function templater_tomorrow(app: App): Promise { + let tomorrow = moment().add(1,'days').format("YYYY-MM-DD"); + return tomorrow; +} + +async function templater_yesterday(app: App): Promise { + let yesterday = moment().add(-1, 'days').format("YYYY-MM-DD"); + return yesterday; +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index d148fe0c..3c9152fc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,6 +9,7 @@ "noImplicitAny": true, "moduleResolution": "node", "importHelpers": true, + "allowSyntheticDefaultImports": true, "lib": [ "dom", "es5",