-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/mila/blog social preview (#481)
* pictures script * wip preview image processing * universal image processign script * bash for generating preview images * add CI script * do not force the push --------- Co-authored-by: generall <[email protected]>
- Loading branch information
Showing
9 changed files
with
219 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: update-blog-preview-images | ||
on: | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Run a script | ||
run: | | ||
ADD_TO_GIT=true bash -x automation/gen-all-blogs-previews.sh | ||
if [[ `git status --porcelain` ]]; then | ||
# Changes | ||
echo "Changes detected" | ||
else | ||
# No changes | ||
echo "No changes detected" | ||
exit 0 | ||
fi | ||
git config --global user.name 'qdrant' | ||
git config --global user.email '[email protected]' | ||
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY | ||
git checkout $GITHUB_HEAD_REF | ||
git commit -am "update blog preview images" && git push || true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# directory of the current script | ||
|
||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
|
||
PATH_TO_BLOGS="$DIR/../qdrant-landing/content/blog" | ||
|
||
STATIC_FOLDER=$(realpath "$DIR/../qdrant-landing/static") | ||
|
||
|
||
function get_value_from_md() { | ||
local key=$1 | ||
local file=$2 | ||
local value=$(grep -m 1 "^$key:" "$file" | sed "s/^$key: //") | ||
echo "$value" | ||
} | ||
|
||
|
||
function process_blog() { | ||
echo "-----" | ||
|
||
echo "Processing $1 file..." | ||
|
||
# Check if draft | ||
DRAFT=$(get_value_from_md "draft" "$1") | ||
|
||
if [ "$DRAFT" == "true" ]; then | ||
echo "Draft. Skipping" | ||
return | ||
fi | ||
|
||
SLUG=$(get_value_from_md "slug" "$1") | ||
|
||
if [ -z "$SLUG" ]; then | ||
SLUG=$(basename "$1" | sed 's/\.md$//') | ||
fi | ||
|
||
echo "Slug: $SLUG" | ||
|
||
IMAGE_KEY="preview_image" # ToDo: change to generic image key | ||
|
||
SOURCE_IMAGE_PATH=$(get_value_from_md "${IMAGE_KEY}" "$1") | ||
|
||
if [ -z "$SOURCE_IMAGE_PATH" ]; then | ||
echo "No preview image for $1" | ||
return | ||
fi | ||
|
||
FULL_IMAGE_PATH="${STATIC_FOLDER}/${SOURCE_IMAGE_PATH}" | ||
|
||
echo "Source image path: $FULL_IMAGE_PATH" | ||
|
||
PATH_TO_IMAGE="${FULL_IMAGE_PATH}" \ | ||
bash ${DIR}/process-blog-img.sh "$FULL_IMAGE_PATH" "$SLUG" | ||
} | ||
|
||
|
||
|
||
for f in $PATH_TO_BLOGS/*.md; do | ||
# Absolute path to the file | ||
|
||
abs_path=$(realpath "$f") | ||
|
||
|
||
process_blog "$abs_path" | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ -z "$1" ]; then | ||
echo "Please provide a path to the image" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "Please provide an blog slug" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -f "$1" ]; then | ||
echo "File $1 does not exist" | ||
exit 1 | ||
fi | ||
|
||
# Get the directory of the script | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" | ||
|
||
|
||
|
||
PATH_TO_IMAGE=$1 \ | ||
STATIC_DIRECTORY_NAME="./qdrant-landing/static/blog_data/${2}" \ | ||
SOCIAL_PREVIEW_RESOLUTION="1200x630" \ | ||
TITLE_RESOLUTION="916x515" \ | ||
PREVIEW_RESOLUTION="350x201" \ | ||
bash -x ${DIR}/process-img.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/bin/bash | ||
|
||
# This script is used to process images for content suitable for social networks | ||
|
||
set -e | ||
|
||
|
||
# Example usage | ||
# | ||
# | ||
# PATH_TO_IMAGE="./qdrant-landing/static/blog_data/qdrant-v-1-7/preview.png" | ||
# STATIC_DIRECTORY_NAME="./qdrant-landing/static/blog_data/qdrant-v-1-7" | ||
|
||
|
||
PATH_TO_IMAGE=${PATH_TO_IMAGE:-""} | ||
STATIC_DIRECTORY_NAME=${STATIC_DIRECTORY_NAME:-""} | ||
|
||
|
||
SOCIAL_PREVIEW_RESOLUTION=${SOCIAL_PREVIEW_RESOLUTION:-"1200x630"} | ||
TITLE_RESOLUTION=${TITLE_RESOLUTION:-"898x300"} | ||
PREVIEW_RESOLUTION=${PREVIEW_RESOLUTION:-"530x145"} | ||
|
||
ALLOW_OVERWRITE=${ALLOW_OVERWRITE:-"false"} | ||
|
||
|
||
if [ -z "$PATH_TO_IMAGE" ]; then | ||
echo "Please provide a path to the image" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$STATIC_DIRECTORY_NAME" ]; then | ||
echo "Please provide an directory name to store images" | ||
exit 1 | ||
fi | ||
|
||
# Check that PATH_TO_IMAGE exists and have a valid extension (png, jpg, jpeg) | ||
if [ ! -f "$PATH_TO_IMAGE" ]; then | ||
echo "File $PATH_TO_IMAGE does not exist" | ||
exit 1 | ||
fi | ||
|
||
if [[ ! "$PATH_TO_IMAGE" =~ \.(png|jpg|jpeg)$ ]]; then | ||
echo "File $PATH_TO_IMAGE has invalid extension. Only png, jpg, jpeg are allowed" | ||
exit 1 | ||
fi | ||
|
||
|
||
IMG_DESTINATION="${STATIC_DIRECTORY_NAME}/preview" | ||
mkdir -p $IMG_DESTINATION | ||
|
||
function check_file_exists() { | ||
local file=$1 | ||
if [ -f "${file}" ] && [ "$ALLOW_OVERWRITE" != "true" ]; then | ||
echo "$file exists. Please remove it or set ALLOW_OVERWRITE=true" | ||
exit 0 | ||
fi | ||
} | ||
|
||
check_file_exists "${IMG_DESTINATION}/social_preview.jpg" | ||
check_file_exists "${IMG_DESTINATION}/title.jpg" | ||
check_file_exists "${IMG_DESTINATION}/preview.jpg" | ||
check_file_exists "${IMG_DESTINATION}/title.webp" | ||
check_file_exists "${IMG_DESTINATION}/preview.webp" | ||
|
||
|
||
convert "${PATH_TO_IMAGE}" -resize "${SOCIAL_PREVIEW_RESOLUTION}^" -gravity center -extent $SOCIAL_PREVIEW_RESOLUTION "${IMG_DESTINATION}/social_preview.jpg"; | ||
convert "${PATH_TO_IMAGE}" -resize "${TITLE_RESOLUTION}^" -gravity center -extent "${TITLE_RESOLUTION}" "${IMG_DESTINATION}/title.jpg"; | ||
convert "${IMG_DESTINATION}/title.jpg" -resize "${PREVIEW_RESOLUTION}^" -gravity center -extent "${PREVIEW_RESOLUTION}" "${IMG_DESTINATION}/preview.jpg"; | ||
|
||
cwebp -q 95 "${IMG_DESTINATION}/title.jpg" -o "${IMG_DESTINATION}/title.webp"; | ||
cwebp -q 95 "${IMG_DESTINATION}/preview.jpg" -o "${IMG_DESTINATION}/preview.webp"; | ||
|
||
ADD_TO_GIT=${ADD_TO_GIT:-"false"} | ||
|
||
if [ "$ADD_TO_GIT" == "true" ]; then | ||
git add "${IMG_DESTINATION}" | ||
fi | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
qdrant-landing/content/blog/new-0-7-update-of-the-qdrant-engine-went-live.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
qdrant-landing/content/blog/qdrant-v-0-6-0-engine-with-grpc-released.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
qdrant-landing/content/blog/v0-8-0-update-of-the-qdrant-engine-was-released.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
qdrant-landing/content/blog/v0-9-0-update-of-the-qdrant-engine-went-live.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters