Skip to content

Commit

Permalink
Merge pull request #191 from SirSpidey/master
Browse files Browse the repository at this point in the history
Fix template table and update content
  • Loading branch information
akosbalasko authored Feb 1, 2021
2 parents 9bb5da4 + b53edfa commit 8fbde0c
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions Templates.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
# How to use templates with YARLE

You can control the Markdown output generated by YARLE by using templates like the one below, which is similar to YARLE's default template (which is located [here](./src/utils/templates/default-template.ts)):
You can control the Markdown output generated by YARLE by using a custom template file like the one below, which is similar to YARLE's [default template](./src/utils/templates/default-template.ts).

## Calling the template
To use a custom template with YARLE, include the `templateFile` parameter in your `config.json` file. For example,

To provide a template to YARLE just pass it as a parameter in `config.json`, e.g `templateFile: '/../path/to/template.md'`. You can use any file name/extension you want.
```json
"templateFile": "/absolute-path-to-your-template-dir/myTemplate.tmpl"
```

## Creating the template

A template has two basic elements, a "block" tag which encloses the type of content it will produce, and also the formatting you want around it (e.g. `#` for a header, or `---` for a separator), and the content tag itself such as `{tags}` and `{content}`. Every content tag must have its block surrounding it.
A custom template file can have any file name and extension.

If you suppress any of the blocks, it will be skipped altogether, for example if you want to have Markdown files with just the title and the main content, and you could use a template such as
- To include content, specify its block. A template block has two basic elements:
- A "block" tag that encloses the type of content it will produce and the formatting around the content (e.g. `#` for a header, or `---` for a separator).
- The "content" tag inside the block, such as `{tags}` and `{content}`. Every content tag must be surrounded by its block tags.

- To exclude a type of content, don't include that block. For example, to create Markdown files with only the title and the content, define a template with these blocks:

```
{title-block}# {title}{end-title-block}
{content-block}{content}{end-content-block}
```

The possible blocks are the followings:
### Available blocks

| Name | Block and content tags | Description |
|-|-|-|
| Title | `{title-block}{title}{end-title-block}` | Note title |
| Tags | `{tags-block}{tags}{end-tags-block}` | Note tags |
| Content | `{content-block}{content}{end-content-block}` | Note content |
| Date of creation | `{created-at-block}{created-at}{end-created-at-block}` | Creation date of the note |
| Last update | `{updated-at-block}{updated-at}{end-updated-at-block}` | Last updated date of the note |
| Source URL | `{source-url-block}{source-url}{end-source-url-block}` | Source URL from the EN metadata|
| Original Notebook Name | `{notebook-block}{notebook}{end-notebook-block}` | Name of the EN notebook where the note is stored |
| Link to the HTML file | `{link-to-original-block}{link-to-original}{end-link-to-original-block}` | Generate an HTML version of the note in the note's resource folder. A link to the HTML file is included here. |
| Location | `{location-block}{location}{end-location-block}` | The GPS coordinates of the location from the EN location details. |

| Name | Placeholder | Description | 
|------|-------------|-------------|
| Title | {title-block}{title}{end-title-block} | Adds title|
| Tags | {tags-block}{tags}{end-tags-block} | Tags block|
| Content | {content-block}{content}{end-content-block} | The actual content of the note|
| Date of creation | {created-at-block}{created-at}{end-created-at-block} | The creation date of the note|
| Last update | {updated-at-block}{updated-at}{end-updated-at-block}| Last update of the note|
| Source URL | {source-url-block}{source-url}{end-source-url-block} | The source URL|
| Original Notebook Name | {notebook-block}{notebook}{end-notebook-block}| Name of the EN notebook in where the note placed|
| Link to the HTML file | {link-to-original-block}{link-to-original}{end-link-to-original-block}| If it's set, then a HTML version of the note will be generated in the note's resource folder, and it will be referenced here|
| Location| {location-block}{location}{end-location-block} | The GPS coordinates of the location where the note has been taken |
## Example template:

## Example:
This example puts the note title at the top, preceded by `#`. The tags are listed next, surrounded by horizontal rules. The note content follows. Finally, the note's metadata is included, indented, at the bottom of the note. The output also includes an HTML version of the note, with a link to it in the Markdown file.

```
{title-block}# {title}{end-title-block}
Expand All @@ -47,11 +59,11 @@ Tag(s): {tags}
{updated-at-block} Updated at: {updated-at}{end-updated-at-block}
{source-url-block} Source: {source-url}{end-source-url-block}
{notebook-block} Notebook: {notebook}{end-notebook-block}
{location-block} Where: {location}{end-location-block}
{link-to-original-block} Link to original content: {link-to-original}{end-link-to-original-block}
{location-block} Where: {location}{end-location-block}
```

As a good base, your can edit sampleTemplate.tmpl, and refer to it in the config file's template file parameter.

As a starting point, you can edit the `sampleTemplate.tmpl` default template. Don't forget to specify the `templateFile` in your config file.

Have fun! 😃

0 comments on commit 8fbde0c

Please sign in to comment.