|
| 1 | +# Obsidian: Alphabetized List - Version 1 <!-- omit from toc --> |
| 2 | +- This snippet requires the program [Obsidian.md](obsidian.md/) |
| 3 | +- This snippet requires the [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |
| 4 | +- This snippet has optional support for [Style Settings Plugin](https://github.com/mgmeyers/obsidian-style-settings) |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +<br /> |
| 9 | + |
| 10 | +## Table of Contents <!-- omit from toc --> |
| 11 | + |
| 12 | +- [About](#about) |
| 13 | + - [Previews](#previews) |
| 14 | +- [Install](#install) |
| 15 | + - [Javascript](#javascript) |
| 16 | + - [Normal Version](#normal-version) |
| 17 | + - [Minified Version](#minified-version) |
| 18 | + - [CSS](#css) |
| 19 | +- [Customization](#customization) |
| 20 | + - [Page Titles / Frontmatter Support](#page-titles--frontmatter-support) |
| 21 | + - [Change Appearance / CSS](#change-appearance--css) |
| 22 | + |
| 23 | +<br /> |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +<br /><br /> |
| 28 | + |
| 29 | +## About |
| 30 | +The `Alphabetized List - Version 1` snippet fetches a list of every page which exists in your vault, and automatically sorts them in a A, B, C collapsible structure. |
| 31 | + |
| 32 | +<br /> |
| 33 | + |
| 34 | +Each letter of the alphabet is clickable, and displays a list of pages in your vault starting with that letter. |
| 35 | + |
| 36 | +<br /> |
| 37 | + |
| 38 | +This snippet supports `Frontmatter` values for page names. For more information on this, view the customization section: [Page Titles / Frontmatter Support](#page-titles--frontmatter-support). |
| 39 | + |
| 40 | +<br /> |
| 41 | + |
| 42 | +At the time of writing this script, I am using the following: |
| 43 | + |
| 44 | +| Software | Version | |
| 45 | +| --- | --- | |
| 46 | +| [Obsidian.md](https://obsidian.md/) |  | |
| 47 | +| [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |  | |
| 48 | + |
| 49 | + |
| 50 | +<br /><br /> |
| 51 | + |
| 52 | +<div align="center"> |
| 53 | + |
| 54 | +**[`^ back to top ^`](#table-of-contents-)** |
| 55 | + |
| 56 | +</div> |
| 57 | + |
| 58 | +<br /><br /> |
| 59 | + |
| 60 | +--- |
| 61 | + |
| 62 | +<br /><br /> |
| 63 | + |
| 64 | +### Previews |
| 65 | +The following are preview images of what the snippet will do and appear like: |
| 66 | + |
| 67 | +<br /> |
| 68 | + |
| 69 | +<p align="center"><img style="width: 80%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Bad%20Links%201/images/example_1.gif"></p> |
| 70 | + |
| 71 | +<br /><br /> |
| 72 | + |
| 73 | +<div align="center"> |
| 74 | + |
| 75 | +**[`^ back to top ^`](#table-of-contents-)** |
| 76 | + |
| 77 | +</div> |
| 78 | + |
| 79 | +<br /><br /> |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +<br /><br /> |
| 84 | + |
| 85 | +## Install |
| 86 | + |
| 87 | +- Install [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview) |
| 88 | +- View the [Javascript](#javascript) section below, and copy the [Normal](#normal-version) or [Minified](#minified-version) version of the code and paste it into your Obsidian note. |
| 89 | +- View the [CSS](#css) section below, and copy the provided CSS, then create a new `.css` snippet and paste the copied code. |
| 90 | +- Enable the new CSS snippet in your `Obsidian Settings` under `Appearance`. |
| 91 | +- More detailed instructions below. |
| 92 | + |
| 93 | +<br /><br /> |
| 94 | + |
| 95 | +### Javascript |
| 96 | +Pick **One** of the versions below. |
| 97 | +<small>The features are the same, just the code is structured differently.</small> |
| 98 | +1. [Normal Version](#normal-version)<br /><small>Much easier to read the code</small> |
| 99 | +2. [Minified Version](#minified-version)<br /><small>Much easier to paste</small> |
| 100 | + |
| 101 | +<br /> |
| 102 | + |
| 103 | +#### Normal Version |
| 104 | +This version is much easier to read the code. It includes formatting and comments. |
| 105 | + |
| 106 | +<br /> |
| 107 | + |
| 108 | +````shell |
| 109 | +```dataviewjs |
| 110 | +dv.container.className += ' atx-alv1-dataview' |
| 111 | +
|
| 112 | +let arrABC = []; |
| 113 | +let arrPages = dv.pages( "" ) |
| 114 | +.forEach( p => |
| 115 | +{ |
| 116 | + const file = p.file |
| 117 | + const file_path = file.path; |
| 118 | + const file_name = file.name; |
| 119 | + const file_label = file.frontmatter.name || file.frontmatter.title || file.frontmatter.alias || file_name; |
| 120 | +
|
| 121 | + const letter = file_label.charAt( 0 ).toUpperCase( ); |
| 122 | + let index = arrABC.findIndex( ( item ) => item.name === letter ); |
| 123 | +
|
| 124 | + if ( index === -1 ) |
| 125 | + arrABC.push( { name: letter, pages: [ { name: file_name, label: file_label, path: file_path } ] } ); |
| 126 | + else |
| 127 | + { |
| 128 | + var item = arrABC.find( item => item.name == letter ); |
| 129 | + let arr = item.pages; |
| 130 | +
|
| 131 | + arr.push( { name: file_name, label: file_label, path: file_path } ); |
| 132 | + } |
| 133 | +
|
| 134 | + arrABC.sort( ( a, b ) => a.name.localeCompare( b.name ) ) |
| 135 | +}); |
| 136 | +
|
| 137 | +var sethtml = ""; |
| 138 | +
|
| 139 | +dv.list( |
| 140 | + dv.array( arrABC ) |
| 141 | + .forEach( obj => |
| 142 | + { |
| 143 | + const arrPages = obj.pages; |
| 144 | +
|
| 145 | + sethtml += "\n<details><summary>" + obj.name + "</summary>\n\n"; |
| 146 | +
|
| 147 | + Promise.all( arrPages.map( async ( pages ) => |
| 148 | + { |
| 149 | + const page_path = pages.path; |
| 150 | + const page_name = pages.name; |
| 151 | + const page_label = pages.label; |
| 152 | +
|
| 153 | + const file_link = dv.fileLink( page_path, false, page_label ); |
| 154 | + |
| 155 | + sethtml += "- " + file_link + "\n"; |
| 156 | + } |
| 157 | + )); |
| 158 | +
|
| 159 | + sethtml += "</details>\n"; |
| 160 | +
|
| 161 | + }) |
| 162 | +
|
| 163 | +) |
| 164 | +
|
| 165 | +const divClose = dv.el( 'div', sethtml, { container: dv.container, cls: 'atx-alv1-s' } ); |
| 166 | +
|
| 167 | +``` |
| 168 | +```` |
| 169 | +
|
| 170 | +<br /> |
| 171 | +
|
| 172 | +#### Minified Version |
| 173 | +This version only formats the settings. All other formatting and comments are removed. |
| 174 | +
|
| 175 | +<br /> |
| 176 | +
|
| 177 | +````shell |
| 178 | +```dataviewjs |
| 179 | + Not Available Yet |
| 180 | +``` |
| 181 | +```` |
| 182 | +
|
| 183 | +<br /><br /> |
| 184 | +
|
| 185 | +<div align="center"> |
| 186 | +
|
| 187 | +**[`^ back to top ^`](#table-of-contents-)** |
| 188 | +
|
| 189 | +</div> |
| 190 | +
|
| 191 | +<br /><br /> |
| 192 | +
|
| 193 | +--- |
| 194 | +
|
| 195 | +<br /><br /> |
| 196 | +
|
| 197 | +### CSS |
| 198 | +Next, you need to add some custom CSS. |
| 199 | +Open Obsidian Settings, click **Appearance**, and then scroll all the way down. (See image below). |
| 200 | +
|
| 201 | +Click the mini folder icon to open your **Obsidian Snippets folder**. |
| 202 | +
|
| 203 | +<br /> |
| 204 | +
|
| 205 | +<p align="center"><img style="width: 70%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Bad%20Links%201/images/install_1.gif"></p> |
| 206 | +
|
| 207 | +<br /> |
| 208 | +
|
| 209 | +Create a new file named whatever (`badlinks_v1.css` in our example). |
| 210 | +
|
| 211 | +<br /> |
| 212 | +
|
| 213 | +<p align="center"><img style="width: 70%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Bad%20Links%201/images/install_2.png"></p> |
| 214 | +
|
| 215 | +<br /> |
| 216 | +
|
| 217 | +Copy the code below and paste it into the new `badlinks_v1.css` file which should be in `YourVaultName/.obsidian/snippets/badlinks_v1.css` |
| 218 | +
|
| 219 | +<br /> |
| 220 | +
|
| 221 | +```css |
| 222 | + Not Available Yet |
| 223 | +``` |
| 224 | +
|
| 225 | +<br /> |
| 226 | +<br /> |
| 227 | +
|
| 228 | +Save the file and go back to **Obsidian Settings** -> **Appearance**. Scroll all the way down and enable the checkbox to the right of `badlinks_v1.css`. |
| 229 | +
|
| 230 | +<br /> |
| 231 | +<br /> |
| 232 | +
|
| 233 | +<p align="center"><img style="width: 70%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Bad%20Links%201/images/install_3.gif"></p> |
| 234 | +
|
| 235 | +<br /> |
| 236 | +
|
| 237 | +You should see a list of pages associated to your vault. |
| 238 | +
|
| 239 | +<br /> |
| 240 | +
|
| 241 | +This snippet supports modifying the CSS values using the **[Style Settings](https://github.com/mgmeyers/obsidian-style-settings)** plugin. If you want to change how the tags in this snippet look: |
| 242 | +- Open `Obsidian Settings` |
| 243 | +- Install the `Style Settings` plugin |
| 244 | +- Select `Style Settings` config panel under `Community Plugins`. |
| 245 | +- Click the tab `Bad Links - Version 1` |
| 246 | +- Edit the settings for the Page Cloud tags |
| 247 | +
|
| 248 | +<br /> |
| 249 | +
|
| 250 | +<p align="center"><img style="width: 70%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Page%20Cloud%201/images/install_4.gif"></p> |
| 251 | +
|
| 252 | +<br /><br /> |
| 253 | +
|
| 254 | +<div align="center"> |
| 255 | +
|
| 256 | +**[`^ back to top ^`](#table-of-contents-)** |
| 257 | +
|
| 258 | +</div> |
| 259 | +
|
| 260 | +<br /><br /> |
| 261 | +
|
| 262 | +--- |
| 263 | +
|
| 264 | +<br /><br /> |
| 265 | +
|
| 266 | +## Customization |
| 267 | +The section below explains how to customize this snippet. |
| 268 | +
|
| 269 | +<br /> |
| 270 | +<br /> |
| 271 | +
|
| 272 | +### Page Titles / Frontmatter Support |
| 273 | +This script supports `Frontmatter` / `Metadata` titles. When one of your notes includes a broken link, the name of the note will display in the Bad Links snippet. The name of each page displayed has several ways of being defined, and supports **frontmatter**. |
| 274 | +
|
| 275 | +<br /> |
| 276 | +
|
| 277 | +The name that displays for each page will have the following priority: |
| 278 | +1. `frontmatter.name` |
| 279 | +2. `frontmatter.title` |
| 280 | +3. `frontmatter.alias` |
| 281 | +4. `filename.Name` |
| 282 | +
|
| 283 | +<br /> |
| 284 | +
|
| 285 | +If none of the above frontmatter values are specified, the normal file name of the page will be used. |
| 286 | +
|
| 287 | +<br /> |
| 288 | +
|
| 289 | +Based on the priority list above, if you provide both a frontmatter `name` AND `title`, the frontmatter **name** will be used first. |
| 290 | +
|
| 291 | +<br /> |
| 292 | +
|
| 293 | +If you provide a frontmatter `title` and frontmatter `alias`, then the frontmatter **title** will be used. |
| 294 | +
|
| 295 | +<br /> |
| 296 | +
|
| 297 | +To define frontmatter values, add the following to the very top of your page: |
| 298 | +
|
| 299 | +```markdown |
| 300 | +--- |
| 301 | +title: "Your Page Title" |
| 302 | +--- |
| 303 | +``` |
| 304 | +
|
| 305 | +<br /> |
| 306 | +
|
| 307 | +You cannot have any blank lines above the first `---`. |
| 308 | +
|
| 309 | +<br /> |
| 310 | +
|
| 311 | +If you do not specify `title`, `name`, or `alias` in your frontmatter, the normal page filename will be used. |
| 312 | +
|
| 313 | +<br /> |
| 314 | +<br /> |
| 315 | +
|
| 316 | +### Change Appearance / CSS |
| 317 | +This snippet supports tweaking the look and feel of the cloud & tags using the **[Style Settings](https://github.com/mgmeyers/obsidian-style-settings)** plugin. If you want to change how this snippet looks: |
| 318 | +- Open `Obsidian Settings` |
| 319 | +- Install the `Style Settings` plugin |
| 320 | +- Select `Style Settings` config panel under `Community Plugins`. |
| 321 | +- Click the tab `Bad Links - Version 1` |
| 322 | +- Edit the settings for the Page Cloud tags |
| 323 | +
|
| 324 | +<br /> |
| 325 | +
|
| 326 | +<p align="center"><img style="width: 70%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Bad%20Links%201/images/example_5.gif"></p> |
| 327 | +
|
| 328 | +<br /><br /> |
| 329 | +
|
| 330 | +<div align="center"> |
| 331 | +
|
| 332 | +**[`^ back to top ^`](#table-of-contents-)** |
| 333 | +
|
| 334 | +</div> |
| 335 | +
|
| 336 | +<br /><br /> |
0 commit comments