Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/src/project/project-cites.ts
6446 views
1
/*
2
* project-cites.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*/
6
7
import { ensureDirSync, existsSync } from "../deno_ral/fs.ts";
8
9
import { join } from "../deno_ral/path.ts";
10
import { PandocOptions } from "../command/render/types.ts";
11
import { FormatPandoc } from "../config/types.ts";
12
import { projectIsBook } from "./project-shared.ts";
13
14
import { projectScratchPath } from "./project-scratch.ts";
15
16
export const kCitesIndexFile = "cites-index-file";
17
18
const kCiteIndexDir = "cites";
19
20
type CiteIndex = Record<string, string[]>;
21
22
export function citeIndexFilterParams(
23
options: PandocOptions,
24
_defaults?: FormatPandoc,
25
) {
26
if (options.project && projectIsBook(options.project)) {
27
return {
28
[kCitesIndexFile]: citeIndexFile(options.project.dir),
29
};
30
} else {
31
return {};
32
}
33
}
34
35
export function citeIndex(projectDir: string) {
36
const mainIndexFile = citeIndexFile(projectDir);
37
const mainIndex: CiteIndex = existsSync(mainIndexFile)
38
? JSON.parse(Deno.readTextFileSync(mainIndexFile))
39
: {};
40
return mainIndex;
41
}
42
43
function citeIndexFile(projectDir: string) {
44
// read (or create) main index
45
const citesDir = projectScratchPath(projectDir, kCiteIndexDir);
46
ensureDirSync(citesDir);
47
return join(citesDir, "index.json");
48
}
49
50