-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add build support for linking to bibliographical references
- Loading branch information
1 parent
bfa7f4c
commit 3d26e54
Showing
4 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import axios from "axios"; | ||
import { readFile } from "fs/promises"; | ||
import { glob } from "glob"; | ||
import uniq from "lodash-es/uniq"; | ||
|
||
export const biblioPattern = /\[\[([\w-]+)\]\]/g; | ||
|
||
/** Compiles URLs from local biblio + specref for linking in Understanding documents. */ | ||
export async function getBiblio() { | ||
const localBiblio = eval( | ||
(await readFile("biblio.js", "utf8")) | ||
.replace(/^respecConfig\.localBiblio\s*=\s*/, "(") | ||
.replace("};", "})") | ||
); | ||
|
||
const refs: string[] = []; | ||
for (const path of await glob(["guidelines/**/*.html", "understanding/*/*.html"])) { | ||
const content = await readFile(path, "utf8"); | ||
let match; | ||
while ((match = biblioPattern.exec(content))) if (!localBiblio[match[1]]) refs.push(match[1]); | ||
} | ||
const uniqueRefs = uniq(refs); | ||
|
||
const response = await axios.get(`https://api.specref.org/bibrefs?refs=${uniqueRefs.join(",")}`); | ||
const fullBiblio = { | ||
...response.data, | ||
...localBiblio, | ||
}; | ||
|
||
const resolvedRefs = Object.keys(fullBiblio); | ||
const unresolvedRefs = uniqueRefs.filter((ref) => !resolvedRefs.includes(ref)); | ||
if (unresolvedRefs.length) console.warn(`Unresolved biblio refs: ${unresolvedRefs.join(", ")}`); | ||
|
||
return fullBiblio; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters