From 83a02af58834f8779230f5a9dcc3ee0d3bc40f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Dur=C3=A1n=20=28midudev=29?= Date: Wed, 20 May 2026 12:00:35 +0200 Subject: [PATCH] fix(jb): ocultar celdas iniciales en el HTML Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- jb/build.sh | 12 ++++++++---- jb/prep_notebooks.py | 7 ++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/jb/build.sh b/jb/build.sh index 860b87d4..6a6d88db 100755 --- a/jb/build.sh +++ b/jb/build.sh @@ -4,16 +4,20 @@ set -euo pipefail # Build the Jupyter book version cd "$(dirname "$0")" -# Link the translated notebooks into the Jupyter Book source directory. +# Copy the translated notebooks into the Jupyter Book source directory so +# prep_notebooks.py can add build-only metadata without modifying originals. for notebook in ../chapters/chap[01][0-9]*.ipynb; do target="$(basename "$notebook")" - if [ -e "$target" ] && [ ! -L "$target" ]; then - echo "Refusing to replace existing non-symlink: $target" >&2 + if [ -e "$target" ] && [ ! -f "$target" ] && [ ! -L "$target" ]; then + echo "Refusing to replace existing non-file: $target" >&2 exit 1 fi - ln -sfn "$notebook" "$target" + rm -f "$target" + cp "$notebook" "$target" done +python3 prep_notebooks.py + if command -v jupyter-book >/dev/null 2>&1; then jupyter_book_cmd="jupyter-book" else diff --git a/jb/prep_notebooks.py b/jb/prep_notebooks.py index 514949d0..86a66aa3 100644 --- a/jb/prep_notebooks.py +++ b/jb/prep_notebooks.py @@ -6,10 +6,15 @@ def process_cell(cell): # get tags tags = cell['metadata'].get('tags', []) - # add hide-cell tag to solutions if cell['cell_type'] == 'code': source = cell['source'] + if 'def download(url):' in source and 'import thinkpython' in source: + tags = cell['metadata'].setdefault('tags', []) + for tag in ['remove-cell', 'keep']: + if tag not in tags: + tags.append(tag) + # remove solutions if source.startswith('# Solution') or 'solution' in tags: cell['source'] = []