mirror of
https://github.com/h-sphere/sql-seal.git
synced 2026-07-22 10:10:28 +00:00
Merge pull request #108 from kDCYorke/feature/frontmatterLinks
feat: Add frontmatter links to the links table
This commit is contained in:
commit
fba988511c
2 changed files with 60 additions and 22 deletions
|
|
@ -56,3 +56,28 @@ Introduced in 0.20.0
|
|||
| `position` | JSON object containing information about location of the link |
|
||||
| `display_text` | Text displayed on the page for that link |
|
||||
| `target_exists` | information if the target file exists. 1 if it exists, 0 otherwise |
|
||||
|
||||
|
||||
#### Frontmatter links
|
||||
|
||||
Links that appear in a file's frontmatter (Obsidian properties) contain a `frontmatterKey` property in the `position`
|
||||
JSON object. This can be used to identify links that are in the note body or within a specific frontmatter property.
|
||||
|
||||
For instance, to query all links to the current file that appear in the body of a note:
|
||||
|
||||
```sql
|
||||
SELECT * FROM links
|
||||
WHERE target = @path
|
||||
AND json_extract(position, '$.frontmatterKey') IS NULL
|
||||
```
|
||||
|
||||
`frontmatterKey` can be used to select links within a specific property. A Map of Content, for instance, may wish to
|
||||
show a list of files that list the MOC as a type:
|
||||
|
||||
```sql
|
||||
LIST
|
||||
SELECT a(path) FROM links
|
||||
WHERE target = @path
|
||||
AND json_extract(position, '$.frontmatterKey') = 'type'
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { TFile } from "obsidian";
|
||||
import { FrontmatterLinkCache, LinkCache, TFile } from "obsidian";
|
||||
import { AFileSyncTable } from "./abstractFileSyncTable";
|
||||
|
||||
export class LinksFileSyncTable extends AFileSyncTable {
|
||||
|
|
@ -26,26 +26,39 @@ export class LinksFileSyncTable extends AFileSyncTable {
|
|||
if (!cache) {
|
||||
return []
|
||||
}
|
||||
const tags = cache.links
|
||||
if (!tags) {
|
||||
return []
|
||||
}
|
||||
return tags.map((t) => {
|
||||
const targetFile = this.app.metadataCache.getFirstLinkpathDest(t.link, file.path)
|
||||
let targetExists = false
|
||||
let target = t.link
|
||||
if (targetFile) {
|
||||
target = targetFile.path
|
||||
targetExists = true
|
||||
}
|
||||
return {
|
||||
path: file.path,
|
||||
target: target,
|
||||
position: t.position,
|
||||
display_text: t.displayText,
|
||||
target_exists: targetExists
|
||||
}
|
||||
})
|
||||
|
||||
const links: any[] = (cache.links || []).map((l: LinkCache) => {
|
||||
return {
|
||||
targetLink: l.link,
|
||||
position: l.position,
|
||||
display_text: l.displayText
|
||||
}
|
||||
});
|
||||
|
||||
const frontmatterLinks: any[] = (cache.frontmatterLinks || []).map((l: FrontmatterLinkCache) => {
|
||||
return {
|
||||
targetLink: l.link,
|
||||
position: { frontmatterKey: l.key },
|
||||
display_text: l.displayText
|
||||
}
|
||||
});
|
||||
|
||||
return links.concat(frontmatterLinks).map(({ targetLink, ...reference }) => {
|
||||
const targetFile = this.app.metadataCache.getFirstLinkpathDest(targetLink, file.path)
|
||||
let targetExists = false
|
||||
let target = targetLink
|
||||
if (targetFile) {
|
||||
target = targetFile.path
|
||||
targetExists = true
|
||||
}
|
||||
|
||||
return {
|
||||
path: file.path,
|
||||
target: target,
|
||||
...reference,
|
||||
target_exists: targetExists
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -59,4 +72,4 @@ export class LinksFileSyncTable extends AFileSyncTable {
|
|||
this.db.createIndex(`links_${column}_idx`, this.tableName, [column])
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue