DataviewJS help—having trouble matching key values that are also links

Topic

Summary

1.How to get the unique links from each page.parent?
2.How to create a_pages_from_links?


Input

Summary

dictionary files

sons

  • location: “100_Project/01_dataviewjs/01_by_example/Q14_links/Q14_test_data_sons”
A04
  • filename : dic_20130401
---
date created: 2013-04-01T19:30:50.000Z
date updated: 2013-04-11 19:30:50
aliases: []
parent: "[[ProjectI]]"
tags:
    - project/p1
---

  • filename : dic_20130406
---
date created: 2013-04-06T19:30:50.000Z
date updated: 2013-04-16 19:30:50
aliases: []
parent: ["[[ProjectN]]", "[[ProjectK]]"]
tags:
    - project/p6
---

F02
  • filename : dic_20130201
---
date created: 2013-02-01T19:30:50.000Z
date updated: 2013-02-11 19:30:50
aliases: []

tags:
    - project/p1
---

parent:: [[ProjectD]]

  • filename : dic_20130206
---
date created: 2013-02-06T19:30:50.000Z
date updated: 2013-02-06 19:30:50
aliases: []

tags:
    - project/p6
---

parent:: [[ProjectR]], [[ProjectD]]

R03_excluding
  • filename : dic_20130301
---
date created: 2013-03-01T19:30:50.000Z
date updated: 2013-03-11 19:30:50
aliases: []
tags:
    - JOTnote/j1
---

parent:: [[ProjectN_J1]]

  • filename : dic_20130306
---
date created: 2013-03-06T19:30:50.000Z
date updated: 2013-03-16 19:30:50
aliases: []
tags:
    - JOTnote/j6
---

parent:: [[ProjectN_J6]]

Y05_excluding
  • filename : dic_20130501
---
date created: 2013-05-01T19:30:50.000Z
date updated: 2013-05-11 19:30:50
aliases: []
tags:
    - JOTnote/j1
---

parent:: [[ProjectK_J1]]

  • filename : dic_20130506
---
date created: 2013-05-06T19:30:50.000Z
date updated: 2013-05-16 19:30:50
aliases: []
tags:
    - JOTnote/j6
---

parent:: [[ProjectK_J6]]

Z06
  • filename : dic_20130601
---
date created: 2013-06-01T19:30:50.000Z
date updated: 2013-06-11 19:30:50
aliases: []
parent: "[[ProjectK]]"
tags:
    - project/p1
---

parents

  • location: “100_Project/01_dataviewjs/01_by_example/Q14_links/Q14_test_data_parents”
P01
  • filename : ProjectD
  • ctime: 2013-02-01T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-02-01
name: ProjectD
---
#project/p01

P02
  • filename : ProjectR
  • ctime: 2013-02-06T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-02-06
name: ProjectR
---
#project/p02

P03
  • filename : ProjectI
  • ctime: 2013-04-01T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-04-01
name: ProjectI
---
#project/p03

P04
  • filename : ProjectN
  • ctime: 2013-04-06T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-04-06
name: ProjectN
---
#project/p04

P05
  • filename : ProjectK
  • ctime: 2013-06-01T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-06-01
name: ProjectK
---
#project/p05

P06
  • filename : ProjectS
  • ctime: 2013-07-01T19:30:50
  • mtime: ctime + dv.func.duration(10 days)
---
date: 2013-07-01
name: ProjectS
---
#project/p06


DVJS10_output_a_parents_and_a_sons:

Summary

Main DVJS

Code Name data type Purposes Remark
DVJS10_output_a_parents_and_a_sons non-lists or lists 1.get a_parents: Project[DRINKS]

2.get a_sons

3.output a_parents

4.output a_sons
(unique son_of_project.parent = links of Project[DRINK])

Code DVJS10_output_a_parents_and_a_sons

