Revert "fix(slug_url): remove ending hypen if any"

This reverts commit cb3e46ca61.
This commit is contained in:
rlespinasse
2022-06-15 15:51:30 +02:00
parent cb3e46ca61
commit 930d4521cc
3 changed files with 8 additions and 12 deletions

View File

@@ -75,7 +75,7 @@ jobs:
with:
key: ANOTHER_MAX_LENGTH
value: "Never gonna give you up Never gonna let you down"
slug-maxlength: 24
slug-maxlength: 23
- name: Validate // Slugify with another max length
run: |
[[ "${{ env.ANOTHER_MAX_LENGTH }}" == "Never gonna give you up Never gonna let you down" ]]

View File

@@ -18,7 +18,6 @@ Produce some `slug`-ed environment variables based on the input one.
- `<env name>_SLUG_URL` (or `<env name>_SLUG_URL_CS`)
- like `<env name>_SLUG` (or `<env name>_SLUG_CS`) with the `.`, and `_` characters also replaced by `-`
- will not end with `-`
## Usage

View File

@@ -33,7 +33,7 @@ slug() {
# 3d : Remove leading dashes
# 4d : Remove trailing dashes
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9._-]+/-/g;s/^-*//;s/-*$//' <<<"$1")
reduce "$output" false
reduce "$output"
}
slug_url() {
@@ -42,19 +42,16 @@ slug_url() {
# 3d : Remove leading dashes
# 4d : Remove trailing dashes
output=$(sed -E 's#refs/[^\/]*/##;s/[^a-zA-Z0-9-]+/-/g;s/^-*//;s/-*$//' <<<"$1")
reduce "$output" true
reduce "$output"
}
reduce() {
reduced_value="$1"
remove_ending_hypen="$2"
if [ "${MAX_LENGTH}" != "nolimit" ]; then
reduced_value=$(cut -c1-"${MAX_LENGTH}" <<<"$1")
if [ "${MAX_LENGTH}" == "nolimit" ]; then
echo "$1"
else
cut -c1-"${MAX_LENGTH}" <<<"$1"
fi
if [ "remove_ending_hypen" == "true" ]; then
reduced_value="${reduced_value//-*$/}"
fi
echo "$reduced_value"
}
SLUG_VALUE=$(slug "$VALUE")
SLUG_CS_VALUE=$(slug "$CS_VALUE")