Topic
Summary
1.How to get sBibTex_citations and display it in the current file?
( Look at DVJS20_output_this_BibTex_citations_shorter )
1.1 How to get a_Author each of which is a string from page.Author?
( Look at Step M23 )
2.How to get s_Year where the format of page.Year is YYYY or YYYY-MM-DD such as :
---
Year: 1963
---
or
---
Year: 1963-12-13
---
( Look at Inline DQL: get s_Year )
3.How to get s_Author where page.Author is a link or a list of links such as :
Author:: [[Foucault, Michel]]
or
Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]
( Look at DVJS30_output_this_s_Author )
4.How to get s_bID where page.bID is s_Author_LastName + s_Year ?
( Look at DVJS40_output_this_s_bID )
Input
Summary
Requirements
- Author field: My author field is currently set up as a link, so I can see all works by a given Author in my database. How can I change this so the format in Dataview is consistent with BibTex? I’d like it to displace {Foucault, Michel} without the []
Note: This would have to be able to juggle multiple authors (for example: [[Foucault, Michel]] and [[Deleuze, Gilles]] )
I think the simplest solution is a .replace() function that removes [], if some sort of analog exists here.
- Year field: The Date is only the year (1963) for this file, but could be 1963-12-13 for example (YYYY or YYYY-MM-DD).
All dates will begin with a year. How do I call the substring method?
- bID field: I’m also trying to generate the bID field automatically to be LastNameYear for the first author, any suggestions for doing that?
dictionary files
---
Date: 2019-03-01
bID: Foucault1963
Year: 1963-12-13
Publisher: Routledge
Address: United Kingdom
---
Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh
---
Date: 2019-03-01
bID: Deleuze1972
Year: 1972
Publisher: Routledge
Address: United Kingdom
---
Author:: [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh
- filename :
Deleuze, Gilles
Deleuze, Gilles is a philosopher.
- filename :
Foucault, Michel
(not exist)
Metadata: used by the current page code
Summary
---
number headings: first-level 2, max 6, contents ^toc, _.1.1.
Date: 2019-03-01
bID: Foucault1963
Year: 1963-12-30
Publisher: Routledge
Address: United Kingdom
---
Author:: [[Foucault, Michel]], [[Deleuze, Gilles]]
Type:: Book
Topics:: [[Biopower]], [[Healthcare]]
Tags:: #Philosophy
Status:: Fresh
original design
@BOOK={=this.bID,
 Title = {=this.file.name}
 Author = {=this.Author}
 Year = {=this.Year}
 Publisher = {=this.Publisher}
 Address = {=this.Address}
}
expected result
@BOOK={Foucault1963},
Title = {20220721_BiBTeX}
Author = {Foucault, Michel and Deleuze, Gilles}
Year = {1963}
Publisher = {Routledge}
Address = {United Kingdom}
}
Notes
- Author=
Foucault, Michel and Deleuze, Gilles
- Field and entry names are case insensitive.So there is no difference between
author
, Author
, AUTHOR
.
Solution: Inline
Summary
Inline DQL: get s_Year
step 1: get dt_Year
dt_Year== choice( typeof(this.Year) != "date", date(this.Year+ "-12-30"), this.Year )
//=>12 30, 1963 (a date)
step 2: get s_Year
s_Year== dateformat(choice( typeof(this.Year) != "date", date(this.Year+ "-12-30"), this.Year ), "yyyy")
//=>“1963”
Inline DVJS: get s_Author
To understand steps:
To look at: DVJS30_output_this_s_Author
To use code:
To copy from: inDVJS10_output_this_s_Author
Inline DVJS: get s_bID
To understand steps:
To look at: DVJS40_output_this_s_bID
To use code:
To copy from: inDVJS20_output_this_s_bID
Solution: Main
Summary_wikiLink
F1_R1 `rest_field` Type path
Link [[wikiLinkNotExist]] Hash(Link) wikiLinkNotExist
Link [[wikiLinkExist]] Hash(Link) 100_Project/wikiLinkExist.md
DVJS10_output_this_BibTex_citations
Summary
Main DVJS
Code Name |
deal with data type |
Purposes |
Remark |
DVJS10_output_this_BibTex_citations |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) 2.s_Year: number, date |
0.require metadata YAML+DVIF 1.get a_Author + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it |
|
Code DVJS10_output_this_BibTex_citations
Summary_code
title: DVJS10_output_this_BibTex_citations =>0.require metadata YAML+DVIF 1.get + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it
collapse: close
icon:
color:
```dataviewjs
// M02. Require the print function :
// #####################################################################
// version : 2022-05-01 v1.00 Justdoitcc
function print(...aArgs){
let aText=[...aArgs];
let sTextJoined=aText.join('').replace(/[ ]/g,' ').replace(/(\r\n|\r|\n)/g, '<br>');
dv.el("span", sTextJoined);
return true;
}
// M11. define pages: this current page
// #####################################################################
let pages = dv.current();
// M21. define a_Author: array of hashes(links)
// #####################################################################
let a_Author = [];
if (!dv.isArray(pages.Author)) {
a_Author = [pages.Author];
} else {
a_Author = pages.Author;
}
// M21.DEB01 Debug Output a_Author:
// #####################################################################
//print("The following is the content of the `a_Author`.\n");
//print(JSON.stringify(a_Author, null, 2), "\n");
// CASE 1: [[wikiLinkNotExist]]=>Hash(Link).path: not endwith ".md"
// #####################################################################
// The following is the content of the a_Author.
// [
// {
// "path": "Foucault, Michel",
// "type": "file",
// "embed": false
// },
// {
// "path": "Deleuze, Gilles",
// "type": "file",
// "embed": false
// }
// ]
// CASE 2: [[wikiLinkExist]]=>Hash(Link).path: endwith ".md"
// #####################################################################
// The following is the content of the a_Author.
// [
// {
// "path": "100_Project/02_dataview/Q08_BiBTeX/Q08_BiBTeX/04/Foucault, Michel.md",
// "type": "file",
// "embed": false
// },
// {
// "path": "100_Project/02_dataview/Q08_BiBTeX/Q08_BiBTeX/04/Deleuze, Gilles.md",
// "type": "file",
// "embed": false
// }
// ]
// M23. get a_Author: array of strings
// #####################################################################
// CASE 1: When the file does not exist : get each path of a_Author
// CASE 2: When the file exists: get each file.name of a_Author
a_Author = a_Author.map((hLink) => {
// M17.EL01 CASE 1:
// [[wikiLinkNotExist]]=>Hash(Link).path:wikiLinkNotExist
if (!dv.func.endswith(hLink.path, ".md")) {
return hLink.path; //=>"Foucault, Michel"
} else {
// M17.EL03 CASE 2:
// [[wikiLinkExist]]=>Hash(Link).path:100_Project/wikiLinkExist.md
return dv.page(hLink.path).file.name;//=>"Foucault, Michel"
}
});
// M23.DEB01 Debug Output a_Author:
// #####################################################################
// [
// "Foucault, Michel",
// "Deleuze, Gilles"
// ]
// #####################################################################
// M25. get s_Author: Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
s_Author = a_Author[0];
} else {
s_Author = a_Author.join(" and ");//=>Foucault, Michel and Deleuze, Gilles
}
// M31. get dt_Year : transform idt_Year into a `date`
// #####################################################################
let idt_Year = pages.Year;//=> pages.Year = 1963 or 1963-12-30
let dt_Year = dv.func.choice(
dv.func.typeof(idt_Year) !== "date",
dv.date(idt_Year + "-12-30"),
idt_Year
);
//=>12 30, 1963 (a date)
// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`)
// #####################################################################
let s_Year = dt_Year.toFormat("yyyy"); //=>"1963"
// #####################################################################
// M41. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;
let s_bID = s_Author_LastName + s_Year;
// M61. define sBibTex_citations:
// #####################################################################
// Requirement:
// ```
// @BOOK={=this.bID,
//  Title = {=this.file.name}
//  Author = {=this.Author}
//  Year = {=this.Year}
//  Publisher = {=this.Publisher}
//  Address = {=this.Address}
// }
// ```
let sBibTex_citations = `
<pre><code>
@BOOK={${s_bID}},
 Title = {${pages.file.name}}
 Author = {${s_Author}}
 Year = {${s_Year}}
 Publisher = {${pages.Publisher}}
 Address = {${pages.Address}}
}
</code></pre>
`
// M71. Output sBibTex_citations:
// #####################################################################
dv.span(sBibTex_citations);
```
Screenshots(DVJS10)
@BOOK={Foucault1963},
Title = {20220721_BiBTeX}
Author = {Foucault, Michel and Deleuze, Gilles}
Year = {1963}
Publisher = {Routledge}
Address = {United Kingdom}
}
DVJS20_output_this_BibTex_citations_shorter : final
Summary
Main DVJS
Code Name |
deal with data type |
Purposes |
Remark |
DVJS20_output_this_BibTex_citations_shorter |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) 2.s_Year: number, date |
0.require metadata YAML+DVIF 1.get a_Author + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it |
1.The code is copied from DVJS10_output_this_BibTex_citations 2.The comments which are out of use are removed. 3.To refactor Step M21 an M23 4.It is the final verson. |
Code DVJS20_output_this_BibTex_citations_shorter
Summary_code
title: DVJS20_output_this_BibTex_citations_shorter =>0.require metadata YAML+DVIF 1.get a_Author + s_Author 2.get s_Year 3.get s_bID 4.define sBibTex_citations 5.output it
collapse: close
icon:
color:
```dataviewjs
// M11. define pages: this current page
// #####################################################################
let pages = dv.current();
// M21. define a_Author: array of hashes(links)
// #####################################################################
// dv.array():Convert a given value or array into a Dataview data array. If the value is already a data array, returns it unchanged.
let a_Author = dv.array(pages.Author);
// M23. get a_Author: array of strings
// #####################################################################
// CASE 1: When the file does not exist : get each path of a_Author
// Left : [[wikiLinkNotExist]]=>Hash(Link).path:wikiLinkNotExist
// CASE 2: When the file exists: get each file.name of a_Author
// Right : [[wikiLinkExist]]=>Hash(Link).path:100_Project/wikiLinkExist.md
a_Author = a_Author.map(
(hLink) =>
(!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
dv.page(hLink.path).file.name
);
// #####################################################################
// M25. get s_Author: Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
s_Author = a_Author[0];
} else {
s_Author = a_Author.join(" and ");//=>Foucault, Michel and Deleuze, Gilles
}
// M31. get dt_Year : transform idt_Year into a `date`
// #####################################################################
let idt_Year = pages.Year;//=> pages.Year = 1963 or 1963-12-30
let dt_Year = dv.func.choice(
dv.func.typeof(idt_Year) !== "date",
dv.date(idt_Year + "-12-30"),
idt_Year
);
//=>12 30, 1963 (a date)
// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`)
// #####################################################################
let s_Year = dt_Year.toFormat("yyyy"); //=>"1963"
// #####################################################################
// M41. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;
let s_bID = s_Author_LastName + s_Year;
// M61. define sBibTex_citations:
// #####################################################################
// Requirement:
// ```
// @BOOK={=this.bID,
//  Title = {=this.file.name}
//  Author = {=this.Author}
//  Year = {=this.Year}
//  Publisher = {=this.Publisher}
//  Address = {=this.Address}
// }
// ```
let sBibTex_citations = `
<pre><code>
@BOOK={${s_bID}},
 Title = {${pages.file.name}}
 Author = {${s_Author}}
 Year = {${s_Year}}
 Publisher = {${pages.Publisher}}
 Address = {${pages.Address}}
}
</code></pre>
`
// M71. Output sBibTex_citations:
// #####################################################################
dv.span(sBibTex_citations);
```
Screenshots(DVJS20)
@BOOK={Foucault1963},
Title = {20220721_BiBTeX}
Author = {Foucault, Michel and Deleuze, Gilles}
Year = {1963}
Publisher = {Routledge}
Address = {United Kingdom}
}
DVJS30_output_this_s_Author
Summary
Main DVJS
Code Name |
deal with data type |
Purposes |
Remark |
DVJS30_output_this_s_Author |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) |
0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.output s_Author |
1.The comments which are out of use are removed. 2.The code is copied from DVJS20_output_this_BibTex_citations_shorter 3.To remove Step (>=M30) 4.To add Step M91 5.The code is used to be converted to inline DVJS. |
Code DVJS30_output_this_s_Author
Summary_code
title: DVJS30_output_this_s_Author =>0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.output s_Author
collapse: close
icon:
color:
```dataviewjs
// M23. get a_Author: array of hashes(links)==>array of strings (M11+M21+M23)
// #####################################################################
let a_Author = dv.array(dv.current().Author).map(
(hLink) =>
(!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
dv.page(hLink.path).file.name
);
// #####################################################################
// M25. get s_Author: Foucault, Michel and Deleuze, Gilles
// #####################################################################
let s_Author = "";
if (a_Author.length === 1) {
s_Author = a_Author[0];
} else {
s_Author = a_Author.join(" and ");
}
// M91. Output s_Author:
// #####################################################################
dv.span(s_Author);
```
Screenshots(DVJS30)
//=>Foucault, Michel and Deleuze, Gilles
inDVJS10_output_this_s_Author
Summary
Main Inline DVJS
Code Name |
deal with data type |
Purposes |
Remark |
inDVJS10_output_this_s_Author |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) |
0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 4.output s_Author |
1.It is the same as DVJS30_output_this_s_Author. 2.DVJS30_output_this_s_Author is simplified to be an Inline DVJS. |
Notes
Notes:
0.copy DVJS30_output_this_s_Author to code_tmp
1.Steps: (M11+M21+M23)+M25+(M91)
2.At Step M25: To remove let s_Author = "";
3.At Step M25: To remove s_Author =
4.At Step M91: To remove dv.span(s_Author);
5.At Step M25: To replace a_Author
as the content of a_Author
which is defined at Step M23
6.At Step M23: To remove the content which is defined at Step M23
7.At Step M25: To copy the content into an Inline DVJS expression.
8.An Inline DVJS is finishd!
Code inDVJS10_output_this_s_Author
Summary_code
s_Author=$= if ( dv .array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name ).length === 1 ) { dv .array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name )[0]; } else { dv.array(dv.current().Author) .map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name ) .join("and"); }
Screenshots(inDVJS10)
//=>Foucault, MichelandDeleuze, Gilles
DVJS40_output_this_s_bID
Summary
Main DVJS
Code Name |
deal with data type |
Purposes |
Remark |
DVJS40_output_this_s_bID |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) 2.s_Year: number, date |
0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.get s_Year 4.get s_bID 5.output s_bID |
1.The comments which are out of use are removed. 2.The code is copied from DVJS20_output_this_BibTex_citations_shorter 3.To remove Step M25, M61 and M71 4.To add Step M91 5.The code is used to be converted to inline DVJS. |
Code DVJS40_output_this_s_bID
Summary_code
title: DVJS40_output_this_s_bID =>0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.get s_Year 4.get s_bID 5.output s_bID
collapse: close
icon:
color:
```dataviewjs
// M23. get a_Author: array of hashes(links)==>array of strings (M11+M21+M23)
// #####################################################################
let a_Author = dv.array(dv.current().Author).map(
(hLink) =>
(!dv.func.endswith(hLink.path, ".md") && hLink.path) ||
dv.page(hLink.path).file.name
);
// #####################################################################
// M33. get s_Year: dateformat dt_Year (`date`) to a s_Year (`string`) (M31+M33)
// #####################################################################
let s_Year = dv.func.choice(
dv.func.typeof(dv.current().Year) !== "date",
dv.date(dv.current().Year + "-12-30"),
dv.current().Year
).toFormat("yyyy"); //=>"1963"
// M41. get s_Author_LastName:
// #####################################################################
let s_Author_LastName = dv.func.split(a_Author[0], ",")[0] ;
// #####################################################################
// M51. get s_bID: s_Author_LastName + s_Year
// #####################################################################
let s_bID = s_Author_LastName + s_Year;
// M91. Output s_bID:
// #####################################################################
dv.span(s_bID);
```
Screenshots(DVJS40)
//=>Foucault1963
inDVJS20_output_this_s_bID
Summary
Main Inline DVJS
Code Name |
deal with data type |
Purposes |
Remark |
inDVJS20_output_this_s_bID |
1.a_Author: 1.1 NotLists, Lists; 1.2 Hash(Link), AoH(Array of hashes) 2.s_Year: number, date |
0.require metadata YAML+DVIF 1.get a_Author 2.get s_Author 3.get s_Year 4.get s_bID 5.output s_bID |
1.It is the same as DVJS40_output_this_s_bID. 2.DVJS40_output_this_s_bID is simplified to be an Inline DVJS. |
Notes
Notes:
0.copy DVJS40_output_this_s_bID to code_tmp
1.Step M51: let s_bID = s_Author_LastName + s_Year;
Part A(Left): To simplify s_Author_LastName
10.At Step M41: To replace a_Author
as the content of a_Author
which is defined at Step M23
11.At Step M51: To replace s_Author_LastName
as the content of s_Author_LastName
which is defined at Step M41
12.Part A(Left) is finoshed.
Part B(Right): To replace s_Year
21.At Step M51: To replace s_Year
as the content of s_Year
which is defined at Step M33
22.Part B(Right) is finoshed.
31.At Step M51: To copy the content between let s_bID =
and ;
into an Inline DVJS expression.
32.An Inline DVJS is finishd!
Code inDVJS20_output_this_s_bID
Summary_code
s_bID=$= dv.func.split(dv.array(dv.current().Author).map( (hLink) => (!dv.func.endswith(hLink.path, ".md") && hLink.path) || dv.page(hLink.path).file.name )[0], ",")[0] + dv.func.choice( dv.func.typeof(dv.current().Year) !== "date", dv.date(dv.current().Year + "-12-30"), dv.current().Year ).toFormat("yyyy")
Screenshots(inDVJS20)
//=>Foucault1963