Is the a way to view all of the metadata in the current note?

Topic

Summary
  • How to get each key/value of the metadata(YAML and DVIF) in one page? (DVJS10)
  • How to get each key/value of the metadata(YAML and DVIF) excluding the file key and the duplicated DVIF in one page? (DVJS12)
  • How to get each key/value of the metadata(ONLY the file key) excluding YAML and DVIF in one page? (DVJS20)
  • How to get each key/value of the metadata(ONLY the file key and aWhiteList keys) excluding YAML and DVIF in one page? (DVJS22)

Test

Summary
  • dataview: v0.5.46

input

Summary

the main DVJS file

  • filename : 20221011_Metadata_DVJS


### DVJS12_get_keys_values_excluding_file_key_and_duplicated_DVIF_and_TABLE
// #####################################################################
// The following note is the content of the main DVJS12.



### DVJS22_get_keys_values_of_only_file_key_and_aWhiteList_keys_and_TABLE
// #####################################################################
// The following note is the content of the main DVJS22.




dictionary files:

  • Location: “999_Test/Q87_test_data”

folder: 03

  • filename : dic_19880301
---
Date: 1988-03-01
drinks_y: "[[Black Coffee]]"
---
#Project/P03

drinks_d:: [[Green Tea]] 
exercises_a:: "table tennis", "cycling"
exercises_b:: badminton , walking race
exercises duration:: 90 minutes
expenses:: 100, 200
remark::



DVJS10_get_keys_values_excluding_file_key_and_TABLE

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS10
_get_keys_values
_excluding_file_key
_and_TABLE
Metadata
of one page
no 1.To gather the key/value of one page
2.To filter the data excluding the file key
3.To display the result as a table

Notes

Summary

The same codes: To get the file.path of the note like [[dic_19880301]]?

  • Suppose that the note like [[dic_19880301]] is unique in your Obsidian vault.
A10: Inline DQL
file_path = `=[[dic_19880301]].file.path`

//=>file_path = 999_Test/Q87_test_data/03/dic_19880301.md

A11: Inline DVJS
file_path = `$=dv.page("dic_19880301").file.path`

//=>file_path = 999_Test/Q87_test_data/03/dic_19880301.md

The same codes: To gather one page like [[dic_19880301]]

M11: Original Example10
// M11. define h_single_page: gather one relevant page
// #####################################################################
let h_single_page = dv
    .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();
M11: Another Example11
  • Suppose that the note like [[dic_19880301]] is unique in your Obsidian vault.
// M11. define h_single_page: gather one relevant page
// #####################################################################
// let h_single_page = dv
//     .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();
M11: Another Example12
  • The code must exist in the note [[dic_19880301]].
// M11. define h_single_page: gather one relevant page
// #####################################################################
// let h_single_page = dv
//     .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
let h_single_page = dv.current();

code DVJS10_get_keys_values_excluding_file_key_and_TABLE

Summary_code
title: DVJS10_get_keys_values_excluding_file_key_and_TABLE =>1.To gather the key/value of one page 2.To filter the data excluding the `file` key 3.To display the result as a table
collapse: close
icon: 
color: 
```dataviewjs
// M11. define h_single_page: gather one relevant page
// #####################################################################
let h_single_page = dv
    .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();


// M21.Gather the key/value of one page : AoA = Array of Arrays
// FILTER_CASE_01: excluding the `file` key
// #####################################################################
let AoA = Object.entries(h_single_page)
    .filter(([key, value]) => key !== "file")
    .map(([key, value]) => [key, value, dv.func.typeof(value)]);


// M31.Output the heading as H3: 
// #####################################################################
dv.span(
    `### M33.Output keys_values of ${h_single_page.file.name}: excluding the file key`
);


// M33.Output AoA:
// #####################################################################
dv.table(["key", "value", "dv.func.typeof"], AoA);




Screenshots(DVJS10):


DVJS12_get_keys_values_excluding_file_key_and_duplicated_DVIF_and_TABLE

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS12
_get_keys_values
_excluding_file_key
_and_duplicated_DVIF
_and_TABLE
Metadata
of one page
no 1.To gather the key/value of one page
2.To filter the data excluding the file key
3.To filter the data excluding the duplicated DVIF created by Dataview
4.To display the result as a table

code DVJS12_get_keys_values_excluding_file_key_and_duplicated_DVIF_and_TABLE

