Skip to content

Commit

Permalink
updated outlinks section to inclued transclusion links
Browse files Browse the repository at this point in the history
  • Loading branch information
jparkerweb committed Nov 24, 2024
1 parent bf4a0c5 commit 202c487
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to Rich Foot will be documented in this file.


## [1.6.2] - 2024-11-23

### Updated
- outlinks section to inclued transclusion links (example `[[note#section]]` or `[text](note#section)`)

## [1.6.1] - 2024-11-14

### 🐛 Fixed
Expand Down
4 changes: 4 additions & 0 deletions UPDATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 🎉 What's New

### v1.6.2
#### Updated
- outlinks section to inclued transclusion links (example `[[note#section]]` or `[text](note#section)`)

### v1.6.1
#### Fixed
- Fixed console error when switching between reading/editing modes
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "rich-foot",
"name": "Rich Foot",
"version": "1.6.1",
"minAppVersion": "1.6.0",
"minAppVersion": "1.6.1",
"description": "Adds backlink tags and created/modified dates to the footer of your notes.",
"author": "Justin Parker",
"authorUrl": "https://www.jparkerweb.com",
Expand Down
37 changes: 35 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,9 @@ class RichFootPlugin extends Plugin {
// Check regular links in content
if (cache?.links) {
for (const link of cache.links) {
const targetFile = this.app.metadataCache.getFirstLinkpathDest(link.link, file.path);
// Handle both standard links and links with section references
const linkPath = link.link.split('#')[0]; // Remove section reference if present
const targetFile = this.app.metadataCache.getFirstLinkpathDest(linkPath, file.path);
if (targetFile && targetFile.extension === 'md') {
links.add(targetFile.path);
}
Expand All @@ -399,14 +401,45 @@ class RichFootPlugin extends Plugin {
for (const link of frontmatterLinks) {
const linkText = link.match(/\[\[(.*?)\]\]/)?.[1];
if (linkText) {
const targetFile = this.app.metadataCache.getFirstLinkpathDest(linkText, file.path);
const linkPath = linkText.split('#')[0]; // Remove section reference if present
const targetFile = this.app.metadataCache.getFirstLinkpathDest(linkPath, file.path);
if (targetFile && targetFile.extension === 'md') {
links.add(targetFile.path);
}
}
}
}
}

// Check embeds/transclusions
if (cache?.embeds) {
for (const embed of cache.embeds) {
const filePath = embed.link.split('#')[0];
const targetFile = this.app.metadataCache.getFirstLinkpathDest(filePath, file.path);
if (targetFile && targetFile.extension === 'md') {
links.add(targetFile.path);
}
}
}

// Check for data-href links in the rendered content
if (cache?.sections) {
for (const section of cache.sections) {
if (section.type === 'paragraph') {
const matches = section.text?.match(/\[.*?\]\((.*?)(?:#.*?)?\)/g) || [];
for (const match of matches) {
const linkPath = match.match(/\[.*?\]\((.*?)(?:#.*?)?\)/)?.[1];
if (linkPath) {
const cleanPath = linkPath.split('#')[0]; // Remove section reference if present
const targetFile = this.app.metadataCache.getFirstLinkpathDest(cleanPath, file.path);
if (targetFile && targetFile.extension === 'md') {
links.add(targetFile.path);
}
}
}
}
}
}

return links;
}
Expand Down

0 comments on commit 202c487

Please sign in to comment.