Skip to content

Commit fbffacc

Browse files
committed
Update main readme
1 parent 0212eb0 commit fbffacc

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ These snippets in this repo require you to download and install [Obsidian.md](ob
1313
- [Tag Cloud: Version 1](#tag-cloud-version-1)
1414
- [Tag Cloud: Version 2](#tag-cloud-version-2)
1515
- [Page Cloud: Version 1](#page-cloud-version-1)
16+
- [Alphabetized List: Version 1](#alphabetized-list-version-1)
1617

1718

1819
<br /><br />
@@ -226,4 +227,34 @@ This version **requires** you to install the following:
226227

227228
[![View](https://img.shields.io/badge/%20-%20View%20Readme-%20%23de2343?style=for-the-badge&logo=github&logoColor=FFFFFF)](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/Page%20Cloud%201)
228229

230+
</div>
231+
232+
<br /><br />
233+
234+
---
235+
236+
<br /><br />
237+
238+
### Alphabetized List: Version 1
239+
240+
<p align="center"><img style="width: 100%;text-align: center;" src="https://raw.githubusercontent.com/Aetherinox/obsidian-dataview-snippets/main/Snippets/Alphabetized%20List%201/images/example_1.gif"></p>
241+
242+
The `Alphabetized List: Version 1` snippet fetches a list of pages within your vault and displays them in a alphabetized list.
243+
244+
Each page can be clicked on which will re-direct you to that particular page. Page titles also support the frontmatter values:
245+
- name
246+
- title
247+
- alias
248+
249+
<br />
250+
251+
This version **requires** you to install the following:
252+
- [Dataview Plugin](https://github.com/blacksmithgu/obsidian-dataview)
253+
254+
<br />
255+
256+
<div align="center">
257+
258+
[![View](https://img.shields.io/badge/%20-%20View%20Readme-%20%23de2343?style=for-the-badge&logo=github&logoColor=FFFFFF)](https://github.com/Aetherinox/obsidian-dataview-snippets/tree/main/Snippets/Alphabetized%20List%201)
259+
229260
</div>

Snippets/Alphabetized List 2/code.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
dv.container.className += ' atx-alv1-dataview'
2+
3+
var html = "";
4+
let arrAlphabet = [];
5+
let arrPages = dv.pages( "" )
6+
.forEach( p =>
7+
{
8+
const file = p.file
9+
const file_path = file.path;
10+
const file_name = file.name;
11+
const file_label = file.frontmatter.name || file.frontmatter.title || file.frontmatter.alias || file_name;
12+
13+
const letter = file_label.charAt( 0 ).toUpperCase( );
14+
let index = arrAlphabet.findIndex( ( item ) => item.name === letter );
15+
16+
if ( index === -1 )
17+
arrAlphabet.push( { name: letter, pages: [ { name: file_name, label: file_label, path: file_path } ] } );
18+
else
19+
{
20+
var item = arrAlphabet.find( item => item.name == letter );
21+
let arr = item.pages;
22+
23+
arr.push( { name: file_name, label: file_label, path: file_path } );
24+
}
25+
26+
arrAlphabet.sort( ( a, b ) => a.name.localeCompare( b.name ) )
27+
});
28+
29+
const ulAlphabet = dv.el( 'ul', '', { container: dv.container } );
30+
31+
dv.list(
32+
dv.array( arrAlphabet )
33+
.forEach( obj =>
34+
{
35+
const arrPages = obj.pages;
36+
const liAlphabet = dv.el( 'li', obj.name, { container: ulAlphabet } );
37+
const ulPages = dv.el( 'ul', '', { container: liAlphabet });
38+
39+
Promise.all( arrPages.map( async ( pages ) =>
40+
{
41+
const page_path = pages.path;
42+
const page_name = pages.name;
43+
const page_label = pages.label;
44+
45+
const file_link = dv.fileLink( page_path, false, page_label );
46+
47+
dv.el( 'li', file_link, { container: ulPages } );
48+
49+
}
50+
));
51+
})
52+
)
53+
54+
const divClose = dv.el( 'div', html, { container: dv.container, cls: 'atx-alv1-close' } );

0 commit comments

Comments
 (0)