Skip to content

Commit 0d2c214

Browse files
committed
add detailed description for automatically add internal link
1 parent 2b5cc2a commit 0d2c214

File tree

6 files changed

+143
-21
lines changed

6 files changed

+143
-21
lines changed

README.md

+74-11
Original file line numberDiff line numberDiff line change
@@ -582,29 +582,92 @@ ea.optimize_image_attachments_to_webp('H2q3901uFDCH')
582582

583583
This action can save significant space if you have many clipped pages. Whoever invented `WebP` is a genius.
584584

585-
## (Advanced Usage) Automatically add internal link
585+
## (Advanced Usage) 🔗 Automatically Add Internal Links
586586

587-
Experimental feature. Backup your database before do anything with this feature. It may completely destroy your notes.
587+
This feature allows you to automatically create internal links within your notes. Let’s take a look at how it works.
588588

589-
If you find something wrong after using this feature. Please provide me a minimal note sample to test and fix potential
590-
bugs.
589+
### Example
591590

592-
Add internal link in note
591+
Here is a sample note:
593592

593+
![auto-link-1](docs/auto-link-1.webp)
594+
595+
After running a single line of code:
596+
597+
```python
598+
auto_create_internal_link('put_note_id_here')
594599
```
595-
auto_create_internal_link('HfAnsf8XiarY')
596-
```
597600

598-
For multiple notes
601+
The note transforms into this:
602+
603+
![auto-link-2](docs/auto-link-2.webp)
604+
605+
As you can see, some text has been replaced with internal links. The feature follows these rules:
606+
607+
- **Title Match**: Content that matches any other note's title is replaced with an internal link.
608+
- **Duplicate Titles Ignored**: If multiple notes share the same title, no link is created for that title.
609+
- **Longer Matches First**: Longer titles take precedence. For example, in the above example, "Nate River" is linked,
610+
not just "River."
611+
- **Existing Links Remain**: Pre-existing links in the text are left untouched.
612+
613+
However, some words like "make" and "work" in the example are part of my "English Words That I Do Not Know" note. Since
614+
they are common and frequently used, I don’t want them to create excessive internal links.
615+
616+
### Excluding Notes from Internal Linking
617+
618+
To prevent certain notes from being linked:
619+
620+
- Add the tag `#ignoreAutoInternalLink` to a note. This note (and optionally its sub-notes) will be excluded from link
621+
creation.
622+
- You can make it **inheritable**—you can apply it to a parent note and inheritable, then it will be automatically
623+
exclude all its sub-notes.
624+
625+
Here’s how it looks after applying the exclusion rule:
626+
627+
![auto-link-3](docs/auto-link-3.webp)
628+
629+
The result is cleaner and more intentional.
630+
631+
### Special Case: Duplicate Titles
632+
633+
When multiple notes share the same title, a specific condition allows for internal links:
599634

635+
- **Direct Sub-Notes Have Priority**: Direct child notes take precedence over other notes with the same title.
636+
637+
For instance:
638+
639+
![auto-link-4](docs/auto-link-4.webp)
640+
641+
In this case, the note `TriliumNext` links "How to compile" to its own child note, not the one from `Trilium`.
642+
643+
### Final Rule: No Self-Linking
644+
645+
A note will never create an internal link to itself.
646+
647+
---
648+
649+
### Code Samples
650+
651+
**Add an internal link to a specific note by its ID:**
652+
653+
```python
654+
auto_create_internal_link('gLmmsIM8yPqx')
600655
```
656+
657+
**Add internal links for multiple notes:**
658+
659+
```python
601660
auto_create_internal_link(target_notes=['gLmmsIM8yPqx', 'T4Ui3wNByO03'])
602661
```
603662

604-
(Dangerous action, backup first) Add internal notes for all text notes
663+
**(Experimental - Use with Caution)**
664+
**Add internal links to all text notes:**
605665

