From d606713b6b95cf6586621a713b84fd428b39a3d0 Mon Sep 17 00:00:00 2001 From: hoangvv Date: Fri, 28 Feb 2025 12:28:07 +0700 Subject: [PATCH] update --- conf.py | 1 + config.yaml | 1 - convert2md.sh | 28 ++++++++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/conf.py b/conf.py index 049d4a154..0299ebdb9 100644 --- a/conf.py +++ b/conf.py @@ -206,6 +206,7 @@ extensions = [ # Strange html domain logic used in memento pages "html_domain", "myst_parser", + "sphinx-design", ] myst_enable_extensions = [ diff --git a/config.yaml b/config.yaml index 635d357eb..26cc7f0f8 100644 --- a/config.yaml +++ b/config.yaml @@ -31,7 +31,6 @@ default_conversion: parse_all conversions: docutils.parsers.rst.directives.images.image: parse_all sphinx.directives.patches.ListTable: parse_all # For tables if needed - colon_fences.directives.card: parse_all extensions: - sphinx.ext.intersphinx - sphinx.ext.todo diff --git a/convert2md.sh b/convert2md.sh index dc0d37d03..cb7027f4e 100755 --- a/convert2md.sh +++ b/convert2md.sh @@ -9,7 +9,8 @@ SOURCE_DIR=$(realpath "$1") # Normalize source path readonly TARGET_DIR="$2" readonly TEMP_ERROR=$(mktemp) readonly LOG_FILE="/tmp/convert2md_$$.log" -trap 'rm -f "$TEMP_ERROR" "$LOG_FILE"' EXIT +readonly UNPROCESSED_FILE="/tmp/unprocessed_$$.txt" +trap 'rm -f "$TEMP_ERROR" "$LOG_FILE" "$UNPROCESSED_FILE"' EXIT validate_inputs() { [[ ! -d "$SOURCE_DIR" ]] && { echo "Error: Source directory '$SOURCE_DIR' does not exist." >&2; exit 1; } @@ -23,11 +24,12 @@ process_rst_file() { local md_file_name="${relative_path%.rst}.md" local target_file="$TARGET_DIR/$md_file_name" local target_dir=$(dirname "$target_file") - mkdir -p "$target_dir" || { echo "Error: Could not create '$target_dir' for '$rst_file'" >&2; return 1; } + mkdir -p "$target_dir" || { echo "Error: Could not create '$target_dir' for '$rst_file'" >&2; echo "$rst_file" >> "$UNPROCESSED_FILE"; return 1; } if rst2myst stream --config config.yaml "$rst_file" > "$target_file" 2>>"$TEMP_ERROR"; then # Replace 'rst-class' with 'container' and '.rst' with '.md' in content sed -i 's/rst-class/container/g; s/\.rst/.md/g' "$target_file" 2>>"$TEMP_ERROR" || { echo "Error: Failed to modify content of '$target_file'" >&2 + echo "$rst_file" >> "$UNPROCESSED_FILE" return 1 } echo "Converted: $rst_file -> $target_file" | tee -a "$LOG_FILE" @@ -35,6 +37,7 @@ process_rst_file() { else echo "Failed to convert: $rst_file" >&2 cat "$TEMP_ERROR" >&2 + echo "$rst_file" >> "$UNPROCESSED_FILE" return 1 fi } @@ -48,12 +51,14 @@ copy_non_rst_file() { # Replace 'rst-class' with 'container' and '.rst' with '.md' in content sed -i 's/rst-class/container/g; s/\.rst/.md/g' "$target_file" 2>>"$TEMP_ERROR" || { echo "Error: Failed to modify content of '$target_file'" >&2 + echo "$file" >> "$UNPROCESSED_FILE" return 1 } echo "Copied: $file -> $target_file" | tee -a "$LOG_FILE" return 0 } || { echo "Failed to copy: $file" >&2 + echo "$file" >> "$UNPROCESSED_FILE" return 1 } } @@ -69,9 +74,12 @@ main() { printf '%s\n' "${RST_FILES[@]}" | sed 's/^/RST: /' >> "$LOG_FILE" printf '%s\n' "${NON_RST_FILES[@]}" | sed 's/^/Non-RST: /' >> "$LOG_FILE" + # Initialize unprocessed file list with all found files + printf '%s\n' "${RST_FILES[@]}" "${NON_RST_FILES[@]}" > "$UNPROCESSED_FILE" + local parallel_jobs=$(( $(nproc) / 2 )) export -f process_rst_file copy_non_rst_file - export SOURCE_DIR TARGET_DIR TEMP_ERROR LOG_FILE + export SOURCE_DIR TARGET_DIR TEMP_ERROR LOG_FILE UNPROCESSED_FILE # Process RST files printf '%s\0' "${RST_FILES[@]}" | xargs -0 -P "$parallel_jobs" -I {} bash -c 'process_rst_file "{}"' || { @@ -93,6 +101,18 @@ main() { echo "RST files failed: $failed" | tee -a "$LOG_FILE" echo "Non-RST files copied: $copied" | tee -a "$LOG_FILE" + # List unprocessed files (those still in UNPROCESSED_FILE after processing) + if [[ -s "$UNPROCESSED_FILE" ]]; then + echo "Files not processed:" | tee -a "$LOG_FILE" + cat "$UNPROCESSED_FILE" | while IFS= read -r file; do + echo " $file" | tee -a "$LOG_FILE" + done + echo "Note: Some files were not processed. See above list and $LOG_FILE for details." >&2 + exit 1 + else + echo "All files processed successfully." | tee -a "$LOG_FILE" + fi + if [[ ${#RST_FILES[@]} -ne $((successful + failed)) ]]; then echo "Error: ${#RST_FILES[@]} RST files found, but only $((successful + failed)) processed!" >&2 exit 1 @@ -100,4 +120,4 @@ main() { [[ $failed -gt 0 ]] && { echo "Note: $failed RST conversions failed. See $LOG_FILE." >&2; exit 1; } } -main "$@" \ No newline at end of file +main "$@" \ No newline at end of file