From e4edb880d000325b6a4b792a902426e658673a61 Mon Sep 17 00:00:00 2001 From: cchang-vassar <79338042+cchang-vassar@users.noreply.github.com> Date: Mon, 26 Aug 2024 12:45:30 -0400 Subject: [PATCH] merge apa and bibtex citation json --- .../src/build-citation.js | 19 ++++--------------- templates/extension-template-js/src/index.js | 7 +------ .../src/build-citation.js | 17 +++-------------- templates/extension-template-ts/src/index.ts | 7 +------ .../plugin-template-js/src/build-citation.js | 17 +++-------------- templates/plugin-template-js/src/index.js | 7 +------ .../plugin-template-ts/src/build-citation.js | 17 +++-------------- templates/plugin-template-ts/src/index.ts | 7 +------ 8 files changed, 17 insertions(+), 81 deletions(-) diff --git a/templates/extension-template-js/src/build-citation.js b/templates/extension-template-js/src/build-citation.js index 72fb8900..131d6e96 100644 --- a/templates/extension-template-js/src/build-citation.js +++ b/templates/extension-template-js/src/build-citation.js @@ -6,10 +6,9 @@ const { Cite } = require("@citation-js/core"); const srcDir = __dirname; const indexFilePath = path.join(srcDir, "index.js"); -const updateCitations = (indexFilePath, apaCitation, bibtexCitation) => { +const updateCitations = (indexFilePath, citationJson) => { let fileContent = fs.readFileSync(indexFilePath, "utf-8"); - fileContent = fileContent.replace(/`{apaJson}`/g, apaCitation); - fileContent = fileContent.replace(/`{bibtexJson}`/g, bibtexCitation); + fileContent = fileContent.replace(/`{citationJson}`/g, citationJson); fs.writeFileSync(indexFilePath, fileContent, "utf-8"); }; @@ -18,25 +17,15 @@ function cffToJson() { const cffFilePath = path.join(templateDir, "CITATION.cff"); let cffCitation = fs.readFileSync(cffFilePath, "utf-8").toString(); Cite.async(cffCitation).then((data) => { - const apaJson = JSON.stringify( + const citationJson = JSON.stringify( data.format("data", { format: "object", - template: "citation-apa", lang: "en-US", }), null, 2 ); - const bibtexJson = JSON.stringify( - data.format("data", { - format: "object", - template: "citation-bibtex", - lang: "en-US", - }), - null, - 2 - ); - updateCitations(indexFilePath, apaJson, bibtexJson); + updateCitations(indexFilePath, citationJson); }); } diff --git a/templates/extension-template-js/src/index.js b/templates/extension-template-js/src/index.js index a0200b77..e70e8a93 100644 --- a/templates/extension-template-js/src/index.js +++ b/templates/extension-template-js/src/index.js @@ -45,12 +45,7 @@ var _globalName_ = (function (jspsych) { type: ParameterType.STRING, }, }, - citations: { - /** APA citation JSON */ - apa: `{apaJson}`, - /** BibTeX citation JSON */ - bibtex: `{bibtexJson}`, - }, + citation: `{citationJson}`, }; return ExtensionNameExtension; diff --git a/templates/extension-template-ts/src/build-citation.js b/templates/extension-template-ts/src/build-citation.js index d5f9ff8e..7f466028 100644 --- a/templates/extension-template-ts/src/build-citation.js +++ b/templates/extension-template-ts/src/build-citation.js @@ -9,10 +9,9 @@ import { Cite } from "@citation-js/core"; const srcDir = path.dirname(fileURLToPath(import.meta.url)); const indexFilePath = path.join(srcDir, "index.js"); -const updateCitations = (indexFilePath, apaCitation, bibtexCitation) => { +const updateCitations = (indexFilePath, citationJson) => { let fileContent = fs.readFileSync(indexFilePath, "utf-8"); - fileContent = fileContent.replace(/`{apaJson}`/g, apaCitation); - fileContent = fileContent.replace(/`{bibtexJson}`/g, bibtexCitation); + fileContent = fileContent.replace(/`{citationJson}`/g, citationJson); fs.writeFileSync(indexFilePath, fileContent, "utf-8"); }; @@ -24,22 +23,12 @@ function cffToJson() { const apaJson = JSON.stringify( data.format("data", { format: "object", - template: "citation-apa", lang: "en-US", }), null, 2 ); - const bibtexJson = JSON.stringify( - data.format("data", { - format: "object", - template: "citation-bibtex", - lang: "en-US", - }), - null, - 2 - ); - updateCitations(indexFilePath, apaJson, bibtexJson); + updateCitations(indexFilePath, citationJson); }); } diff --git a/templates/extension-template-ts/src/index.ts b/templates/extension-template-ts/src/index.ts index 9e0e9b7f..274a9f96 100644 --- a/templates/extension-template-ts/src/index.ts +++ b/templates/extension-template-ts/src/index.ts @@ -32,12 +32,7 @@ class ExtensionNameExtension implements JsPsychExtension { type: ParameterType.STRING, }, }, - citations: { - /** APA citation JSON */ - apa: `{apaJson}`, - /** BibTeX citation JSON */ - bibtex: `{bibtexJson}`, - }, + citation: `{citationJson}`, }; constructor(private jsPsych: JsPsych) {} diff --git a/templates/plugin-template-js/src/build-citation.js b/templates/plugin-template-js/src/build-citation.js index 72fb8900..bde89069 100644 --- a/templates/plugin-template-js/src/build-citation.js +++ b/templates/plugin-template-js/src/build-citation.js @@ -6,10 +6,9 @@ const { Cite } = require("@citation-js/core"); const srcDir = __dirname; const indexFilePath = path.join(srcDir, "index.js"); -const updateCitations = (indexFilePath, apaCitation, bibtexCitation) => { +const updateCitations = (indexFilePath, citationJson) => { let fileContent = fs.readFileSync(indexFilePath, "utf-8"); - fileContent = fileContent.replace(/`{apaJson}`/g, apaCitation); - fileContent = fileContent.replace(/`{bibtexJson}`/g, bibtexCitation); + fileContent = fileContent.replace(/`{citationJson}`/g, citationJson); fs.writeFileSync(indexFilePath, fileContent, "utf-8"); }; @@ -21,22 +20,12 @@ function cffToJson() { const apaJson = JSON.stringify( data.format("data", { format: "object", - template: "citation-apa", lang: "en-US", }), null, 2 ); - const bibtexJson = JSON.stringify( - data.format("data", { - format: "object", - template: "citation-bibtex", - lang: "en-US", - }), - null, - 2 - ); - updateCitations(indexFilePath, apaJson, bibtexJson); + updateCitations(indexFilePath, citationJson); }); } diff --git a/templates/plugin-template-js/src/index.js b/templates/plugin-template-js/src/index.js index f06bebcb..7fe8588f 100644 --- a/templates/plugin-template-js/src/index.js +++ b/templates/plugin-template-js/src/index.js @@ -25,12 +25,7 @@ var _globalName_ = (function (jspsych) { data2: { type: ParameterType.STRING, }, - citations: { - /** APA citation JSON */ - apa: `{apaJson}`, - /** BibTeX citation JSON */ - bibtex: `{bibtexJson}`, - }, + citation: `{citationJson}`, }, }; diff --git a/templates/plugin-template-ts/src/build-citation.js b/templates/plugin-template-ts/src/build-citation.js index 1bb853c3..5c0d235c 100644 --- a/templates/plugin-template-ts/src/build-citation.js +++ b/templates/plugin-template-ts/src/build-citation.js @@ -9,10 +9,9 @@ import { Cite } from "@citation-js/core"; const srcDir = path.dirname(fileURLToPath(import.meta.url)); const indexFilePath = path.join(srcDir, "index.ts"); -const updateCitations = (indexFilePath, apaCitation, bibtexCitation) => { +const updateCitations = (indexFilePath, citationJson) => { let fileContent = fs.readFileSync(indexFilePath, "utf-8"); - fileContent = fileContent.replace(/`{apaJson}`/g, apaCitation); - fileContent = fileContent.replace(/`{bibtexJson}`/g, bibtexCitation); + fileContent = fileContent.replace(/`{citationJson}`/g, citationJson); fs.writeFileSync(indexFilePath, fileContent, "utf-8"); }; @@ -24,22 +23,12 @@ function cffToJson() { const apaJson = JSON.stringify( data.format("data", { format: "object", - template: "citation-apa", lang: "en-US", }), null, 2 ); - const bibtexJson = JSON.stringify( - data.format("data", { - format: "object", - template: "citation-bibtex", - lang: "en-US", - }), - null, - 2 - ); - updateCitations(indexFilePath, apaJson, bibtexJson); + updateCitations(indexFilePath, citationJson); }); } diff --git a/templates/plugin-template-ts/src/index.ts b/templates/plugin-template-ts/src/index.ts index 03196476..309e4c2b 100644 --- a/templates/plugin-template-ts/src/index.ts +++ b/templates/plugin-template-ts/src/index.ts @@ -26,12 +26,7 @@ const info = { data2: { type: ParameterType.STRING, }, - citations: { - /** APA citation JSON */ - apa: `{apaJson}`, - /** BibTeX citation JSON */ - bibtex: `{bibtexJson}`, - }, + citation: `{citationJson}`, }, };