606-
```
607-
auto_create_internal_link(prcess_all_note=True)
666+
This is an experimental feature. **Backup your database** before using it, as it may irreversibly modify your notes. If
667+
issues occur, please provide a minimal note sample to help debug.
668+
669+
```python
670+
auto_create_internal_link(process_all_notes=True)
608671
```
609672

610673
## 🛠️ Develop

README_CN.md

+69-10
Original file line numberDiff line numberDiff line change
@@ -509,28 +509,87 @@ ea.optimize_image_attachments_to_webp('H2q3901uFDCH')
509509
如果你有很多剪辑的页面,这个操作可以节省大量空间。发明 `WebP` 的人真是个天才。
510510

511511

512-
## (高级用法)自动添加内部链接
512+
## (高级用法)🔗 自动添加内部链接
513513

514-
实验性功能。在使用此功能之前,请备份您的数据库。它可能会完全破坏您的笔记。
514+
此功能可以在笔记中自动创建内部链接。以下是使用示例:
515515

516-
如果在使用此功能后发现任何问题,请提供一个最小化的笔记示例,以便测试和修复潜在的错误。
516+
### 示例
517517

518-
在笔记中添加内部链接
518+
这是一个示例笔记
519519

520+
![auto-link-1](docs/auto-link-1.webp)
521+
522+
执行以下代码后:
523+
524+
```python
525+
auto_create_internal_link('put_note_id_here')
520526
```
521-
auto_create_internal_link('HfAnsf8XiarY')
522-
```
523527

524-
针对多个笔记:
528+
笔记变成这样:
529+
530+
![auto-link-2](docs/auto-link-2.webp)
531+
532+
可以看到,部分文本已被替换为内部链接。该功能遵循以下规则:
533+
534+
- **标题匹配**:与其他笔记标题匹配的内容会被替换为内部链接。
535+
- **重复标题忽略**:如果存在多个笔记使用相同标题,则不会为该标题创建链接。
536+
- **优先匹配较长标题**:较长的标题优先。例如,在上面的示例中,`Nate River` 被链接,而不是 `River`
537+
- **现有链接保留**:文本中已有的链接不会被修改。
538+
539+
然而,在示例中,像 "make" 和 "work" 这样的词属于我的笔记《我不认识的英语单词》。由于这些词短且常用,我不希望它们频繁生成内部链接。
540+
541+
### 排除特定笔记的内部链接
542+
543+
如果需要排除某些笔记的链接:
544+
545+
- 给这些笔记添加标签 `#ignoreAutoInternalLink`,这些笔记(及其子笔记)将在创建内部链接时被忽略。
546+
- 你可以设置为**可继承的**:为父笔记添加这个标签并设置为可继承的,其所有子笔记也会被自动排除。
547+
548+
应用排除规则后,效果如下:
549+
550+
![auto-link-3](docs/auto-link-3.webp)
551+
552+
结果更加简洁美观。
553+
554+
### 特殊情况:重复标题
555+
556+
当多个笔记共享相同标题时,以下情况可以生成内部链接:
525557

558+
- **直接子笔记优先**:直接子笔记的优先级高于其他拥有相同标题的笔记。
559+
560+
例如:
561+
562+
![auto-link-4](docs/auto-link-4.webp)
563+
564+
在此例中,笔记 `TriliumNext` 会将 "How to compile" 链接到自己的子笔记,而不是 `Trilium` 的同名笔记。
565+
566+
### 最后一条规则:避免自引用
567+
568+
笔记不会创建指向自身的内部链接。
569+
570+
---
571+
572+
### 代码示例
573+
574+
**为特定笔记添加内部链接(通过笔记 ID):**
575+
576+
```python
577+
auto_create_internal_link('gLmmsIM8yPqx')
526578
```
579+
580+
**为多个笔记添加内部链接:**
581+
582+
```python
527583
auto_create_internal_link(target_notes=['gLmmsIM8yPqx', 'T4Ui3wNByO03'])
528584
```
529585

530-
(危险操作,请先备份)为所有文本笔记添加内部链接:
586+
**(实验性功能 - 谨慎使用)**
587+
**为所有文本笔记添加内部链接:**
531588

532-
```
533-
auto_create_internal_link(process_all_note=True)
589+
这是一个实验性功能。在使用前请**备份数据库**,因为此操作可能会不可逆地修改您的笔记。如果使用后发现问题,请提供一个最小化的笔记样本以便调试。
590+
591+
```python
592+
auto_create_internal_link(process_all_notes=True)
534593
```
535594

536595

docs/auto-link-1.webp

97 KB
Binary file not shown.

docs/auto-link-2.webp

101 KB
Binary file not shown.

docs/auto-link-3.webp

95.8 KB
Binary file not shown.

docs/auto-link-4.webp

83 KB
Binary file not shown.

0 commit comments

Comments
 (0)