Merge pull request #107 from h-sphere/feat/template-expose-properties

feat: template can now access file properties
This commit is contained in:
Kacper Kula 2025-03-15 16:23:34 +00:00 committed by GitHub
commit 77a4f7109e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 19 additions and 6 deletions

View file

@ -1,3 +1,5 @@
# 0.28.4 (2025-03-15)
- Feat: Template view can now access file properties
# 0.28.3 (2025-03-15)
- Fix: Filename field in files column no longer truncates name after dot

View file

@ -6,9 +6,19 @@ Data from the query is exposed as `data` variable.
Learn more about handlebars syntax [in their official documentation](https://handlebarsjs.com/guide/).
## Variables
The following variables are exposed
| Variable | Description |
| ---------- | -------------------------------------------------- |
| data | Array of the data returned by the SELECT statement |
| columns | Array of column names |
| properties | Object containing all properties of the file |
## Example
```sql
TEMPLATE
Current Path: {{properties.path}}
{{#each data}}
<div>{{path}}</div>
{{/each}}

View file

@ -1,7 +1,7 @@
{
"id": "sqlseal",
"name": "SQLSeal",
"version": "0.28.3",
"version": "0.28.4",
"minAppVersion": "0.15.0",
"description": "Use SQL in your notes to query your vault files and CSV content.",
"author": "hypersphere",

View file

@ -1,6 +1,6 @@
{
"name": "sqlseal",
"version": "0.28.3",
"version": "0.28.4",
"description": "A plugin for Obsidian that allows you to run SQL queries on your notes.",
"main": "main.js",
"scripts": {

View file

@ -122,7 +122,7 @@ export class CodeblockProcessor extends MarkdownRenderChild {
}
const { data, columns } = await this.db.select(transformedQuery, variables)
this.renderer.render({ data, columns, flags: this.flags })
this.renderer.render({ data, columns, flags: this.flags, frontmatter: variables })
} catch (e) {
this.renderer.error(e.toString())
}

View file

@ -39,11 +39,11 @@ export class TemplateRenderer implements RendererConfig {
render(config: TemplateRendererConfig, el: HTMLElement) {
return {
render: ({ columns, data }: any) => {
render: ({ columns, data, frontmatter }: any) => {
el.empty()
// Seems to be the only way to render handlebars into DOM. Don't like it but what can we do.
el.innerHTML = config.template({ data, columns })
el.innerHTML = config.template({ data, columns, properties: frontmatter })
},
error: (error: string) => {
displayError(el, error)

View file

@ -52,5 +52,6 @@
"0.28.0": "0.15.0",
"0.28.1": "0.15.0",
"0.28.2": "0.15.0",
"0.28.3": "0.15.0"
"0.28.3": "0.15.0",
"0.28.4": "0.15.0"
}