Skip to content

Commit

Permalink
Adding new templater_random_picture internal plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentVoid13 committed Nov 8, 2020
1 parent 4c1eef4 commit 7e8ff3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ Now, you can start creating some template files that contains your template patt

### 3. Use your template files

Now you can click on the **Templater** icon located on the left-side bar. You can now choose your template file created in **step 2**. It will then automatically replace all the template patterns with the corresponding output.
Now you can click on the **Templater** icon located on the left-side ribbon. You can now choose your template file created in **step 2**. It will then automatically replace all the template patterns with the corresponding output.

## Internal Templates

Here is the list of all of the internal templates that are already included in this plugin. All internal templates patterns are prefixed with the keyword `templater_` to avoid disruption with user defined templates.

I invite all developers to contribute to this plugin development by adding new internal templates. (Check [INTERNAL_TEMPLATES](INTERNAL_TEMPLATES.md) for more informations).

| Internal Template | Description | Example Output |
| --------------------------- | ------------------------------------------------------------ | -------------------------------------------------------- |
| `{{templater_daily_quote}}` | This templates retrieves and parse the daily quote from the API https://quotes.rest/. | ![templater_daily_quote](imgs/templater_daily_quote.png) |
| Internal Template | Description | Example Output |
| ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| `{{templater_daily_quote}}` | This template retrieves and parse the daily quote from the API https://quotes.rest/. | ![templater_daily_quote](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)` |

## User Configuration example

Expand Down
10 changes: 10 additions & 0 deletions src/internal_templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import axios from 'axios';
// Just add them here to add your internal template to the plugin.
export const internal_templates_map: {[id: string]: Function} = {
"{{templater_daily_quote}}": templater_daily_quote,
"{{templater_random_picture}}": templater_random_picture,
};

export async function replace_internal_templates(content: string) {
Expand All @@ -31,4 +32,13 @@ async function templater_daily_quote() {

let new_content = `> ${quote}\n> &mdash; <cite>${author}</cite>`;
return new_content;
}

async function templater_random_picture() {
console.log("HERE");
let response = await axios.get("https://source.unsplash.com/random");
let url = response.request.responseURL;

let new_content = `![random_image](${url})`
return new_content;
}

0 comments on commit 7e8ff3e

Please sign in to comment.