319 |
320 |
321 | ignore_cert: true
322 | convert_markdown: true
323 | priority: normal
324 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # #
2 | # Ignore everything
3 | # #
4 |
5 | /*
6 |
7 | # #
8 | # [WL]: Git Base Folders/Files
9 | # #
10 |
11 | !/.github
12 | !/.gitea
13 | !*README.md
14 | !*CHANGELOG.md
15 | !*CONTRIBUTE.md
16 | !*CONTRIBUTING.md
17 |
18 | # #
19 | # [WL]: Electron
20 | # #
21 |
22 | !/electron
23 |
24 | # #
25 | # [WL]: Test Folder
26 | # #
27 |
28 | !/Tests
29 |
30 | # #
31 | # [WL]: Manifest Folders
32 | # #
33 |
34 | !/Manifest
35 |
36 | # #
37 | # [WL]: Tools Folders
38 | # #
39 |
40 | !/Tools
41 |
42 | # #
43 | # [WL]: Dist
44 | # #
45 |
46 | !/dist
47 |
48 | # #
49 | # [WL]: assets
50 | # #
51 |
52 | !/assets
53 |
54 | # #
55 | # [WL]: Gitignore File
56 | # #
57 |
58 | !.gitignore
59 |
60 | # #
61 | # [WL]: Docs Folder
62 | # #
63 |
64 | !/docs
65 |
66 | # #
67 | # [WL]: Source Folder
68 | # #
69 |
70 | !/src
71 |
72 | # #
73 | # [WL]: Dist Folder
74 | # #
75 |
76 | !/dist
77 |
78 | # #
79 | # [WL]: Base Files
80 | # #
81 |
82 | !*.all-contributorsrc
83 | !*.editorconfig
84 | !*gistr.js
85 | !*manifest.json
86 | !*package.json
87 | !*package-lock.json
88 | !*rollup.config.js
89 | !*rollup.config.mjs
90 | !*tsconfig.json
91 | !*versions.json
92 | !sign.bat
93 | !*SHA*.asc
94 | !*SHA*.sig
95 | !*styles.css
96 | !*eslint.config.js
97 | !*.prettierignore
98 | !*.prettierrc
99 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | .all-contributorsrc
2 | .github
3 | .gitea
4 | CONTRIBUTING
5 | CONTRIBUTING.md
6 | README
7 | README.md
8 | LICENSE
9 | node_modules
10 | coverage
11 | dist
12 | tests
13 | docs
14 | manifest.json
15 | tsconfig.json
16 | styles.css
17 | rollup.config.mjs
18 |
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | #
2 | # Try prettier's new ternary formatting before it becomes the
3 | # default behavior.
4 | #
5 | # only in prettier v3.x
6 | #
7 | # Moves the ? in multiline ternaries to the end of the first line
8 | # instead of the start of the second, along with several related
9 | # changes.
10 | #
11 | # @default : false
12 | # @ref : https://prettier.io/docs/en/options.html
13 | # https://prettier.io/docs/en/options.html#experimental-ternaries
14 | # https://github.com/prettier/prettier/pull/13183
15 | # #
16 |
17 | # experimentalTernaries: false
18 |
19 | # #
20 | # Specify the line length that the printer will wrap on.
21 | #
22 | # @default : 80
23 | # @ref : https://prettier.io/docs/en/options.html#print-width
24 | # #
25 |
26 | printWidth: 120
27 |
28 | # #
29 | # Specify the number of spaces per indentation-level.
30 | #
31 | # @default : 2
32 | # @ref : https://prettier.io/docs/en/options.html#tab-width
33 | # #
34 |
35 | tabWidth: 4
36 |
37 | # #
38 | # Indent lines with tabs instead of spaces.
39 | #
40 | # @default : false
41 | # @ref : https://prettier.io/docs/en/options.html#tabs
42 | # #
43 |
44 | useTabs: false
45 |
46 | # #
47 | # Print semicolons at the ends of statements.
48 | #
49 | # true : Add a semicolon at the end of every statement.
50 | # false : Only add semicolons at the beginning of lines that
51 | # may introduce ASI failures.
52 | #
53 | # @default : true
54 | # @ref : https://prettier.io/docs/en/options.html#semicolons
55 | # #
56 |
57 | semi: false
58 |
59 | # #
60 | # Use single quotes instead of double quotes.
61 | #
62 | # @default : false
63 | # @ref : https://prettier.io/docs/en/options.html#quotes
64 | # #
65 |
66 | singleQuote: true
67 |
68 | # #
69 | # Change when properties in objects are quoted.
70 | #
71 | # "as-needed" : Only add quotes around object properties where required.
72 | # "consistent" : If at least one property in an object requires quotes, quote all properties.
73 | # "preserve" : Respect the input use of quotes in object properties.
74 | #
75 | #
76 | # @default : "as-needed"
77 | # @ref : https://prettier.io/docs/en/options.html#quote-props
78 | # #
79 |
80 | quoteProps: 'preserve'
81 |
82 | # #
83 | # Use single quotes instead of double quotes in JSX.
84 | #
85 | # @default : false
86 | # @ref : https://prettier.io/docs/en/options.html#jsx-quotes
87 | # #
88 |
89 | jsxSingleQuote: true
90 |
91 | # #
92 | # Print trailing commas wherever possible in multi-line comma-separated
93 | # syntactic structures.
94 | #
95 | # (A single-line array, for example, never gets trailing commas.)
96 | #
97 | # Default value changed from es5 to all in v3.0.0
98 | #
99 | # "all" : Trailing commas wherever possible (including
100 | # function parameters and calls). To run, JavaScript
101 | # code formatted this way needs an engine that
102 | # supports ES2017 (Node.js 8+ or a modern browser)
103 | # or downlevel compilation. This also enables
104 | # trailing commas in type parameters in TypeScript
105 | # (supported since TypeScript 2.7 released in January 2018).
106 | #
107 | # "es5" : Trailing commas where valid in ES5 (objects, arrays, etc.).
108 | #
109 | # Trailing commas in type parameters in TypeScript and Flow.
110 | # "none" : No trailing commas.
111 | #
112 | #
113 | # @default : "all"
114 | # @ref : https://prettier.io/docs/en/options.html#trailing-commas
115 | # #
116 |
117 | trailingComma: none
118 |
119 | # #
120 | # Print spaces between brackets in object literals.
121 | #
122 | # true : Example: { foo: bar }.
123 | # false : Example: {foo: bar}.
124 | #
125 | # @default : true
126 | # @ref : https://prettier.io/docs/en/options.html#bracket-spacing
127 | # #
128 |
129 | bracketSpacing: true
130 |
131 | # #
132 | # Put the > of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the
133 | # last line instead of being alone on the next line (does not apply to self closing
134 | # elements).
135 | #
136 | # true : Example:
137 | #
138 | #
144 | #
145 | # false : Example:
146 | #
147 | #
154 | #
155 | # @default : false
156 | # @ref : https://prettier.io/docs/en/options.html#bracket-line
157 | # #
158 |
159 | bracketSameLine: false
160 |
161 | # #
162 | # Include parentheses around a sole arrow function parameter.
163 | #
164 | # First available in v1.9.0, default value changed from avoid to always in v2.0.0
165 | #
166 | # "always" : Always include parens. Example: (x) => x
167 | # "avoid" : Omit parens when possible. Example: x => x
168 | #
169 | #
170 | # @default : "always"
171 | # @ref : https://prettier.io/docs/en/options.html#arrow-function-parentheses
172 | # #
173 |
174 | arrowParens: always
175 |
176 | # #
177 | # By default, Prettier will not change wrapping in markdown text since some services
178 | # use a linebreak-sensitive renderer, e.g. GitHub comments and BitBucket. To have
179 | # Prettier wrap prose to the print width, change this option to "always". If you want
180 | # Prettier to force all prose blocks to be on a single line and rely on editor/viewer
181 | # soft wrapping instead, you can use "never".
182 | #
183 | # First available in v1.8.2
184 | #
185 | # "always" : Wrap prose if it exceeds the print width.
186 | # "never" : Un-wrap each block of prose into one line.
187 | # "preserve" : Do nothing, leave prose as-is. First available in v1.9.0
188 | #
189 | #
190 | # @default : "preserve"
191 | # @ref : https://prettier.io/docs/en/options.html#prose-wrap
192 | # #
193 |
194 | proseWrap: 'preserve'
195 |
196 | # #
197 | # Specify the global whitespace sensitivity for HTML, Vue, Angular, and Handlebars.
198 | # See whitespace-sensitive formatting for more info.
199 | #
200 | # First available in v1.15.0. First available for Handlebars in 2.3.0
201 | #
202 | # "css" : Respect the default value of CSS display property.
203 | # For Handlebars treated same as strict.
204 | # "strict" : Whitespace (or the lack of it) around all tags is considered significant.
205 | # "ignore" : Whitespace (or the lack of it) around all tags is considered insignificant.
206 | #
207 | #
208 | # @default : "css"
209 | # @ref : https://prettier.io/docs/en/options.html#html-whitespace-sensitivity
210 | # https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting
211 | # #
212 |
213 | htmlWhitespaceSensitivity: 'ignore'
214 |
215 | # #
216 | # For historical reasons, there exist two common flavors of line endings in text
217 | # files. That is:
218 | # - \n (or LF for Line Feed)
219 | # - \r\n (or CRLF for Carriage Return + Line Feed).
220 | #
221 | # The former is common on Linux and macOS, while the latter is prevalent on Windows.
222 | # Some details explaining why it is so can be found on Wikipedia.
223 | #
224 | # When people collaborate on a project from different operating systems, it becomes
225 | # easy to end up with mixed line endings in a shared git repository. It is also possible
226 | # for Windows users to accidentally change line endings in a previously committed file
227 | # from LF to CRLF. Doing so produces a large git diff and thus makes the line-by-line
228 | # history for a file (git blame) harder to explore.
229 | #
230 | # All modern text editors in all operating systems are able to correctly display line
231 | # endings when \n (LF) is used. However, old versions of Notepad for Windows will visually
232 | # squash such lines into one as they can only deal with \r\n (CRLF).
233 | #
234 | # First available in v1.15.0, default value changed from auto to lf in v2.0.0
235 | #
236 | # "lf" : Line Feed only (\n), common on Linux and macOS as well as inside git repos
237 | # "crlf" : Carriage Return + Line Feed characters (\r\n), common on Windows
238 | # "cr" : Carriage Return character only (\r), used very rarely
239 | # "auto" : Maintain existing line endings (mixed values within one file are normalised
240 | # by looking at what’s used after the first line)
241 | #
242 | # @default : "lf"
243 | # @ref : https://prettier.io/docs/en/options.html#end-of-line
244 | # #
245 |
246 | endOfLine: 'auto'
247 |
248 | # #
249 | # Control whether Prettier formats quoted code embedded in the file.
250 | #
251 | # When Prettier identifies cases where it looks like you've placed some code it knows
252 | # how to format within a string in another file, like in a tagged template in
253 | # JavaScript with a tag named html or in code blocks in Markdown, it will by default try
254 | # to format that code.
255 | #
256 | # Sometimes this behavior is undesirable, particularly in cases where you might not have
257 | # intended the string to be interpreted as code. This option allows you to switch between
258 | # the default behavior (auto) and disabling this feature entirely (off).
259 | #
260 | # First available in v2.1.0
261 | #
262 | # "auto" : Format embedded code if Prettier can automatically identify it.
263 | # "off" : Never automatically format embedded code.
264 | #
265 | # @default : "auto"
266 | # @ref : https://prettier.io/docs/en/options.html#embedded-language-formatting
267 | # #
268 |
269 | embeddedLanguageFormatting: 'auto'
270 |
271 | # #
272 | # Enforce single attribute per line in HTML, Vue and JSX.
273 | #
274 | # true : Enforce single attribute per line.
275 | # false : Do not enforce single attribute per line.
276 | #
277 | # @default : false
278 | # @ref : https://prettier.io/docs/en/options.html#single-attribute-per-line
279 | # #
280 |
281 | singleAttributePerLine: false
282 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 Aetherinox
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
Dataview Snippets
3 |
⭕ Obsidian Snippet Collection ⭕
4 |
5 |
6 |
7 |
A collection of dataview scripts which can be utilized within your Obsidian.md notes to perform various tasks and display data.
26 |
27 |
28 |
29 | ---
30 |
31 |
32 |
33 | - [About](#about)
34 | - [Snippets](#snippets)
35 | - [Table of Contents: Version 1](#table-of-contents-version-1)
36 | - [Table of Contents: Version 2](#table-of-contents-version-2)
37 | - [Subfolder Data](#subfolder-data)
38 | - [Bad Links: Version 1](#bad-links-version-1)
39 | - [Tag Cloud: Version 1](#tag-cloud-version-1)
40 | - [Tag Cloud: Version 2](#tag-cloud-version-2)
41 | - [Page Cloud: Version 1](#page-cloud-version-1)
42 | - [Alphabetized List: Version 1](#alphabetized-list-version-1)
43 | - [Contributors ✨](#contributors-)
44 |
45 |
46 |
47 | ---
48 |
49 |
50 |
51 | ## About
52 | This repo originally started a single **Table of Contents** script which displays at the top of your obsidian note. However, numerous other scripts have been added since then.
53 |
54 | The snippets in this repo require you to download and install the following:
55 | - [Obsidian.md](obsidian.md/)
56 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
57 |
58 |
59 |
60 | ---
61 |
62 |
63 |
64 | ## Snippets
65 | The following snippets are available in this repo
66 |
67 |
68 |
69 | ### Table of Contents: Version 1
70 |
71 |
72 |
73 | 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.
74 |
75 |
76 |
77 | For this version, you will need to create a new **Folder Note** using the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes), and then paste the provided code at the top of the new folder note.
78 |
79 |
80 |
81 | This version requires you to install the following:
82 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
83 | - [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)
84 |
85 |
86 |
87 |
98 |
99 | ### Table of Contents: Version 2
100 |
101 |
102 |
103 | 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.
104 |
105 |
106 |
107 | To use this snippet, paste the provided table of contents code at the top of a regular Obsidian note. It will fetch all of the headers which exist on that same page and display them in an unordered list at the top.
108 |
109 |
110 |
111 | This version requires you to install the following:
112 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
113 |
114 |
115 |
116 |
131 |
132 | The `Subfolder Data` snippet displays a table of contents listing based on a specified subfolder. This is useful if you want to pull a list of headers which exist on a page that is not associated to the current folder you are working in.
133 |
134 | The other snippets above also support subpages, but this one is a bit more customized for subfolder management.
135 |
136 |
137 |
138 | This version **requires** you to install the following:
139 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
140 |
141 | The following plugins are **optional**:
142 | - [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)
143 |
144 |
145 |
146 |
161 |
162 | The `Bad Links: Version 1` snippet displays a list of internal links within your vault that lead nowhere (are broken).
163 |
164 | To fix these, you can delete the link on the associated page, or you can click each item in the list and create a new page. Once the link has been fixed, it will be removed from the list.
165 |
166 |
167 |
168 | This version **requires** you to install the following:
169 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
170 |
171 |
172 |
173 |
188 |
189 | The `Tag Cloud: Version 1` snippet fetches a list of tags associated to your vault and displays them in a series of columns.
190 |
191 | Each tag can be clicked on, which will open the Search interface and display all other pages associated to the selected tag.
192 |
193 | The functionality of `Version 1` and `Version 2` are the same. Both just have difference appearances.
194 |
195 |
196 |
197 |
198 | This version **requires** you to install the following:
199 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
200 |
201 |
202 |
203 |
218 |
219 | The `Tag Cloud: Version 2` snippet fetches a list of tags associated to your vault and displays them in a series of columns.
220 |
221 | Each tag can be clicked on, which will open the Search interface and display all other pages associated to the selected tag.
222 |
223 | The functionality of `Version 1` and `Version 2` are the same. Both just have difference appearances.
224 |
225 |
226 |
227 | This version **requires** you to install the following:
228 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
229 |
230 |
231 |
232 |
247 |
248 | The `Page Cloud: Version 1` snippet fetches a list of pages within your vault and displays them in a cloud structure.
249 |
250 | Each page can be clicked on which will re-direct you to that particular page. Page titles also support the frontmatter values:
251 | - name
252 | - title
253 | - alias
254 |
255 | The functionality of `Version 1` and `Version 2` are the same. Both just have difference appearances.
256 |
257 |
258 |
259 | This version **requires** you to install the following:
260 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
261 |
262 |
263 |
264 |
279 |
280 | The `Alphabetized List: Version 1` snippet fetches a list of pages within your vault and displays them in a alphabetized list.
281 |
282 | Each page can be clicked on which will re-direct you to that particular page. Page titles also support the frontmatter values:
283 | - name
284 | - title
285 | - alias
286 |
287 |
288 |
289 | This version **requires** you to install the following:
290 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
291 |
292 |
293 |
294 |
299 |
300 |
301 |
302 | ---
303 |
304 |
305 |
306 | ## Contributors ✨
307 | We are always looking for contributors. If you feel that you can provide something useful to Gistr, then we'd love to review your suggestion. Before submitting your contribution, please review the following resources:
308 |
309 | - [Pull Request Procedure](.github/PULL_REQUEST_TEMPLATE.md)
310 | - [Contributor Policy](CONTRIBUTING.md)
311 |
312 |
313 |
314 | Want to help but can't write code?
315 | - Review [active questions by our community](https://github.com/Aetherinox/obsidian-dataview-snippets/labels/help%20wanted) and answer the ones you know.
316 |
317 |
318 |
319 | The following people have helped get this project going:
320 |
321 |
322 |
323 |
7 |
8 | ## About
9 | The `Subfolder Data` snippet displays a table of contents listing based on a specified subfolder. This is useful if you want to pull a list of headers which exist on a page that is not associated to the current folder you are working in.
10 |
11 |
12 |
13 | At the time of writing this script, I am using the following:
14 |
15 | | Software | Version |
16 | | --- | --- |
17 | | [Obsidian.md](https://obsidian.md/) |  |
18 | | [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |  |
19 | | [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes) |  |
20 |
21 |
22 |
23 | ### Previews
24 | The following are preview images of what the snippet will do and appear like:
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | ---
35 |
36 |
37 |
38 | ## Usage
39 |
40 | - Install [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
41 | - Install [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes) *(if wanting to use notes*)
42 | - Copy the code below and paste it in a note.
43 |
44 |
45 |
46 | ````shell
47 | ```dataviewjs
48 | /*
49 | Table of Contents Script > Version 3
50 |
51 | This version allows for pulling subfolder notes to
52 | another table of contents page.
53 |
54 | Excludes any subfolder table of contents pages
55 | labeled FOLDERNAME/FOLDERNAME.md
56 |
57 | Change "General" to the subpage you are wanting to target
58 | */
59 |
60 | const path_sub = "General"
61 |
62 | let count = 0;
63 | const path_base = dv.current().file.path
64 | const path_targ = path_base.substr(0, path_base.lastIndexOf("/"));
65 | const path_fnote_excl = path_sub + ".md"
66 | const filter_page = '"' + path_targ + "/" + path_sub + '"';
67 | const filter_folder = path_targ + "/" + path_sub;
68 |
69 | let p = dv.pages(filter_page)
70 | .where(p => p.file.name != dv.current().file.name) // Filter out the current page
71 | .where(p => p.file.folder == filter_folder) // Filter out folders
72 | .where(p => !p.file.path.endsWith(path_fnote_excl) ) // Filter folder note index
73 | .sort(p => p.file.path)
74 | .forEach(p =>
75 | {
76 | dv.header(4, p.file.name); // display page name as header
77 | const cache = this.app.metadataCache.getCache(p.file.path);
78 |
79 | if (cache)
80 | {
81 | const headings = cache.headings; // get headings from cache
82 |
83 | if (headings)
84 | {
85 | const houtput = headings.slice(1) // exclude the first heading
86 | .filter(h => h.level <= 6)
87 | .map(h =>
88 | {
89 | var file_head = h.heading
90 | var header_skip = file_head.replace(/ /g,"_").toLowerCase();
91 | if (header_skip === "table_of_contents" || header_skip === "toc")
92 | {
93 | return ""
94 | }
95 |
96 | count++;
97 |
98 | // Determine indentation based on heading level
99 | let indent = " ".repeat(h.level);
100 | var file_name = p.file.name;
101 |
102 | // remove backticks and tag symbols
103 | var file_head = file_head.replace(/`/g, '');
104 | var file_head = file_head.replace(/#/g, '');
105 | var file_title = h.heading.split('#')[0];
106 |
107 | let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
108 |
109 | if ( h.level == 1 )
110 | return indent + "- " + objLink + "";
111 | else if ( h.level == 2 )
112 | return indent + " - " + objLink + "";
113 | else if ( h.level == 3 )
114 | return indent + " - " + objLink + "";
115 | else if ( h.level == 4 )
116 | return indent + " - " + objLink + "";
117 | else if ( h.level == 5 )
118 | return indent + " - " + objLink + "";
119 | else if ( h.level == 6 )
120 | return indent + " - " + objLink + "";
121 | else
122 | return indent + "- " + objLink;
123 | })
124 | .join("\n")
125 |
126 | dv.el("div", houtput);
127 | dv.el("div", " ");
128 | }
129 | }
130 | });
131 |
132 | /*
133 | display NO RESULTS
134 | */
135 |
136 | if (count === 0)
137 | {
138 | const rootNode = dv.el("div", "No results", { cls: "toc_results_none" });
139 | rootNode.setAttribute("style", "text-align:center;");
140 | }
141 | ```
142 | ````
143 |
144 |
145 |
146 | Ensure you change the path to the **subfolder** you want to target:
147 |
148 | ```javascript
149 | const path_sub = "General"
150 | ```
151 |
152 |
153 |
154 | In the screenshot example, I changed it `Plugins` because the Plugins folder is a subfolder of what I wanted to target and build a table of contents from. You can use an entirely different path to whatever folder you want to generate a list of headers from.
155 |
156 | ```javascript
157 | const path_sub = "Plugins"
158 | ```
159 |
160 |
161 |
162 | Next, you need to add some custom CSS.
163 | Open Obsidian Settings, click **Appearance**, and then scroll all the way down. (See image below).
164 |
165 | Click the mini folder icon to open your **Obsidian Snippets folder**.
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 | Create a new file named whatever (`toc.css` in our example).
174 |
175 | Copy the code below and paste it into the new `toc.css` file which should be in `YourVaultName/.obsidian/snippets/toc.css`
176 |
177 |
178 |
179 |
252 |
253 |
254 |
255 | You should see a table of contents which is populated with the headings of your subfolders.
--------------------------------------------------------------------------------
/Snippets/Subfolder Data/images/example_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/Subfolder Data/images/example_1.gif
--------------------------------------------------------------------------------
/Snippets/Subfolder Data/images/install_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/Subfolder Data/images/install_1.gif
--------------------------------------------------------------------------------
/Snippets/Subfolder Data/images/install_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/Subfolder Data/images/install_2.png
--------------------------------------------------------------------------------
/Snippets/Subfolder Data/images/install_3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/Subfolder Data/images/install_3.gif
--------------------------------------------------------------------------------
/Snippets/Subfolder Data/snippet-version3:
--------------------------------------------------------------------------------
1 | ```dataviewjs
2 | /*
3 | Table of Contents Script > Version 3
4 |
5 | This version allows for pulling subfolder notes to
6 | another table of contents page.
7 |
8 | Excludes any subfolder table of contents pages
9 | labeled FOLDERNAME/FOLDERNAME.md
10 |
11 | change "General" to the subpage you are wanting to target
12 | */
13 |
14 | const path_sub = "General"
15 |
16 | let count = 0;
17 | const path_base = dv.current().file.path
18 | const path_targ = path_base.substr(0, path_base.lastIndexOf("/"));
19 | const path_fnote_excl = path_sub + ".md"
20 | const filter_page = '"' + path_targ + "/" + path_sub + '"';
21 | const filter_folder = path_targ + "/" + path_sub;
22 |
23 | let p = dv.pages(filter_page)
24 | .where(p => p.file.name != dv.current().file.name) // Filter out the current page
25 | .where(p => p.file.folder == filter_folder) // Filter out folders
26 | .where(p => !p.file.path.endsWith(path_fnote_excl) ) // Filter folder note index
27 | .sort(p => p.file.path)
28 | .forEach(p =>
29 | {
30 | dv.header(4, p.file.name); // display page name as header
31 | const cache = this.app.metadataCache.getCache(p.file.path);
32 |
33 | if (cache)
34 | {
35 | const headings = cache.headings; // get headings from cache
36 |
37 | if (headings)
38 | {
39 | const houtput = headings.slice(1) // exclude the first heading
40 | .filter(h => h.level <= 6)
41 | .map(h =>
42 | {
43 | count++;
44 |
45 | // Determine indentation based on heading level
46 | let indent = " ".repeat(h.level);
47 | var file_name = p.file.name;
48 |
49 | // remove backticks and tag symbols
50 | var file_head = h.heading
51 | var file_head = file_head.replace(/`/g, '');
52 | var file_head = file_head.replace(/#/g, '');
53 | var file_title = h.heading.split('#')[0];
54 |
55 | let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
56 |
57 | if ( h.level == 1 )
58 | return indent + "- " + objLink + "";
59 | else if ( h.level == 2 )
60 | return indent + " - " + objLink + "";
61 | else if ( h.level == 3 )
62 | return indent + " - " + objLink + "";
63 | else if ( h.level == 4 )
64 | return indent + " - " + objLink + "";
65 | else if ( h.level == 5 )
66 | return indent + " - " + objLink + "";
67 | else if ( h.level == 6 )
68 | return indent + " - " + objLink + "";
69 | else
70 | return indent + "- " + objLink;
71 | })
72 | .join("\n")
73 |
74 | dv.el("div", houtput);
75 | dv.el("div", " ");
76 | }
77 | }
78 | });
79 |
80 | /*
81 | display NO RESULTS
82 | */
83 |
84 | if (count === 0)
85 | {
86 | const rootNode = dv.el("div", "No results", { cls: "toc-results-none" });
87 | rootNode.setAttribute("style", "text-align:center;");
88 | }
89 | ```
--------------------------------------------------------------------------------
/Snippets/TOC Version 1/README.md:
--------------------------------------------------------------------------------
1 |
2 |
📃 Table of Contents: Version 1 📃
3 |
4 |
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.
5 |
6 |
7 |
8 |
9 |
10 | > [!NOTE]
11 | > Need a table of contents snippet which does **not** require the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)?
12 | >
13 | > Click here to install [Table of Contents: Version 2](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/TOC%20Version%202)
14 |
15 |
16 |
17 | ## About
18 |
19 | This snippet requires you to have:
20 | - [Obsidian.md](obsidian.md/)
21 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
22 | - [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)
23 |
24 |
25 |
26 | The code for this version should be pasted inside a **Folder Note**. It will fetch all of the files that exist inside that folder.
27 |
28 |
29 |
30 | At the time of writing this script, I am using the following:
31 |
32 | | Software | Version |
33 | | --- | --- |
34 | | [Obsidian.md](https://obsidian.md/) |  |
35 | | [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |  |
36 | | [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes) |  |
37 |
38 |
39 |
40 | ### Previews
41 | The following are preview images of what the snippet will do and appear like:
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 | ---
52 |
53 |
54 |
55 | ## Usage
56 |
57 | - Install [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
58 | - Install [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)
59 | - Right-click on a folder, select `Folder Note Commands` and select `Create Folder Note`
60 | - Copy the code below and paste in Obsidian folder note:
61 |
62 |
63 |
64 | ````javascript
65 | ```dataviewjs
66 |
67 | /*
68 | Table of Contents Script > Version 1
69 |
70 | This version requires the plugins:
71 | https://github.com/LostPaul/obsidian-folder-notes
72 | https://github.com/blacksmithgu/obsidian-dataview
73 |
74 | Create a new folder, right-click, and create folder note.
75 | Click inside the folder note and paste the code below.
76 |
77 | Inside that folder, place the files you want the table of
78 | contents to display. Make sure each file contains headers.
79 | */
80 |
81 | let count = 0;
82 | const path_base = dv.current().file.path
83 | const path_targ = path_base.substr(0, path_base.lastIndexOf("/"));
84 | const path_sub = ""
85 |
86 | const filter_page = '"' + path_targ + "" + path_sub + '"';
87 | const filter_folder = path_targ + path_sub;
88 |
89 | let p = dv.pages(filter_page)
90 | .where(p => p.file.name != dv.current().file.name) // Filter out the current page
91 | .where(p => p.file.folder == filter_folder) // Filter out folders
92 | .sort(p => p.file.path)
93 | .forEach(p =>
94 | {
95 | dv.header(4, p.file.name); // display page name as header
96 | const cache = this.app.metadataCache.getCache(p.file.path);
97 |
98 | if (cache)
99 | {
100 | const headings = cache.headings; // get headings from cache
101 |
102 | if ( typeof headings === 'undefined') {
103 | dv.el("div", '⭕ No Subheaders Found', { cls: "toc_results_none_subheader" });
104 | dv.el("div", " ");
105 | return;
106 | }
107 |
108 | if (headings)
109 | {
110 | const houtput = headings.slice(0) // exclude the first heading
111 | .filter(h => h.level <= 6)
112 | .map(h =>
113 | {
114 | let file_head = h.heading
115 | const header_skip = file_head.replace(/ /g,"_").toLowerCase();
116 | if (header_skip === "table_of_contents" || header_skip === "toc")
117 | {
118 | return ""
119 | }
120 |
121 | count++;
122 |
123 | // Determine indentation based on heading level
124 | let indent = " ".repeat(h.level);
125 | const file_name = p.file.name;
126 |
127 | // remove backticks and tag symbols
128 | file_head = file_head.replace(/`/g, '');
129 | file_head = file_head.replace(/#/g, '');
130 | const file_title = h.heading.split('#')[0];
131 |
132 | let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
133 |
134 | if ( h.level == 1 )
135 | return indent + "- " + objLink + "";
136 | else if ( h.level == 2 )
137 | return indent + " - " + objLink + "";
138 | else if ( h.level == 3 )
139 | return indent + " - " + objLink + "";
140 | else if ( h.level == 4 )
141 | return indent + " - " + objLink + "";
142 | else if ( h.level == 5 )
143 | return indent + " - " + objLink + "";
144 | else if ( h.level == 6 )
145 | return indent + " - " + objLink + "";
146 | else
147 | return 'No Result'
148 | })
149 | .join("\n")
150 |
151 | dv.el("div", houtput);
152 | dv.el("div", " ");
153 | }
154 | }
155 | });
156 |
157 | /*
158 | display NO RESULTS
159 | */
160 |
161 | if (count === 0)
162 | {
163 | const rootNode = dv.el("div", "No results", { cls: "toc_results_none" });
164 | rootNode.setAttribute("style", "text-align:center;");
165 | }
166 | ```
167 | ````
168 |
169 |
170 |
171 | If you want to target a subfolder / path, you can modify the variable `path_sub`. If you leave it blank, it will target the folder you paste the code in.
172 |
173 | ```javascript
174 | const path_sub = "Path/To/Subfolder"
175 | ```
176 |
177 |
178 |
179 | Next, you need to add some custom CSS.
180 | Open Obsidian Settings, click **Appearance**, and then scroll all the way down. (See image below).
181 |
182 | Click the mini folder icon to open your **Obsidian Snippets folder**.
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 | Create a new file named whatever (`toc.css` in our example).
191 |
192 | Copy the code below and paste it into the new `toc.css` file which should be in `YourVaultName/.obsidian/snippets/toc.css`
193 |
194 |
195 |
196 |
279 |
280 |
281 |
282 | You should see a table of contents which is populated with the headings of your subfolders.
283 |
284 |
285 |
286 | ---
287 |
288 |
289 |
290 | ## Customization
291 | ### How to make page title above the each list appear bigger
292 | In your code, locate
293 | ```javascript
294 | dv.header(4, p.file.name);
295 | ```
296 |
297 | The `4` stands for `H4` or header 4. To make the text bigger, change that number to `3 or lower`. Overall, it accepts any number between `1 - 6`, with 1 being the biggest and 6 being the smallest text size.
298 |
299 |
300 |
301 |
302 | ### Make each page title not display as a listed item
303 | Locate the code toward the top:
304 | ```javascript
305 | dv.header(4, p.file.name);
306 | ```
307 | and replace it with:
308 | ```javascript
309 | dv.el("div", p.file.name);
310 | ```
311 |
312 | This will force each page title to display in a `div` and not as header object.
313 |
314 |
315 |
316 |
317 | ### My list is cutting off the first header of each page
318 | Locate the following code:
319 | ```javascript
320 | const houtput = headings.slice(1)
321 | ```
322 |
323 | The number `1` represents how many headers on the page that should be excluded from the first going from the top down. If you enter the number `0`, then no headers will be filtered out / all will show in the list. If you enter `3`, then the first three headers of each page will not appear in the table of contents list.
324 |
325 | To disable any headers from being excluded in the list, change the code above to the following:
326 | ```javascript
327 | const houtput = headings.slice(0)
328 | ```
329 |
330 |
331 |
332 |
333 | ### Exclude certain headers from appearing in the list
334 | Much like the example above which allows you to filter from from the top, you can also filter exactly which headers display in the list with the following code:
335 | ```javascript
336 | .filter(h => h.level <= 6)
337 | ```
338 |
339 | The number `6` represents which headers will be included in the list. If you change the value to a `4`, that means any sections of your page with headers 5 or 6 will not show.
340 | ```
341 | ##### This is H5
342 | ###### This is H6
343 | ```
344 |
345 |
346 |
347 |
348 | ### Making the gap between each list smaller/bigger
349 | You need to modify the following:
350 | ```javascript
351 | dv.el("div", "
");
352 | ```
353 | Each ` ` is a line break. The more breaks you add, the larger the gap between each list. Remove each break to make the gap smaller.
354 |
355 |
356 |
--------------------------------------------------------------------------------
/Snippets/TOC Version 1/images/example_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/TOC Version 1/images/example_1.gif
--------------------------------------------------------------------------------
/Snippets/TOC Version 1/images/install_1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/TOC Version 1/images/install_1.gif
--------------------------------------------------------------------------------
/Snippets/TOC Version 1/images/install_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/TOC Version 1/images/install_2.png
--------------------------------------------------------------------------------
/Snippets/TOC Version 1/images/install_3.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/bf4bbc7cf4777909a2a0035db9f9f05ca2ddcd37/Snippets/TOC Version 1/images/install_3.gif
--------------------------------------------------------------------------------
/Snippets/TOC Version 2/README.md:
--------------------------------------------------------------------------------
1 |
2 |
📃 Table of Contents: Version 2 📃
3 |
4 |
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.
5 |
6 |
7 |
8 |
9 |
10 | > [!NOTE]
11 | > Want a table of contents which is compatible with the [Folder Notes Plugin](https://github.com/LostPaul/obsidian-folder-notes)?
12 | >
13 | > Click here to install [Table of Contents: Version 1](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/TOC%20Version%201)
14 |
15 |
16 |
17 | ## About
18 |
19 | This snippet requires you to have:
20 | - [Obsidian.md](obsidian.md/)
21 | - [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
22 |
23 |
24 |
25 | The code for this version should be pasted at the top of a note. It will fetch all of the headers that exist on that page and display them in an unordered list at the top.
26 |
27 |
28 |
29 | At the time of writing this script, I am using the following:
30 |
31 | | Software | Version |
32 | | --- | --- |
33 | | [Obsidian.md](https://obsidian.md/) |  |
34 | | [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |  |
35 |
36 |
37 |
38 | ### Previews
39 | The following are preview images of what the snippet will do and appear like:
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | ---
50 |
51 |
52 |
53 | ## Usage
54 |
55 | - Install [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
56 | - Copy the code below and paste it at the top of a note you want to display a list of headers for:
57 |
58 |
59 |
60 | ````javascript
61 | ```dataviewjs
62 |
63 | /*
64 | Table of Contents Script > Version 2
65 |
66 | Should be pasted at the top of the page to outline
67 | all of the headers you want to list on the same page
68 |
69 | For this script, "path_sub" should not be edited.
70 | */
71 |
72 | let count = 0;
73 | const path_base = dv.current().file.path
74 | const path_targ = path_base.substr(0, path_base.lastIndexOf(".md"));
75 | const path_sub = ""
76 |
77 | const filter_page = '"' + path_targ + "" + path_sub + '"';
78 | const filter_folder = path_targ + path_sub;
79 |
80 | let p = dv.pages(filter_page)
81 | .sort(p => p.file.path)
82 | .forEach(p =>
83 | {
84 | // dv.header(4, p.file.name); // display page name as header
85 | const cache = this.app.metadataCache.getCache(p.file.path);
86 |
87 | if (cache)
88 | {
89 | const headings = cache.headings; // get headings from cache
90 |
91 | if (headings)
92 | {
93 | const houtput = headings.slice(0) // exclude the first heading
94 | .filter(h => h.level <= 6)
95 | .map(h =>
96 | {
97 | let file_head = h.heading
98 | const header_skip = file_head.replace(/ /g,"_").toLowerCase();
99 | if (header_skip === "table_of_contents" || header_skip === "toc")
100 | {
101 | return ""
102 | }
103 |
104 | count++;
105 |
106 | // Determine indentation based on heading level
107 | let indent = " ".repeat(h.level);
108 | const file_name = p.file.name;
109 |
110 | // remove backticks and tag symbols
111 | file_head = file_head.replace(/`/g, '');
112 | file_head = file_head.replace(/#/g, '');
113 | const file_title = h.heading.split('#')[0];
114 |
115 | let objLink = "[[" + file_name + "#" + file_head + "|" + file_title + "]]";
116 |
117 | if ( h.level == 1 )
118 | return indent + "- " + objLink + "";
119 | else if ( h.level == 2 )
120 | return indent + " - " + objLink + "";
121 | else if ( h.level == 3 )
122 | return indent + " - " + objLink + "";
123 | else if ( h.level == 4 )
124 | return indent + " - " + objLink + "";
125 | else if ( h.level == 5 )
126 | return indent + " - " + objLink + "";
127 | else if ( h.level == 6 )
128 | return indent + " - " + objLink + "";
129 | else
130 | return indent + "- " + objLink;
131 | })
132 | .join("\n")
133 |
134 | dv.el("div", houtput);
135 | dv.el("div", " ");
136 | }
137 | }
138 | });
139 |
140 | /*
141 | display NO RESULTS
142 | */
143 |
144 | if (count === 0)
145 | {
146 | const rootNode = dv.el("div", "No results", { cls: "toc_results_none" });
147 | rootNode.setAttribute("style", "text-align:center;");
148 | }
149 | ```
150 | ````
151 |
152 |
153 |
154 | If you want to target a subfolder / path, you can modify the variable `path_sub`. If you leave it blank, it will target the folder you paste the code in.
155 |
156 | ```javascript
157 | const path_sub = "Path/To/Subfolder"
158 | ```
159 |
160 |
161 |
162 | Next, you need to add some custom CSS.
163 | Open Obsidian Settings, click **Appearance**, and then scroll all the way down. (See image below).
164 |
165 | Click the mini folder icon to open your **Obsidian Snippets folder**.
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 | Create a new file named whatever (`toc.css` in our example).
174 |
175 | Copy the code below and paste it into the new `toc.css` file which should be in `YourVaultName/.obsidian/snippets/toc.css`
176 |
177 |
178 |
179 |
252 |
253 |
254 |
255 | You should see a table of contents which is populated with the headings of your subfolders.
256 |
257 |
258 |
259 | ---
260 |
261 |
262 |
263 | ## Customization
264 | ### How to make page title above the each list appear bigger
265 | In your code, locate
266 | ```javascript
267 | dv.header(4, p.file.name);
268 | ```
269 |
270 | The `4` stands for `H4` or header 4. To make the text bigger, change that number to `3 or lower`. Overall, it accepts any number between `1 - 6`, with 1 being the biggest and 6 being the smallest text size.
271 |
272 |
273 |
274 |
275 | ### Make each page title not display as a listed item
276 | Locate the code toward the top:
277 | ```javascript
278 | dv.header(4, p.file.name);
279 | ```
280 | and replace it with:
281 | ```javascript
282 | dv.el("div", p.file.name);
283 | ```
284 |
285 | This will force each page title to display in a `div` and not as header object.
286 |
287 |
288 |
289 |
290 | ### My list is cutting off the first header of each page
291 | Locate the following code:
292 | ```javascript
293 | const houtput = headings.slice(1)
294 | ```
295 |
296 | The number `1` represents how many headers on the page that should be excluded from the first going from the top down. If you enter the number `0`, then no headers will be filtered out / all will show in the list. If you enter `3`, then the first three headers of each page will not appear in the table of contents list.
297 |
298 | To disable any headers from being excluded in the list, change the code above to the following:
299 | ```javascript
300 | const houtput = headings.slice(0)
301 | ```
302 |
303 |
304 |
305 |
306 | ### Exclude certain headers from appearing in the list
307 | Much like the example above which allows you to filter from from the top, you can also filter exactly which headers display in the list with the following code:
308 | ```javascript
309 | .filter(h => h.level <= 6)
310 | ```
311 |
312 | The number `6` represents which headers will be included in the list. If you change the value to a `4`, that means any sections of your page with headers 5 or 6 will not show.
313 | ```
314 | ##### This is H5
315 | ###### This is H6
316 | ```
317 |
318 |
319 |
320 |
321 | ### Making the gap between each list smaller/bigger
322 | You need to modify the following:
323 | ```javascript
324 | dv.el("div", "