@@ -28,20 +28,21 @@ const makeFrontMatterBlock = (frontMatter) => {
28
28
const markdown = [ ] ;
29
29
markdown . push ( `# ${ frontMatter . title } ` ) ;
30
30
if ( frontMatter . authors ) {
31
- if ( typeof frontMatter . authors === 'object' && Array . isArray ( frontMatter . authors ) ) {
32
- utils . warn ( `Narrative parsing -- can't do author arrays yet` ) ;
33
- } else if ( typeof frontMatter . authors === 'string' ) {
34
- if ( frontMatter . authorLinks && typeof frontMatter . authorLinks === "string" ) {
35
- markdown . push ( `### Author: [${ frontMatter . authors } ](${ frontMatter . authorLinks } )` ) ;
36
- } else {
37
- markdown . push ( `### Author: ${ frontMatter . authors } ` ) ;
38
- }
31
+ let authors = parseContributors ( frontMatter , "authors" , "authorLinks" ) ;
32
+ if ( authors ) {
33
+ markdown . push ( `### Author: ${ authors } ` ) ;
39
34
if ( frontMatter . affiliations && typeof frontMatter . affiliations === "string" ) {
40
35
markdown [ markdown . length - 1 ] += " <sup> 1 </sup>" ;
41
36
markdown . push ( `<sup> 1 </sup> ${ frontMatter . affiliations } ` ) ;
42
37
}
43
38
}
44
39
}
40
+ if ( frontMatter . translators ) {
41
+ let translators = parseContributors ( frontMatter , "translators" , "translatorLinks" ) ;
42
+ if ( translators ) {
43
+ markdown . push ( `### Translators: ${ translators } ` ) ;
44
+ }
45
+ }
45
46
if ( frontMatter . date && typeof frontMatter . date === "string" ) {
46
47
markdown . push ( `### Created: ${ frontMatter . date } ` ) ;
47
48
}
@@ -58,6 +59,57 @@ const makeFrontMatterBlock = (frontMatter) => {
58
59
return block ;
59
60
} ;
60
61
62
+ const parseContributors = ( frontMatter , contributorsKey , contributorLinksKey ) => {
63
+ const contributors = frontMatter [ contributorsKey ] ;
64
+ const contributorLinks = frontMatter [ contributorLinksKey ] ;
65
+
66
+ if ( Array . isArray ( contributors ) ) {
67
+ return parseContributorsArray ( contributors , contributorLinks , contributorsKey , contributorLinksKey ) ;
68
+ } else if ( typeof contributors === 'string' ) {
69
+ return parseContributorsString ( contributors , contributorLinks , contributorsKey , contributorLinksKey ) ;
70
+ }
71
+ }
72
+
73
+ const parseContributorsArray = ( contributors , contributorLinks , contributorsKey , contributorLinksKey ) => {
74
+ // validate links
75
+ if ( contributorLinks ) {
76
+ if ( ! Array . isArray ( contributorLinks ) ) {
77
+ utils . warn ( `Narrative parsing - if ${ contributorsKey } is an array, then ${ contributorLinksKey } must also be an array. Skipping links.` ) ;
78
+ contributorLinks = undefined ;
79
+ } else if ( contributorLinks . length != contributors . length ) {
80
+ utils . warn ( `Narrative parsing - the length of ${ contributorsKey } and ${ contributorLinksKey } did not match. Skipping links.` ) ;
81
+ contributorLinks = undefined ;
82
+ }
83
+ }
84
+
85
+ if ( contributorLinks ) {
86
+ contributors = contributors . map ( ( contributor , idx ) => {
87
+ return contributorLink ( contributor , contributorLinks [ idx ] ) ;
88
+ } ) ;
89
+ }
90
+
91
+ return contributors . join ( ", " ) ;
92
+ }
93
+
94
+ const parseContributorsString = ( contributors , contributorLinks , contributorsKey , contributorLinksKey ) => {
95
+ // validate links
96
+ if ( contributorLinks ) {
97
+ if ( typeof contributorLinks !== "string" ) {
98
+ utils . warn ( `Narrative parsing - if ${ contributorsKey } is a string, then ${ contributorLinksKey } must also be a string. Skipping links.` ) ;
99
+ contributorLinks = undefined ;
100
+ }
101
+ }
102
+
103
+ return contributorLink ( contributors , contributorLinks ) ;
104
+ }
105
+
106
+ const contributorLink = ( contributor , contributorLink ) => {
107
+ if ( contributorLink ) {
108
+ return `[${ contributor } ](${ contributorLink } )` ;
109
+ }
110
+ return contributor ;
111
+ }
112
+
61
113
/**
62
114
* Extract a code-block from the content, if it exists, tagged as auspiceMainDisplayMarkdown
63
115
* Which we send to the client under a special key for parsing in the main display
0 commit comments