Skip to content

Commit 470b35b

Browse files
committed
change: update table of contents v2
1 parent efdad01 commit 470b35b

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

Snippets/TOC Version 1/README.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1-
# Obsidian: Table of Contents: Version 1
2-
This snippet requires a copy of [Obsidian.md](obsidian.md/)
1+
<div align="center">
2+
<h1>📃 Table of Contents: Version 1 📃</h1>
33
<br />
4-
This snippet requires the [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview).
4+
<p>A dataview script which displays a table of contents. It compiles a list of all your folder's current subpages and pulls the headers from each page to display in a simple and neat list.</p>
5+
56
<br />
6-
This snippet requires the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes).
77

8-
<br /><br />
8+
> [!NOTE]
9+
> Need a table of contents snippet which does **not** require the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)?
10+
>
11+
> Click here to install [Table of Contents: Version 2](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/TOC%20Version%202)
12+
13+
<br />
14+
15+
</div>
16+
17+
<br />
918

1019
## About
11-
The `Table of Contents: Version 1` snippet displays a table of contents. It compiles a list of all your folder's current subpages and pulls the headers from each page to display in a simple and neat list.
20+
21+
This snippet requires you to have:
22+
- [Obsidian.md](obsidian.md/)
23+
- [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
24+
- [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)
1225

1326
<br />
1427

Snippets/TOC Version 2/README.md

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
# Obsidian: Table of Contents: Version 2
2-
This snippet requires a copy of [Obsidian.md](obsidian.md/)
1+
<div align="center">
2+
<h1>📃 Table of Contents: Version 2 📃</h1>
33
<br />
4-
This snippet requires the [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview).
4+
<p>A dataview script which displays a table of contents. The code within this page should be pasted at the top of your Obsidian note which contains headers and subheaders. It will populate a list of all the headers and show them in a list.</p>
55

6-
<br /><br />
6+
<br />
7+
8+
> [!NOTE]
9+
> Want a table of contents which is compatible with the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)?
10+
>
11+
> Click here to install [Table of Contents: Version 1](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/TOC%20Version%201)
12+
13+
<br />
14+
15+
</div>
16+
17+
<br />
718

819
## About
9-
The `Table of Contents: Version 2` snippet displays a table of contents. It compiles a list of all your folder's current subpages and pulls the headers from each page to display in a simple and neat list.
20+
21+
This snippet requires you to have:
22+
- [Obsidian.md](obsidian.md/)
23+
- [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
1024

1125
<br />
1226

@@ -82,8 +96,8 @@ let p = dv.pages(filter_page)
8296
.filter(h => h.level <= 6)
8397
.map(h =>
8498
{
85-
var file_head = h.heading
86-
var header_skip = file_head.replace(/ /g,"_").toLowerCase();
99+
let file_head = h.heading
100+
const header_skip = file_head.replace(/ /g,"_").toLowerCase();
87101
if (header_skip === "table_of_contents" || header_skip === "toc")
88102
{
89103
return ""
@@ -92,15 +106,15 @@ let p = dv.pages(filter_page)
92106
count++;
93107
94108
// Determine indentation based on heading level
95-
let indent = " ".repeat(h.level);
96-
var file_name = p.file.name;
109+
let indent = " ".repeat(h.level);
110+
const file_name = p.file.name;
97111
98112
// remove backticks and tag symbols
99-
var file_head = file_head.replace(/`/g, '');
100-
var file_head = file_head.replace(/#/g, '');
101-
var file_title = h.heading.split('#')[0];
113+
file_head = file_head.replace(/`/g, '');
114+
file_head = file_head.replace(/#/g, '');
115+
const file_title = h.heading.split('#')[0];
102116

103-
let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
117+
let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
104118

105119
if ( h.level == 1 )
106120
return indent + "- " + objLink + "";
@@ -170,7 +184,7 @@ Copy the code below and paste it into the new `toc.css` file which should be in
170184

171185
```css
172186
/*
173-
Snippet: Table of Contents
187+
Snippet: Table of Contents > v2
174188
*/
175189

176190
/*

0 commit comments

Comments
 (0)