Skip to content

Commit

Permalink
Adding new internal_plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentVoid13 committed Nov 8, 2020
1 parent f10d9b5 commit 2c25d8a
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "templater-obsidian",
"version": "0.3.0",
"version": "0.3.1",
"description": "Create and use templates",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -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"
}
Expand Down
21 changes: 20 additions & 1 deletion src/internal_templates.ts
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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) {
Expand Down Expand Up @@ -50,3 +54,18 @@ async function templater_title(app: App): Promise<String> {
let activeLeaf = app.workspace.activeLeaf;
return activeLeaf.getDisplayText();
}

async function templater_today(app: App): Promise<String> {
let today = moment().format("YYYY-MM-DD");
return today;
}

async function templater_tomorrow(app: App): Promise<String> {
let tomorrow = moment().add(1,'days').format("YYYY-MM-DD");
return tomorrow;
}

async function templater_yesterday(app: App): Promise<String> {
let yesterday = moment().add(-1, 'days').format("YYYY-MM-DD");
return yesterday;
}
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"noImplicitAny": true,
"moduleResolution": "node",
"importHelpers": true,
"allowSyntheticDefaultImports": true,
"lib": [
"dom",
"es5",
Expand Down

0 comments on commit 2c25d8a

Please sign in to comment.