88import { kHtmlEmptyPostProcessResult } from "../../command/render/constants.ts" ;
99import { Format , Metadata } from "../../config/types.ts" ;
1010import { bibliographyCslJson } from "../../core/bibliography.ts" ;
11- import { CSL , cslDateToEDTFDate } from "../../core/csl.ts" ;
11+ import {
12+ CSL ,
13+ cslDateToEDTFDate ,
14+ CSLExtras ,
15+ kAbstractUrl ,
16+ kEIssn ,
17+ kPdfUrl ,
18+ } from "../../core/csl.ts" ;
1219import { Document } from "../../core/deno-dom.ts" ;
1320import { encodeAttributeValue } from "../../core/html.ts" ;
1421import { kWebsite } from "../../project/types/website/website-constants.ts" ;
@@ -24,8 +31,8 @@ export function metadataPostProcessor(
2431) {
2532 return async ( doc : Document ) => {
2633 if ( googleScholarEnabled ( format ) ) {
27- const csl = documentCSL ( input , format , "webpage" , offset ) ;
28- const documentMetadata = googleScholarMeta ( csl ) ;
34+ const { csl, extras } = documentCSL ( input , format , "webpage" , offset ) ;
35+ const documentMetadata = googleScholarMeta ( csl , extras ) ;
2936 const referenceMetadata = await googleScholarReferences ( input , format ) ;
3037 [ ...documentMetadata , ...referenceMetadata ] . forEach ( ( meta ) => {
3138 writeMetaTag ( meta . name , meta . content , doc ) ;
@@ -56,6 +63,7 @@ interface MetaTagData {
5663
5764function googleScholarMeta (
5865 csl : CSL ,
66+ extras : CSLExtras ,
5967) : MetaTagData [ ] {
6068 // The scholar metadata that we'll generate into
6169 const scholarMeta : MetaTagData [ ] = [ ] ;
@@ -66,6 +74,14 @@ function googleScholarMeta(
6674 write ( "citation_title" , csl . title ) ;
6775 }
6876
77+ if ( csl . abstract ) {
78+ write ( "citation_abstract" , csl . abstract ) ;
79+ }
80+
81+ if ( extras . keywords ) {
82+ write ( "citation_keywords" , extras . keywords ) ;
83+ }
84+
6985 // Authors
7086 if ( csl . author ) {
7187 csl . author . forEach ( ( author ) => {
@@ -76,6 +92,26 @@ function googleScholarMeta(
7692 } ) ;
7793 }
7894
95+ // Editors
96+ if ( csl . editor ) {
97+ csl . editor . forEach ( ( editor ) => {
98+ write (
99+ "citation_editor" ,
100+ editor . literal || `${ editor . given } ${ editor . family } ` ,
101+ ) ;
102+ } ) ;
103+ }
104+
105+ if ( csl . issued ) {
106+ const edtfIssued = cslDateToEDTFDate ( csl . issued ) ;
107+ write ( "citation_publication_date" , edtfIssued ) ;
108+ write ( "citation_cover_date" , edtfIssued ) ;
109+ const parts = csl . issued [ "date-parts" ] ;
110+ if ( parts ) {
111+ write ( "citation_year" , parts [ 0 ] [ 0 ] ) ;
112+ }
113+ }
114+
79115 if ( csl [ "available-date" ] ) {
80116 write ( "citation_online_date" , cslDateToEDTFDate ( csl [ "available-date" ] ) ) ;
81117 }
@@ -87,14 +123,22 @@ function googleScholarMeta(
87123 ) ;
88124 }
89125
90- if ( csl . issued ) {
91- write ( "citation_publication_date" , cslDateToEDTFDate ( csl . issued ) ) ;
126+ if ( extras [ kPdfUrl ] ) {
127+ write ( "citation_pdf_url" , extras [ kPdfUrl ] ) ;
128+ }
129+
130+ if ( extras [ kAbstractUrl ] ) {
131+ write ( "citation_abstract_html_url" , extras [ kAbstractUrl ] ) ;
92132 }
93133
94134 if ( csl . issue ) {
95135 write ( "citation_issue" , csl . issue ) ;
96136 }
97137
138+ if ( csl . DOI ) {
139+ write ( "citation_doi" , csl . DOI ) ;
140+ }
141+
98142 if ( csl . ISBN ) {
99143 write ( "citation_isbn" , csl . ISBN ) ;
100144 }
@@ -103,10 +147,22 @@ function googleScholarMeta(
103147 write ( "citation_issn" , csl . ISSN ) ;
104148 }
105149
150+ if ( extras [ kEIssn ] ) {
151+ write ( "citation_eissn" , extras [ kEIssn ] ) ;
152+ }
153+
154+ if ( csl . PMID ) {
155+ write ( "citation_pmid" , csl . PMID ) ;
156+ }
157+
106158 if ( csl . volume ) {
107159 write ( "citation_volume" , csl . volume ) ;
108160 }
109161
162+ if ( csl . language ) {
163+ write ( "citation_language" , csl . language ) ;
164+ }
165+
110166 if ( csl [ "page-first" ] ) {
111167 write ( "citation_firstpage" , csl [ "page-first" ] ) ;
112168 }
@@ -117,9 +173,17 @@ function googleScholarMeta(
117173
118174 const type = csl . type ;
119175 if ( type === "paper-conference" ) {
120- write ( "citation_conference_title" , csl [ "container-title" ] ) ;
176+ if ( csl [ "container-title" ] ) {
177+ write ( "citation_conference_title" , csl [ "container-title" ] ) ;
178+ }
179+
180+ if ( csl . publisher ) {
181+ write ( "citation_conference" , csl . publisher ) ;
182+ }
121183 } else if ( type === "thesis" ) {
122- write ( "citation_dissertation_institution" , csl . publisher ) ;
184+ if ( csl . publisher ) {
185+ write ( "citation_dissertation_institution" , csl . publisher ) ;
186+ }
123187 } else if ( type === "report" ) {
124188 if ( csl . publisher ) {
125189 write (
@@ -133,8 +197,28 @@ function googleScholarMeta(
133197 csl . number ,
134198 ) ;
135199 }
200+ } else if ( type === "book" ) {
201+ if ( csl [ "container-title" ] ) {
202+ write ( "citation_book_title" , csl [ "container-title" ] ) ;
203+ }
204+ } else if ( type === "chapter" ) {
205+ write ( "citation_inbook_title" , csl [ "container-title" ] ) ;
136206 } else {
137- write ( "citation_journal_title" , csl [ "container-title" ] ) ;
207+ if ( csl [ "container-title" ] ) {
208+ write ( "citation_journal_title" , csl [ "container-title" ] ) ;
209+ }
210+
211+ if ( csl [ "container-title-short" ] ) {
212+ write ( "citation_journal_abbrev" , csl [ "container-title-short" ] ) ;
213+ }
214+
215+ if ( csl . publisher ) {
216+ write ( "citation_publisher" , csl . publisher ) ;
217+ }
218+ }
219+
220+ if ( csl [ "collection-title" ] ) {
221+ write ( "citation_series_title" , csl [ "collection-title" ] ) ;
138222 }
139223
140224 return scholarMeta ;
@@ -149,7 +233,7 @@ async function googleScholarReferences(input: string, format: Format) {
149233
150234 if ( references ) {
151235 references . forEach ( ( reference ) => {
152- const refMetas = googleScholarMeta ( reference ) ;
236+ const refMetas = googleScholarMeta ( reference , { } ) ;
153237 const metaStrs = refMetas . map ( ( refMeta ) => {
154238 return `${ refMeta . name } =${ refMeta . content } ;` ;
155239 } ) ;
0 commit comments