Summary_code
title: DVJS10_output_a_parents_and_a_sons =>1.get a_parents: Project[DRINKS] 2.get a_sons 3.output a_parents 4.output a_sons (unique son_of_project.parent = links of Project[DRINK])
collapse: close
icon: 
color: 
```dataviewjs
// M21. define a_parents: Project[DRINKS]
// #####################################################################
let a_parents = dv
    .pages(
        '"100_Project/01_dataviewjs/01_by_example/Q14_links/Q14_test_data_parents"'
    )
    .where((page) => dv.func.contains(page.file.name, "Project") )
    .where(
        (page) =>
            dv.func.contains(page.file.tags, "#project") &&
            !dv.func.contains(page.file.tags, "#project/todos") &&
            !dv.func.contains(page.file.tags, "#archival")
    )
    .where(
        (p) =>
            !p.file.folder.includes("Dailies") &&
            !p.file.folder.includes("Inbox")
    );



// M31. define a_sons: 
// dic_20130201, [[dic_20130201]].parent = [[ProjectD]]
// #####################################################################
let a_sons = dv
    .pages(
        '"100_Project/01_dataviewjs/01_by_example/Q14_links/Q14_test_data_sons"'
    )
    .where(
        (page) =>
            dv.func.contains(page.file.name, "dic")
    )
    .where(
        (page) =>
            dv.func.contains(page.file.tags, "#project") &&
            !dv.func.contains(page.file.tags, "#project/todos") &&
            !dv.func.contains(page.file.tags, "#archival")
    );
    
// M81. Output a_parents:
// #####################################################################
dv.header(5, "M81.Print a table of the `a_parents`");
dv.table(
    ["N", "Project", "file.tags"],
    a_parents.map((project, index) => [
        index + 1,
        project.file.name,
        project.file.tags,    
    ])
);



// M91. Output a_sons: unique son_of_project.parent = Project[DRINK]
// #####################################################################
dv.header(5, "M91.Print a table of the `a_sons`");
dv.table(
    ["N", "son_of_project", "tags", "parent", "file.tags"],
    a_sons.map((son_of_project, index) => [
        index + 1,
        son_of_project.file.name,
        son_of_project.tags,    
        son_of_project.parent,
        
        son_of_project.file.tags,
    ])
);

```

Screenshots(DVJS10)


DVJS20_output_filelink_and_mtime_of_a_unique_son_of_links :

Summary

Main DVJS

Code Name data type Purposes Remark
DVJS20_output_filelink_and_mtime
_of_a_unique_son_of_links
non-lists or lists 1.get a_unique_son_of_links

2.create a_pages_from_links

3.output each page.file.link and page.file.mtime
The code is refactered.

Code DVJS20_output_filelink_and_mtime_of_a_unique_son_of_links

Summary_code
title: DVJS20_output_filelink_and_mtime_of_a_unique_son_of_links =>1.get a_unique_son_of_links 2.create a_pages_from_links 3.output each page.file.link and page.file.mtime
collapse: close
icon: 
color: 
```dataviewjs
// M11. define i_max_amount_of_md_files: 
// #####################################################################
let i_max_amount_of_md_files = 20;


// M31. define a_sons: 
// #####################################################################
let a_sons = dv
    .pages(
        '"100_Project/01_dataviewjs/01_by_example/Q14_links/Q14_test_data_sons"'
    )
    .where(
        (page) =>
            dv.func.contains(page.file.name, "dic")
    )
    .where(
        (page) =>
            dv.func.contains(page.file.tags, "#project") &&
            !dv.func.contains(page.file.tags, "#project/todos") &&
            !dv.func.contains(page.file.tags, "#archival")
    );

// M41. get a_unique_son_of_links: js array
// #####################################################################
let a_unique_son_of_links = a_sons
    .map((e) => e.parent)
    .array()  //=>Data Arrays to js array
    .flat()   //=>flatten
    .filter((e) => !(this[e] = e in this)); //=>get unique e



//dv.list(a_unique_son_of_links);
//=>
// [[ProjectD]]
// [[ProjectR]]
// [[ProjectI]]
// [[ProjectN]]
// [[ProjectK]]


// M43. create a_pages_from_links from a_unique_son_of_links:
// dic_20130201, [[dic_20130201]].parent = [[ProjectD]]
// #####################################################################
// CASE 1: When the file does not exist : 
// [[wikiLinkNotExist]]=>Hash(Link).path:wikiLinkNotExist
// CASE 2: When the file exists: 
// [[wikiLinkExist]]=>Hash(Link).path:100_Project/wikiLinkExist.md
let a_pages_from_links = a_unique_son_of_links.map(
    (hLink) =>
        dv.func.endswith(hLink.path, ".md") && dv.page(hLink.path)
);


// M45.a_pages_from_links : 1.js array to Data Arrays 2.sort 3.limit
// #####################################################################
a_pages_from_links = dv
    .array(a_pages_from_links)
    .sort((page) => page.file.mtime, "asc")
    .limit(i_max_amount_of_md_files);


// M71. Output a_pages_from_links: page.file.link and page.file.mtime
// #####################################################################
dv.header(5, "M71.Print a table of the `a_pages_from_links`");
dv.table(
    ["N", "File", "Mtime"],
    a_pages_from_links        
        .map((page, index) => [
            index + 1,
            page.file.link,
            page.file.mtime.toFormat("yyyy-MM-dd HH:mm:ss"),
        ])

);


```

Screenshots(DVJS20)


Reference

Summary