Skip to content

Commit 1e72e0a

Browse files
committed
support for 'nocite' in book bibliography
1 parent 3201b11 commit 1e72e0a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/config/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ export const kServer = "server";
423423
export const kPageTitle = "pagetitle";
424424
export const kTitlePrefix = "title-prefix";
425425
export const kCsl = "csl";
426+
export const kNoCite = "nocite";
426427
export const kCss = "css";
427428
export const kBibliography = "bibliography";
428429
export const kHeaderIncludes = "header-includes";

src/project/types/book/book-bibliography.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { pathWithForwardSlashes } from "../../../core/path.ts";
1818
import { execProcess } from "../../../core/process.ts";
1919
import { pandocBinaryPath } from "../../../core/resources.ts";
2020

21-
import { kBibliography, kCsl } from "../../../config/constants.ts";
21+
import { kBibliography, kCsl, kNoCite } from "../../../config/constants.ts";
2222
import { Metadata } from "../../../config/types.ts";
2323

2424
import { kProjectRender, ProjectContext } from "../../types.ts";
@@ -53,10 +53,13 @@ export async function bookBibliographyPostRender(
5353

5454
// bail if there is no target refs file
5555
if (refsHtml && outputFiles.length > 0) {
56-
// determine the bibliography and the csl based on the first file
56+
// determine the bibliography, csl, and nocite based on the first file
5757
const file = outputFiles[0];
5858
const bibliography = file.format.metadata[kBibliography] as string[];
5959
const csl = file.format.metadata[kCsl];
60+
const nocite = typeof (file.format.metadata[kNoCite]) === "string"
61+
? file.format.metadata[kNoCite] as string
62+
: undefined;
6063
if (!bibliography) {
6164
return;
6265
}
@@ -136,6 +139,13 @@ export async function bookBibliographyPostRender(
136139
}
137140
}
138141

142+
// include citeids from nocite
143+
if (nocite) {
144+
citeIds.push(
145+
...nocite.split(",").map((x) => x.trim().replace(/^@/, "")),
146+
);
147+
}
148+
139149
if (citeIds.length > 0) {
140150
// either append this to the end of the references file or replace an explicit
141151
// refs div in the references file
@@ -179,8 +189,8 @@ async function generateBibliographyHTML(
179189

180190
// make the aggregated bibliography
181191
const yaml: Metadata = {
182-
bibliography: biblioPaths,
183-
nocite: ld.uniq(citeIds).map((id) => "@" + id).join(", "),
192+
[kBibliography]: biblioPaths,
193+
[kNoCite]: ld.uniq(citeIds).map((id) => "@" + id).join(", "),
184194
};
185195
if (csl) {
186196
yaml[kCsl] = csl;

0 commit comments

Comments
 (0)