Skip to content

Commit

Permalink
merge apa and bibtex citation json
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang committed Aug 26, 2024
1 parent fd49f77 commit e4edb88
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 81 deletions.
19 changes: 4 additions & 15 deletions templates/extension-template-js/src/build-citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand All @@ -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);
});
}

Expand Down
7 changes: 1 addition & 6 deletions templates/extension-template-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 3 additions & 14 deletions templates/extension-template-ts/src/build-citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand All @@ -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);
});
}

Expand Down
7 changes: 1 addition & 6 deletions templates/extension-template-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
17 changes: 3 additions & 14 deletions templates/plugin-template-js/src/build-citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand All @@ -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);
});
}

Expand Down
7 changes: 1 addition & 6 deletions templates/plugin-template-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
},
};

Expand Down
17 changes: 3 additions & 14 deletions templates/plugin-template-ts/src/build-citation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
};

Expand All @@ -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);
});
}

Expand Down
7 changes: 1 addition & 6 deletions templates/plugin-template-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ const info = <const>{
data2: {
type: ParameterType.STRING,
},
citations: {
/** APA citation JSON */
apa: `{apaJson}`,
/** BibTeX citation JSON */
bibtex: `{bibtexJson}`,
},
citation: `{citationJson}`,
},
};

Expand Down

0 comments on commit e4edb88

Please sign in to comment.