Summary_code
title: DVJS12_get_keys_values_excluding_file_key_and_duplicated_DVIF_and_TABLE =>1.To gather the key/value of one page 2.To filter the data excluding the `file` key 3.To filter the data excluding the duplicated DVIF created by Dataview 4.To display the result as a table
collapse: close
icon: 
color: 
```dataviewjs
// M11. define h_single_page: gather one relevant page
// #####################################################################
let h_single_page = dv
    .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();


// M21. define a_org_keys: gather the original keys of one page
// #####################################################################
let a_org_keys = Object.keys(h_single_page);


// M23. define a_org_keys_to_lower_case: transform a_org_keys into lower case
// #####################################################################
let a_org_keys_to_lower_case = a_org_keys.map((key) => dv.func.lower(key));


// M25. define h_org_keys_to_lower_case: {date: 2}
// calculate the QTY of each lower case key
// #####################################################################
let h_org_keys_to_lower_case = {};
a_org_keys_to_lower_case.forEach((s_lower_key) => {
    if (s_lower_key in h_org_keys_to_lower_case) {
        h_org_keys_to_lower_case[s_lower_key]++;
    } else {
        h_org_keys_to_lower_case[s_lower_key] = 1;
    }
});


// M25.DB01 Debug Output: h_org_keys_to_lower_case
// #####################################################################
//dv.span("The following is the content of the `h_org_keys_to_lower_case`.\n");
//dv.span(JSON.stringify(h_org_keys_to_lower_case, null, 2), "\n");


//The following is the content of the h_org_keys_to_lower_case.
// let h_org_keys_to_lower_case = {
//     file: 1,
//     date: 2,
//     drinks_y: 1,
//     drinks_d: 1,
//     exercises_a: 1,
//     exercises_b: 1,
//     "exercises duration": 1,
//     expenses: 1,
//     remark: 1,
//     "exercises-duration": 1,
// };


// M31.Gather the key/value of one page : AoA = Array of Arrays
// FILTER_CASE_01: excluding the `file` key
// FILTER_CASE_02: excluding the duplicated DVIF created by Dataview:
// #####################################################################
let AoA = Object.entries(h_single_page)
    .filter(([key, value]) => key !== "file")
    .filter(
        ([key, value]) =>
            !h_org_keys_to_lower_case[key] ||
            h_org_keys_to_lower_case[key] === 1
    )
    .map(([key, value]) => [key, value, dv.func.typeof(value)]);


// M51.Output the heading as H3: 
// #####################################################################
dv.span(
    `### M53.Output keys_values of ${h_single_page.file.name}: excluding the file key and the duplicated DVIF`
);


// M53.Output AoA:
// #####################################################################
dv.table(["key", "value", "dv.func.typeof"], AoA);




Screenshots(DVJS12):


DVJS20_get_keys_values_of_only_file_key_and_TABLE

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS20
_get_keys_values
_of_only_file_key
_and_TABLE
Metadata
of one page
no 1.To gather the key/value of one page h_single_page["file"]
2.To filter the data excluding the frontmatter key
3.To display the result as a table

code DVJS20_get_keys_values_of_only_file_key_and_TABLE

Summary_code
title: DVJS20_get_keys_values_of_only_file_key_and_TABLE =>1.To gather the key/value of one page `h_single_page["file"]` 2.To filter the data excluding the `frontmatter` key 3.To display the result as a table
collapse: close
icon: 
color: 
```dataviewjs
// M11. define h_single_page: gather one relevant page
// #####################################################################
let h_single_page = dv
    .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();


// M21.Gather the key/value of one page : AoA = Array of Arrays
// FILTER_CASE_01: excluding the `frontmatter` key
// #####################################################################
let AoA = Object.entries(h_single_page["file"])
    .filter(([key, value]) => key !== "frontmatter")
    .map(([key, value]) => [key, dv.func.typeof(value), value]);


// M31.Output the heading as H3: 
// #####################################################################
dv.span(
    `### M33.Output keys_values of ${h_single_page.file.name}: ONLY the file key excluding the frontmatter key`
);


// M33.Output AoA:
// #####################################################################
dv.table(["key", "typeof", "value"], AoA);




Screenshots(DVJS20):


DVJS22_get_keys_values_of_only_file_key_and_aWhiteList_keys_and_TABLE

