diff --git a/README.md b/README.md index 6f4c607..50d1829 100644 --- a/README.md +++ b/README.md @@ -174,6 +174,8 @@ When preparing a release: OpenCite automatically includes GitHub release and source-tree identifiers in `CITATION.cff` when a version and repository URL are present. +Generated `CITATION.cff` files start with a `# Generated with OpenCite (https://imageomics.github.io/OpenCite/) version ` comment. `.zenodo.json` is unchanged because JSON does not support comments. + ## Grants Autofill The Grants field includes one-click suggestions for: diff --git a/src/services/appVersion.js b/src/services/appVersion.js new file mode 100644 index 0000000..f62929c --- /dev/null +++ b/src/services/appVersion.js @@ -0,0 +1,3 @@ +import pkg from '../../package.json' with { type: 'json' }; + +export const APP_VERSION = pkg.version; diff --git a/src/services/citation.js b/src/services/citation.js index aa5b3d0..daac826 100644 --- a/src/services/citation.js +++ b/src/services/citation.js @@ -1,3 +1,5 @@ +import { APP_VERSION } from './appVersion.js'; + export function quoteYAML(value) { return String(value ?? '') .replace(/\\/g, '\\\\') @@ -183,6 +185,7 @@ export function toCitationCff(metadata) { : 'If you find this work helpful in your research, please cite it.'; return [ + `# Generated with OpenCite (https://imageomics.github.io/OpenCite/) version ${APP_VERSION}`, 'abstract: >-', indentBlock(abstractText), 'authors:', diff --git a/tests/services/appVersion.test.js b/tests/services/appVersion.test.js new file mode 100644 index 0000000..1655fd1 --- /dev/null +++ b/tests/services/appVersion.test.js @@ -0,0 +1,25 @@ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import test from 'node:test'; +import { APP_VERSION } from '../../src/services/appVersion.js'; +import { toCitationCff } from '../../src/services/citation.js'; + +const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')); + +test('APP_VERSION is loaded from package.json', () => { + assert.equal(APP_VERSION, pkg.version); +}); + +test('CITATION.cff starts with the OpenCite generation comment', () => { + const cff = toCitationCff({ + title: 'T', + authors: [], + keywords: [], + version: '1.0.0', + license: 'MIT', + }); + assert.equal( + cff.split('\n')[0], + `# Generated with OpenCite (https://imageomics.github.io/OpenCite/) version ${pkg.version}`, + ); +});