-
Notifications
You must be signed in to change notification settings - Fork 160
Move metadata for Jupyter Notebooks to frontmatter #4528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
| first_md_cell = next((item for item in data['cells'] if item['cell_type'] == 'markdown')) | ||
| title_line = next((item for item in first_md_cell['source'] if item.startswith("title:"))) | ||
| return title_line.split("title:", 1)[1].strip() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this in a CI check, this code assumes that we already validated that every notebook has the metadata at the top of the first markdown cell. We could validate every assumption here to make it fully independent, but I wasn't sure if it was overkill. We could do:
def get_notebook_title(path: Path) -> str:
data = json.loads(path.read_text())
try:
first_md_cell = next((item for item in data['cells'] if item['cell_type'] == 'markdown'))
except StopIteration:
raise Exception("Make sure your notebook defined the metadata in a markdown cell!")
if first_md_cell['source'][0] != '---\n':
raise Exception("The metadata must be defined at the top of the first markdown cell!")
try:
title_line = next((item for item in first_md_cell['source'] if item.startswith("title:")))
except StopIteration:
raise Exception("Make sure your notebook has a 'title' metadata!")
title_text = title_line.split("title:", 1)[1].strip()
if not title_text:
raise Exception("Make sure your notebook's 'title' is not empty.")
return title_textAlternatively, maybe just adding a comment is enough? Wdyt?
|
One or more of the following people are relevant to this code:
|
Summary
This PR moves the metadata of every Jupyter notebook to the frontmatter at the top of their first markdown cell. It also tweaks our markdown check to understand the new format.
To migrate all the files, I used the following script that can be used from the
scripts/js/commandsfolder:Script
Commits
startscript to include the support of the new notebook's metadata format.