Summary

Main DVJS

Code Name Data type Group By Purposes Remark
DVJS22
_get_keys_values
_of_only_file_key
_and_aWhiteList_keys
_and_TABLE
Metadata
of one page
no 1.To gather the key/value of one page h_single_page["file"]
2.To filter the data where aWhiteList icontains key
3.To display the result as a table

Notes

Summary

To modify

Original Example: ONLY the file key and aWhiteList keys
  • (comments)FILTER_CASE_01: Not to exclud the frontmatter key
  • FILTER_CASE_02: To filter the data where aWhiteList icontains key
// M23.Gather the key/value of one page : AoA = Array of Arrays
// (comments)FILTER_CASE_01: excluding the `frontmatter` key
// FILTER_CASE_02: where aWhiteList icontains key
// #####################################################################
let AoA = Object.entries(h_single_page["file"])
    //.filter(([key, value]) => key !== "frontmatter")
    .filter(([key, value]) => dv.func.icontains(aWhiteList, key))
    .map(([key, value]) => [key, dv.func.typeof(value), value]);
Another Example: ONLY the file key
  • (comments)FILTER_CASE_01: Not to exclud the frontmatter key
  • (comments)FILTER_CASE_02: Not to filter the data where aWhiteList icontains key
// M23.Gather the key/value of one page : AoA = Array of Arrays
// (comments)FILTER_CASE_01: excluding the `frontmatter` key
// (comments)FILTER_CASE_02: where aWhiteList icontains key
// #####################################################################
let AoA = Object.entries(h_single_page["file"])
    //.filter(([key, value]) => key !== "frontmatter")
    //.filter(([key, value]) => dv.func.icontains(aWhiteList, key))
    .map(([key, value]) => [key, dv.func.typeof(value), value]);
Another Example: ONLY the file key excluding the frontmatter key
  • FILTER_CASE_01: To exclud the frontmatter key
  • (comments)FILTER_CASE_02: Not to filter the data where aWhiteList icontains key
// M23.Gather the key/value of one page : AoA = Array of Arrays
// (comments)FILTER_CASE_01: excluding the `frontmatter` key
// (comments)FILTER_CASE_02: where aWhiteList icontains key
// #####################################################################
let AoA = Object.entries(h_single_page["file"])
    .filter(([key, value]) => key !== "frontmatter")
    //.filter(([key, value]) => dv.func.icontains(aWhiteList, key))
    .map(([key, value]) => [key, dv.func.typeof(value), value]);

code DVJS22_get_keys_values_of_only_file_key_and_aWhiteList_keys_and_TABLE

Summary_code
title: DVJS22_get_keys_values_of_only_file_key_and_aWhiteList_keys_and_TABLE =>1.To gather the key/value of one page `h_single_page["file"]` 2.To filter the data where aWhiteList icontains key 3.To display the result as a table
collapse: close
icon: 
color: 
```dataviewjs
// M11. define h_single_page: gather one relevant page
// #####################################################################
let h_single_page = dv
    .pages('"999_Test/Q87_test_data/03/dic_19880301.md"')[0];
//let h_single_page = dv.page("dic_19880301");
//let h_single_page = dv.current();


// M21.define aWhiteList : 
// #####################################################################
let aWhiteList = [
    "name",
    "outlinks",
    "inlinks",
    "etags",
    "tags",
    "ctime",
    "mtime",
    "day",
];


// M23.Gather the key/value of one page : AoA = Array of Arrays
// (comments)FILTER_CASE_01: excluding the `frontmatter` key
// FILTER_CASE_02: where aWhiteList icontains key
// #####################################################################
let AoA = Object.entries(h_single_page["file"])
    //.filter(([key, value]) => key !== "frontmatter")
    .filter(([key, value]) => dv.func.icontains(aWhiteList, key))
    .map(([key, value]) => [key, dv.func.typeof(value), value]);


// M31.Output the heading as H3: 
// #####################################################################
dv.span(
    `### M33.Output keys_values of ${h_single_page.file.name}: ONLY the file key and aWhiteList keys`
);


// M33.Output AoA:
// #####################################################################
dv.table(["key", "typeof", "value"], AoA);




Screenshots(DVJS22):


Conclusion

Summary
  • Use the DVJS12 instead of the DVJS10.
  • Use the DVJS22 instead of the DVJS20.

3 Likes