diff --git a/core/scripts/create-subtheme.sh b/core/scripts/create-subtheme.sh new file mode 100755 index 0000000000..353fe157f5 --- /dev/null +++ b/core/scripts/create-subtheme.sh @@ -0,0 +1,95 @@ +#!/bin/bash +# +# This script creates a sub-theme, with Olivero as base-theme. + +# Check if a valid argument is present, adhering to the machine name rules. +# https://drupal.org/docs/theming-drupal/defining-a-theme-with-an-infoyml-file + +# Check if an argument is present. +if [ -z "$1" ] +then + echo "Please declare a machine name for your sub-theme, for example my_theme" + exit +fi + +# Check if more than one argument is given. +# Also controls for the "It must not contain any spaces." machine name rule. +if [ $# -gt 1 ] +then + echo "Please use only a single argument for the machine name, for example my_theme" + exit +fi + +# It must not exist already. +if [ -d themes/$1 ] +then + echo "themes/$1 already exists on your filesystem ..." + exit +fi + +# It must not be longer than 50 characters. +themename=$1 +if [ ${#themename} -gt 50 ] +then + echo "A theme name must not be longer than 50 characters." + exit +fi + +# Check if characters comply +case $1 in + # It must start with a letter. + ([!abcdefghijklmnopqrstuvwxyz]*) + echo >&2 "A theme name must start with a letter." + exit 1 + ;; + # It must contain only lower-case letters, numbers and underscores. + (*[!abcdefghijklmnopqrstuvwxyz1234567890_]*) + echo >&2 "A theme name must contain only lower-case letters, numbers and underscores." + exit 1 + ;; + # It should not be any of the reserved terms: src, lib, vendor, assets, + # css, files, images, js, misc, templates, includes, fixtures, drupal. + ("src" | "lib" | "vendor" | "assets" | "css" | "files" | "images" | "js" | "misc" | "templates" | "includes" | "fixtures" | "drupal") + echo -e >&2 "A theme name should not be any of the reserved terms (folders in the Drupal distribution): \nsrc, lib, vendor, assets, css, files, images, js, misc, templates, includes, fixtures, drupal." + exit 1 + ;; + (*) + echo "That theme name looks good, continuing ...";; +esac + +# Create the target directory. +mkdir themes/$1 + +# Copy the contents of Olivero recursively. +cp -R core/themes/olivero/subtheme/* themes/$1 + +# Upper case the first letter of theme name, turning "my_theme" into "My_theme". +themename="${themename^}" + +# Replace all underscores with a space, turning "My_theme" into "My theme". +themename=${themename//_/ } + +# Update theme name and machine name in MACHINENAME.info.yml. +sed -i "s/THEMENAME/$themename/g" themes/$1/MACHINENAME.info.yml +sed -i "s/MACHINENAME/$1/g" themes/$1/MACHINENAME.info.yml + +# Remove "hidden: true" from *.info.yml file, 7th line +sed -i "7d" themes/$1/MACHINENAME.info.yml + +# Strip .template suffix CSS and js files (added to prevent pcss test fails). +mv themes/$1/css/style.css.template themes/$1/css/style.css +mv themes/$1/js/scripts.js.template themes/$1/js/scripts.js + +# Update three *.yml file names from MACHINENAME.info.yml to my_theme.info.yml. +for f in themes/$1/MACHINENAME*; do mv "$f" "${f/MACHINENAME/$1}"; done + +# Simple check, does number of files match between subtheme and theme folder? +subthemecount=$(find core/themes/olivero/subtheme -type f | wc -l) +themecount=$(find themes/$1 -type f | wc -l) + +if [ $subthemecount == $themecount ] +then + echo "Theme '$themename' created successfully in themes/$1 ..." +else + echo "It looks like something went wrong ... please check your themes folder." +fi diff --git a/core/themes/olivero/subtheme/MACHINENAME.info.yml b/core/themes/olivero/subtheme/MACHINENAME.info.yml new file mode 100644 index 0000000000..85ffcde2a2 --- /dev/null +++ b/core/themes/olivero/subtheme/MACHINENAME.info.yml @@ -0,0 +1,25 @@ +name: 'THEMENAME' +type: theme +base theme: olivero +description: 'An Olivero based sub-theme.' +package: 'Olivero' +version: 1.x +hidden: true +core_version_requirement: ^8 || ^9 || ^10 +regions: + header: Header + primary_menu: 'Primary menu' + secondary_menu: 'Secondary menu' + hero: 'Hero (full width)' + highlighted: Highlighted + breadcrumb: Breadcrumb + social: Social Bar + content_above: Content Above + content: Content + sidebar: 'Sidebar' + content_below: 'Content Below' + footer_top: 'Footer Top' + footer_bottom: 'Footer Bottom' +libraries: + - MACHINENAME/global-styling + - MACHINENAME/global-scripts diff --git a/core/themes/olivero/subtheme/MACHINENAME.libraries.yml b/core/themes/olivero/subtheme/MACHINENAME.libraries.yml new file mode 100644 index 0000000000..6fdde25365 --- /dev/null +++ b/core/themes/olivero/subtheme/MACHINENAME.libraries.yml @@ -0,0 +1,10 @@ +global-styling: + css: + component: + css/style.css: {} +global-scripts: + js: + js/scripts.js: {} + dependencies: + - core/drupal + - core/jquery diff --git a/core/themes/olivero/subtheme/MACHINENAME.theme b/core/themes/olivero/subtheme/MACHINENAME.theme new file mode 100644 index 0000000000..6670b68ed1 --- /dev/null +++ b/core/themes/olivero/subtheme/MACHINENAME.theme @@ -0,0 +1,8 @@ + diff --git a/core/themes/olivero/subtheme/templates/README.md b/core/themes/olivero/subtheme/templates/README.md new file mode 100644 index 0000000000..f086cc425b --- /dev/null +++ b/core/themes/olivero/subtheme/templates/README.md @@ -0,0 +1 @@ +This directory is used to implement various templates.