Skip to content
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

Flatten directory structure #5323

Closed
wants to merge 1 commit into from

Conversation

tarleb
Copy link
Contributor

@tarleb tarleb commented May 8, 2024

No description provided.

@arfon
Copy link
Member

arfon commented Jun 29, 2024

Hey @tarleb – sorry it took me ages to get to this. Is this PR good to merge as far as you're concerned (i.e., flattens all the folders etc.)

@tarleb
Copy link
Contributor Author

tarleb commented Jul 1, 2024 via email

@tarleb
Copy link
Contributor Author

tarleb commented Jul 1, 2024

Re-posting the script via the web interface just to get proper syntax highlighting.

#!/bin/sh
set -e
find . -maxdepth 2 -name media -type d | \
while IFS= read -r media; do
    paper=$(basename ${media%/media*})
    printf 'Processing %s...\n' "$paper"
    find "$media" -type f | while IFS= read -r fullimgpath; do
        # original path relative to JATS file; remove prefix
        imgpath=${fullimgpath#*joss.?????/}
        # image filename
        img=$(basename "$fullimgpath")

        # Regex removing folders from image paths
        printf 'Replacing references to %s\n' "$imgpath"
        regexp="s#xlink:href=\"$imgpath\"#xlink:href=\"$img\"#g"
        sed -i'' -e "$regexp" "$paper"/10.21105."$paper".jats

        # Move image into base dir
        newpath="${paper}/${img}"
        printf 'Renaming %s to %s\n' "$fullimgpath" "$newpath"
        git mv "$fullimgpath" "$newpath"
    done

    printf 'Removing media folder %s\n' "$media"
    rmdir -r "$media"
done

@tarleb
Copy link
Contributor Author

tarleb commented Jul 20, 2024

Closing, new PR will follow

@tarleb tarleb closed this Jul 20, 2024
@tarleb tarleb deleted the flatten-folders branch July 20, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants