Skip to content

Commit 72cb362

Browse files
committed
feat(doc): 📝 add CITATION file
Add CITATION.cff and update init script for metadata Introduces a CITATION.cff file to provide citation metadata for the project, adhering to the citation-file-format standard. Enhances the `init` script to support customizable project title and author details, enabling dynamic updates to metadata files like LICENSE and CITATION. Improves maintainability by refactoring file reading logic into a reusable function and adding support for resetting the citation file template.
1 parent ffc23e7 commit 72cb362

File tree

7 files changed

+85
-13
lines changed

7 files changed

+85
-13
lines changed

.cspell.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"version": "0.2",
33
"language": "en",
44
"words": [
5+
"djmaxus",
6+
"Elizarev",
7+
"Maksim",
8+
"ORCID",
59
"ruleset",
610
"Rulesets",
711
"Simulink"

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ README.md export-ignore
2424
version.txt export-ignore
2525
test.m export-ignore
2626
.gitignore export-ignore
27+
CITATION.cff export-ignore

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
"action-patch",
99
"init"
1010
],
11+
"yaml.schemas": {
12+
"https://raw.githubusercontent.com/citation-file-format/citation-file-format/main/schema.json": [
13+
"CITATION.cff"
14+
]
15+
}
1116
}

CITATION.cff

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# https://github.com/citation-file-format/citation-file-format
2+
cff-version: 1.2.0
3+
type: software
4+
message: >-
5+
If you use this software,
6+
please put the copyright NOTICE.txt in your developments
7+
and cite it using metadata in this file.
8+
# doi:
9+
title: "Template GitHub repository for open-source MATLAB"
10+
authors:
11+
- &djmaxus
12+
family-names: Elizarev
13+
given-names: Maksim
14+
alias: djmaxus
15+
orcid: "https://orcid.org/0000-0002-5279-2877"
16+
website: "https://djmaxus.dev"
17+
contact:
18+
- *djmaxus
19+
keywords:
20+
- MATLAB
21+
- Template repository
22+
- CI/CD
23+
- Semantic Versioning
24+
- License
25+
- Release automation
26+
- Github Actions
27+
- github.io page
28+
license: BSD-3-Clause
29+
repository-code: "https://github.com/djmaxus/matlab-repo-init"
30+
url: "https://matlab-template.djmaxus.dev"
31+
abstract: "Wiki: https://github.com/djmaxus/matlab-repo-init/wiki"

CITATION.cff.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# https://github.com/citation-file-format/citation-file-format
2+
cff-version: 1.2.0
3+
type: software
4+
message: >-
5+
If you use this software,
6+
please put the copyright NOTICE.txt in your developments
7+
and cite it using metadata in this file.
8+
# doi:

init.m

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [] = init(year,full_name,args)
1+
function [] = init(year,first_name,last_name,project_title,args)
22
% Main initialization script
33
%
44
% BSD 3-Clause License
@@ -31,7 +31,9 @@
3131
% OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232
arguments
3333
year (1,1) int32
34-
full_name char
34+
first_name char
35+
last_name char
36+
project_title char
3537
args.self_delete (1,1) logical = true;
3638
args.reset_test (1,1) logical = true;
3739
end
@@ -46,7 +48,7 @@
4648
delete_file('version.txt');
4749

4850
reset_file('README.md', ...
49-
"# README\n\n" + ...
51+
"# " + project_title + "\n\n" + ...
5052
"![CI](../../actions/workflows/ci.yml/badge.svg?branch=main)\n\n"+...
5153
"## Source Template Repository\n\n"+...
5254
"Generated from matlab-repo-init\n\n"+...
@@ -71,12 +73,16 @@
7173
'ignoreWords',[]);
7274
reset_file('.cspell.json',jsonencode(cspell_default,PrettyPrint=true)+"\n");
7375

74-
rmdir('.vscode','s');
75-
rmdir('.github/actions','s');
76+
rmdir('.vscode','s'); % TODO keep cff schema in settings
77+
rmdir('.github/actions','s'); % TODO add printed notification
7678

7779
% Set license details
80+
full_name = [first_name, ' ', last_name];
7881
set_license('LICENSE',year,full_name);
7982

83+
% CITATION.cff
84+
reset_cff(first_name,last_name,project_title);
85+
8086
if ~args.self_delete
8187
return;
8288
end
@@ -108,24 +114,41 @@ function reset_file(name,lines)
108114
function set_license(file_name,year,full_name)
109115
full_file = fullfile(pwd, file_name);
110116

111-
[fid, err_msg] = fopen(full_file,'r');
112-
if fid == -1
113-
error(['Could not open ', name,' for reading: ',err_msg]);
114-
end
115-
license_text=fread(fid,'*char')';
116-
fclose(fid);
117+
license_text=read_to_char(file_name);
117118

118119
upd_license_text = regexprep(license_text,'Copyright \(c\) (.*?)\n', ...
119120
['Copyright (c) ',num2str(year),', ', full_name,'\n']);
120121

121122
[fid, err_msg] = fopen(full_file,'w');
122123
if fid == -1
123-
error(['Could not open ', name,' for writing: ',err_msg]);
124+
error(['Could not open ', file_name,' for writing: ',err_msg]);
124125
end
125126
fprintf(fid,'%s',upd_license_text);
126127
fclose(fid);
127128
end
128129

130+
function reset_cff(first_name,last_name,project_title)
131+
cff_template = read_to_char('CITATION.cff.template');
132+
delete_file('CITATION.cff.template');
133+
134+
reset_file('CITATION.cff', cff_template + ...
135+
"title: """ + project_title + """\n" + ...
136+
"authors:\n" + ...
137+
" - family-names: " + last_name + "\n" + ...
138+
" given-names: " + first_name + "\n"...
139+
);
140+
end
141+
142+
function read_char = read_to_char(file_name)
143+
full_file = fullfile(pwd, file_name);
144+
[fid, err_msg] = fopen(full_file,'r');
145+
if fid == -1
146+
error(['Could not open ', file_name,' for reading: ',err_msg]);
147+
end
148+
read_char = fread(fid,'*char')';
149+
fclose(fid);
150+
end
151+
129152
function print_info()
130153
[fid, ~] = fopen('version.txt','r');
131154
version_str=fread(fid,'*char')';

test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
init(1984, 'George Orwell', self_delete=false, reset_test=false);
1+
init(1984, 'George', 'Orwell', '1984', self_delete=false, reset_test=false);

0 commit comments

Comments
 (0)