Skip to content

Commit 4d4b949

Browse files
committed
make validate-yaml work from any dir
1 parent 14eaecd commit 4d4b949

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

_templates/publication-template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Copy this template when adding a new publication to `_data/publications.yml`
2020
arxiv: '2401.12345' # optional - arXiv ID
2121
doi: '10.1234/journal.2024.123456' # strongly recommended
2222
pdf: 'https://journal.com/paper.pdf' # or '/static/pub/lastname_year.pdf'
23-
github: 'deep-mi/repository-name' # optional - relative to github.com
23+
github: 'deep-mi/repository-name' # optional - format: org/repo (no leading slash)
2424
bibtex: '/static/pub/lastname_year.bib'
2525
links: # optional - additional links
2626
- name: 'Project Website'
@@ -51,5 +51,7 @@ Copy this template when adding a new publication to `_data/publications.yml`
5151
- Always include DOI if available
5252
- Bold current and former lab members in author list
5353
- Keep image file size small (max 100KB)
54+
- GitHub format: `'deep-mi/repository-name'` (lowercase org, no leading slash)
55+
- Rendered as: `https://github.com/deep-mi/repository-name`
5456
- Test that all file paths exist before committing
5557

scripts/validate_yaml.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
require 'yaml'
55
require 'date'
66

7+
# Get the project root directory (parent of scripts directory)
8+
PROJECT_ROOT = File.expand_path('..', __dir__)
9+
710
def validate_file(filepath)
811
puts "Validating #{filepath}..."
912

@@ -41,8 +44,8 @@ def validate_members(data, filepath)
4144
end
4245
end
4346

44-
# Check if image file exists
45-
image_path = File.join(File.dirname(__dir__), member['image'])
47+
# Check if image file exists (resolve relative to project root)
48+
image_path = File.expand_path(member['image'], PROJECT_ROOT)
4649
unless File.exist?(image_path)
4750
puts " Warning: Image not found for #{member['name']}: #{member['image']}"
4851
end
@@ -80,12 +83,12 @@ def validate_publications(data, filepath)
8083
raise "Publication #{pub['id']} has invalid year: #{pub['year']}"
8184
end
8285

83-
# Check if files exist
86+
# Check if files exist (resolve relative to project root)
8487
['image', 'bibtex', 'pdf'].each do |file_field|
8588
next unless pub[file_field]
8689
next if pub[file_field].start_with?('http')
8790

88-
file_path = File.join(File.dirname(__dir__), pub[file_field])
91+
file_path = File.expand_path(pub[file_field], PROJECT_ROOT)
8992
unless File.exist?(file_path)
9093
puts " Warning: File not found for #{pub['id']}: #{pub[file_field]}"
9194
end
@@ -96,6 +99,9 @@ def validate_publications(data, filepath)
9699
# Main execution
97100
exit_code = 0
98101

102+
# Change to project root directory to find _data files
103+
Dir.chdir(PROJECT_ROOT)
104+
99105
Dir.glob('_data/*.yml').each do |file|
100106
unless validate_file(file)
101107
exit_code = 1

0 commit comments

Comments
 (0)