Preview: myscript.sh
Size: 2.17 KB
/var/www/nea-dev.wpress.dk/httpdocs/wp-content/plugins/myscript.sh
#!/bin/bash
# Define base paths
BLOCKS_PATH="nea-custom-acf-blocks/blocks"
# Array of block slugs
BLOCKS=(
"2-up-sponsored-content-cards"
"accordion"
"button"
"cta-column-width"
"cta-full-width"
"featured-content-area"
"generic-hero"
"horizontal-text-icon-cards"
"image-beside-text"
"image-gallery"
"image-with-caption"
"link-list"
"related-content"
"rich-text"
"simple-cards-with-image"
"spotify-embed"
"tags-list"
"text-icon-cards"
"vertical-cards"
"video-embed"
)
# Create necessary directories and files
# Function to convert slug to title case
slug_to_title_case() {
echo "$1" | sed -E 's/-/ /g' | awk '{for (i=1;i<=NF;++i) $i=toupper(substr($i,1,1)) tolower(substr($i,2))}1'
}
# Create necessary directories and files
for BLOCK in "${BLOCKS[@]}"; do
BLOCK_DIR="$BLOCKS_PATH/$BLOCK"
mkdir -p "$BLOCK_DIR"
# Convert block name to title case
BLOCK_TITLE=$(slug_to_title_case "$BLOCK")
# Create render.php file
RENDER_FILE="$BLOCK_DIR/render.php"
if [[ ! -f "$RENDER_FILE" ]]; then
echo "<?php" > "$RENDER_FILE"
echo "// Render template for $BLOCK block" >> "$RENDER_FILE"
fi
# Create block.json file
JSON_FILE="$BLOCK_DIR/block.json"
if [[ ! -f "$JSON_FILE" ]]; then
cat <<EOL > "$JSON_FILE"
{
"name": "acf/$BLOCK",
"title": "$BLOCK_TITLE",
"description": "A custom block to display $BLOCK_TITLE.",
"category": "Nea Custom block",
"icon": "list-view",
"keywords": ["$BLOCK_TITLE"],
"acf": {
"mode": "preview",
"renderTemplate": "render.php"
},
"supports": {
"align": true
},
"example": {
"attributes": {
"mode": "preview",
"data": {
"title": "Sample $BLOCK_TITLE Title",
"content": "Sample $BLOCK_TITLE content that can be toggled."
}
}
}
}
EOL
fi
# Create CSS file
CSS_FILE="$BLOCK_DIR/style.css"
if [[ ! -f "$CSS_FILE" ]]; then
echo "/* Styles for $BLOCK_TITLE block */" > "$CSS_FILE"
fi
done
echo "ACF block folders and files created successfully."
Directory Contents
Dirs: 38 × Files: 4