Skip to content

Commit

Permalink
Add server scripts to repo (closes #4302) (#4303)
Browse files Browse the repository at this point in the history
* Add existing server scripts
* Update thumbnail script to update any time the PDF is newer than the thumbnail
  • Loading branch information
mjpost authored Jan 2, 2025
1 parent 7dfd2fb commit 6ecf1e3
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
50 changes: 50 additions & 0 deletions bin/build-thumbnails.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Requires $PREVIEW_DIR to be set.
#!/bin/bash

# Builds thumbnails for files. There are two use cases:
# 1. If no arguments are supplied, will do so for all Anthology files.
#
# Example:
#
# build_thumbnails.sh
#
# 2. If two arguments are supplied, will read the first file and write
# to the second.
#
# Example:
#
# build_thumbnails ~/anthology-files/pdf/W/W19/W19-5605.pdf \
# ~/anthology-files/thumb/W/W19/W19-5606-thumb.pdf
#
# The first use case recurses to the second.

# The base directory of Anthology object files (contains pdf/ and thumb/)
ANTHOLOGYFILES=$HOME/anthology-files

# Where to write thumbnails
THUMBDIR=${ANTHOLOGYFILES}/thumb

# Thumbnail dimensions
DIM=600

if [[ -z $2 ]]; then
[[ ! -e $THUMBDIR ]] && mkdir -p $THUMBDIR

inputdir=${1:-$ANTHOLOGYFILES/pdf/}
echo "Looking for PDFs in $inputdir..."
for pdf in $(find $inputdir -type f -name '*.pdf'); do
outfile=$THUMBDIR/$(basename $pdf .pdf).jpg
# update if outfile doesn't exist or has an older timestamp
if [[ ! -e $outfile || $pdf -nt $outfile ]]; then
echo "$pdf -> $outfile"
bash $0 $pdf $outfile
fi
done
else
pdffile=$1
outfile=$2

cmd="convert $pdffile[0] -background white -flatten -resize x${DIM}^ -gravity North -crop ${DIM}x${DIM}+0+10 -colorspace Gray $outfile"
# echo $cmd
$cmd
fi
17 changes: 17 additions & 0 deletions bin/remove-previews.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Removes previews of branches that have been deleted on Github.

export PREVIEW_DIR="/var/www/preview.aclanthology.org"

set -u

if [[ -d $PREVIEW_DIR ]]; then
cd $PREVIEW_DIR
for branch in *; do
if ! curl -s -o /dev/null -f https://github.com/acl-org/acl-anthology/tree/$branch; then
echo "* Removing Anthology preview $branch"
rm -rf "./$branch"
fi
done
fi

0 comments on commit 6ecf1e3

Please sign in to comment.