Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
harmtemolder committed Sep 26, 2024
2 parents ac9c02a + b7b03cf commit 499b971
Show file tree
Hide file tree
Showing 63 changed files with 3,872 additions and 1,325 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
gh-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install mdbook
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: denolib/setup-deno@v2
with:
deno-version: v1.x
Expand Down
271 changes: 271 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ A list of useful resources about [Templater](https://github.com/SilentVoid13/Tem
- @GitMurf quick demo `How to setup and run your first Templater JS script`: https://github.com/SilentVoid13/Templater/discussions/187
- @shabegom `How To Use Templater JS Scripts`: https://shbgm.ca/blog/obsidian/how-to-use-templater-js-scripts
- @chhoumann Templates showcase: https://github.com/chhoumann/Templater_Templates
- @zachatoo Templates showcase: https://zachyoung.dev/posts/templater-snippets
- @lguenth Templates showcase: https://github.com/lguenth/obsidian-templates
- @tallguyjenks video: https://youtu.be/2234DXKbNgM?t=1944
- @ProductivityGuru videos: https://www.youtube.com/watch?v=cSawi0tYPMM

Expand All @@ -44,7 +46,7 @@ You can create an [issue](https://github.com/SilentVoid13/Templater/issues) to r

You can make a [pull request](https://github.com/SilentVoid13/Templater/pulls) to contribute to this plugin development.

Check [this](https://silentvoid13.github.io/Templater/docs/internal-variables-functions/contribute) to get more information on how to develop a new internal variable / function.
Check [this](https://silentvoid13.github.io/Templater/internal-functions/contribute.html) to get more information on how to develop a new internal variable / function.

## License

Expand Down
472 changes: 388 additions & 84 deletions docs/documentation.toml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [tp.date](./internal-functions/internal-modules/date-module.md)
- [tp.file](./internal-functions/internal-modules/file-module.md)
- [tp.frontmatter](./internal-functions/internal-modules/frontmatter-module.md)
- [tp.hooks](./internal-functions/internal-modules/hooks-module.md)
- [tp.obsidian](./internal-functions/internal-modules/obsidian-module.md)
- [tp.system](./internal-functions/internal-modules/system-module.md)
- [tp.web](./internal-functions/internal-modules/web-module.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/src/commands/dynamic-command.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is useful for internal functions like `tp.file.last_modified_date` for exam
Last modified date: <%+ tp.file.last_modified_date() %>
```

**Note**: Dynamic commands have known issues, and will likely not be maintained going forward (see [this issue](https://github.com/SilentVoid13/Templater/issues/913) for more details). In most cases the [Dataview](https://github.com/blacksmithgu/obsidian-dataview) plugin is the suggested alternative.

## Refresh problems

One "downside" of the preview mode is that it puts the rendered note in cache, to speed things up.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/commands/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Command Types

[Templater](https://github.com/SilentVoid13/Templater) defines 3 types of opening tags, that defines 3 types of **commands**:
[Templater](https://github.com/SilentVoid13/Templater) defines 2 types of opening tags, that defines 2 types of **commands**:

- `<%`: Interpolation command. It will output the result of the expression that's inside.
- `<%*`: [JavaScript execution command](./execution-command.md). It will execute the JavaScript code that's inside. It does not output anything by default.
Expand All @@ -11,7 +11,7 @@ The closing tag for a command is always the same: `%>`

## Command utilities

In addition to the 3 different types of commands, you can also use command utilities. They are also declared in the opening tag of the command, and they work with all the command types. Available command utilities are:
In addition to the different types of commands, you can also use command utilities. They are also declared in the opening tag of the command. All command utilities work with all command types. The available command utilities are:

- [Whitespace Control](./whitespace-control.md)
- [Dynamic Commands](./dynamic-command.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

You can install this plugin via the Community Plugins tab within Obsidian. Search for "Templater".

It's a good practice to restart the obsidian app after the installation of [Templater](https://github.com/SilentVoid13/Templater), to make sure everything is working properly.
It's a good practice to restart the Obsidian app after the installation of [Templater](https://github.com/SilentVoid13/Templater), to make sure everything is working properly.
2 changes: 1 addition & 1 deletion docs/src/internal-functions/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class InternalModuleDate extends InternalModule {

Every module extends the [InternalModule](https://github.com/SilentVoid13/Templater/blob/master/src/InternalTemplates/InternalModule.ts) abstract class, which means they contain the following attributes and methods:

- `this.app` attribute: the obsidian API `App` object.
- `this.app` attribute: the Obsidian API `App` object.
- `this.file` attribute: The destination file where the template will be inserted.
- `this.plugin` attribute: The Templater plugin object.
- `this.static_templates` attribute: A map containing all (name; variable/function) that are static. A static variable / function means that it doesn't depend on the file when executed. These type of variables / functions won't be updated each time we insert a new template, to save some overhead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{% if fn.args %}
##### Arguments

{% for key, arg in fn.args %}
{% for arg in fn.args %}
- `{{ arg.name }}`: {{ arg.description }}
{% endfor %}
{% endif %}
Expand Down
53 changes: 26 additions & 27 deletions docs/src/internal-functions/internal-modules/date-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Documentation

Function documentation is using a specific syntax. More information [here](../../syntax.md#function-documentation-syntax)
Function documentation is using a specific syntax. More information [here](../../syntax.md#function-documentation-syntax).

{%- for key, fn in tp.date.functions %}
### `{{ fn.definition }}`
Expand All @@ -16,16 +16,19 @@ Function documentation is using a specific syntax. More information [here](../..
{% if fn.args %}
##### Arguments

{% for key, arg in fn.args %}
{% for arg in fn.args %}
- `{{ arg.name }}`: {{ arg.description }}
{% endfor %}
{% endif %}

{% if fn.example %}
##### Example
{% if fn.examples %}
##### Examples

```
{{ fn.example }}
```javascript
{% for example in fn.examples -%}
// {{ example.name}}
{{ example.example }}
{% endfor -%}
```
{% endif %}
{%- endfor %}
Expand All @@ -34,30 +37,26 @@ Function documentation is using a specific syntax. More information [here](../..

Templater gives you access to the `moment` object, with all of its functionalities.

More information on moment.js [here](https://momentjs.com/docs/#/displaying/)
More information on moment.js [here](https://momentjs.com/docs/#/displaying/).

## Examples
{% if tp.date.momentjs.examples %}
##### Examples

```javascript
Date now: <% tp.date.now() %>
Date now with format: <% tp.date.now("Do MMMM YYYY") %>

Last week: <% tp.date.now("dddd Do MMMM YYYY", -7) %>
Today: <% tp.date.now("dddd Do MMMM YYYY, ddd") %>
Next week: <% tp.date.now("dddd Do MMMM YYYY", 7) %>

Last month: <% tp.date.now("YYYY-MM-DD", "P-1M") %>
Next year: <% tp.date.now("YYYY-MM-DD", "P1Y") %>

File's title date + 1 day (tomorrow): <% tp.date.now("YYYY-MM-DD", 1, tp.file.title, "YYYY-MM-DD") %>
File's title date - 1 day (yesterday): <% tp.date.now("YYYY-MM-DD", -1, tp.file.title, "YYYY-MM-DD") %>

Date tomorrow with format: <% tp.date.tomorrow("Do MMMM YYYY") %>
{% for example in tp.date.momentjs.examples -%}
// {{ example.name}}
{{ example.example }}
{% endfor -%}
```
{% endif %}

This week's monday: <% tp.date.weekday("YYYY-MM-DD", 0) %>
Next monday: <% tp.date.weekday("YYYY-MM-DD", 7) %>
File's title monday: <% tp.date.weekday("YYYY-MM-DD", 0, tp.file.title, "YYYY-MM-DD") %>
File's title next monday: <% tp.date.weekday("YYYY-MM-DD", 7, tp.file.title, "YYYY-MM-DD") %>
## Examples

Date yesterday with format: <% tp.date.yesterday("Do MMMM YYYY") %>
```javascript
{%- for key, fn in tp.date.functions %}
{% for example in fn.examples -%}
// {{ example.name}}
{{ example.example }}
{% endfor -%}
{%- endfor %}
```
62 changes: 16 additions & 46 deletions docs/src/internal-functions/internal-modules/file-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Documentation

Function documentation is using a specific syntax. More information [here](../../syntax.md#function-documentation-syntax)
Function documentation is using a specific syntax. More information [here](../../syntax.md#function-documentation-syntax).


{%- for key, fn in tp.file.functions %}
Expand All @@ -17,60 +17,30 @@ Function documentation is using a specific syntax. More information [here](../..
{% if fn.args %}
##### Arguments

{% for key, arg in fn.args %}
{% for arg in fn.args %}
- `{{ arg.name }}`: {{ arg.description }}
{% endfor %}
{% endif %}

{% if fn.example %}
##### Example
{% if fn.examples %}
##### Examples

```
{{ fn.example }}
```javascript
{% for example in fn.examples -%}
// {{ example.name}}
{{ example.example }}
{% endfor -%}
```
{% endif %}
{%- endfor %}

## Examples

```javascript
File content: <% tp.file.content %>

File creation date: <% tp.file.creation_date() %>
File creation date with format: <% tp.file.creation_date("dddd Do MMMM YYYY HH:mm") %>

File creation: [[<% (await tp.file.create_new("MyFileContent", "MyFilename")).basename %>]]

File cursor: <% tp.file.cursor(1) %>

File cursor append: <% tp.file.cursor_append("Some text") %>

File existence: <% await tp.file.exists("MyFolder/MyFile.md") %>
File existence of current file: <% await tp.file.exists(tp.file.folder(true)+"/"+tp.file.title+".md") %>

File find TFile: <% tp.file.find_tfile("MyFile").basename %>

File Folder: <% tp.file.folder() %>
File Folder with relative path: <% tp.file.folder(true) %>

File Include: <% tp.file.include("[[Template1]]") %>

File Last Modif Date: <% tp.file.last_modified_date() %>
File Last Modif Date with format: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm") %>

File Move: <% await tp.file.move("/A/B/" + tp.file.title) %>
File Move + Rename: <% await tp.file.move("/A/B/NewTitle") %>

File Path: <% tp.file.path() %>
File Path with relative path: <% tp.file.path(true) %>

File Rename: <% await tp.file.rename("MyNewName") %>
Append a "2": <% await tp.file.rename(tp.file.title + "2") %>

File Selection: <% tp.file.selection() %>

File tags: <% tp.file.tags %>

File title: <% tp.file.title %>
Strip the Zettelkasten ID of title (if space separated): <% tp.file.title.split(" ")[1] %>
```
{%- for key, fn in tp.file.functions %}
{% for example in fn.examples -%}
// {{ example.name}}
{{ example.example }}
{% endfor -%}
{%- endfor %}
```
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,18 @@ Then you can use the following template:
````
File's metadata alias: <% tp.frontmatter.alias %>
Note's type: <% tp.frontmatter["note type"] %>
````
````

For lists in frontmatter, you can use JavaScript array prototype methods to manipulate how the data is displayed.

```
---
categories:
- book
- movie
---
```

```
<% tp.frontmatter.categories.map(prop => ` - "${prop}"`).join("\n") %>
```
44 changes: 44 additions & 0 deletions docs/src/internal-functions/internal-modules/hooks-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Hooks Module

{{ tp.hooks.description }}

<!-- toc -->

## Documentation

Function documentation is using a specific syntax. More information [here](../../syntax.md#function-documentation-syntax).


{%- for key, fn in tp.hooks.functions %}
### `{{ fn.definition }}`

{{ fn.description }}

{% if fn.args %}
##### Arguments

{% for arg in fn.args %}
- `{{ arg.name }}`: {{ arg.description }}
{% endfor %}
{% endif %}
{%- endfor %}

## Examples

```javascript
// Update frontmatter after template finishes executing
<%*
tp.hooks.on_all_templates_executed(async () => {
const file = tp.file.find_tfile(tp.file.path(true));
await app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key"] = "value";
});
});
%>
// Run a command from another plugin that modifies the current file, after Templater has updated the file
<%*
tp.hooks.on_all_templates_executed(() => {
app.commands.executeCommandById("obsidian-linter:lint-file");
});
-%>
```
24 changes: 23 additions & 1 deletion docs/src/internal-functions/internal-modules/obsidian-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,27 @@

This is mostly useful when writing scripts.

Refer to the obsidian API [declaration file](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts) for more information.
Refer to the Obsidian API [declaration file](https://github.com/obsidianmd/obsidian-api/blob/master/obsidian.d.ts) for more information.

## Examples

```javascript
// Get all folders
<%
app.vault.getAllLoadedFiles()
.filter(x => x instanceof tp.obsidian.TFolder)
.map(x => x.name)
%>

// Normalize path
<% tp.obsidian.normalizePath("Path/to/file.md") %>

// Html to markdown
<% tp.obsidian.htmlToMarkdown("\<h1>Heading\</h1>\<p>Paragraph\</p>") %>

// HTTP request
<%*
const response = await tp.obsidian.requestUrl("https://jsonplaceholder.typicode.com/todos/1");
tR += response.json.title;
%>
```
Loading

0 comments on commit 499b971

Please sign in to comment.