Skip to content

Commit ff934ee

Browse files
committed
bug set-slogan
1 parent 54b39f4 commit ff934ee

File tree

27 files changed

+238
-80
lines changed

27 files changed

+238
-80
lines changed

batch/set-description.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
4+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
5+
CONFIG_FILE="$PROJECT_DIR/hugo.toml"
6+
TMP_FILE="$PROJECT_DIR/hugo_tmp.toml"
7+
8+
if [ ! -f "$CONFIG_FILE" ]; then
9+
echo "❌ Fichier introuvable : $CONFIG_FILE"
10+
exit 1
11+
fi
12+
13+
read -p "Langue à modifier (ex: fr, es, ar, etc.) : " lang_code
14+
read -p "Description du site pour [$lang_code] : " desc
15+
read -p "Bio courte pour [$lang_code] : " bio
16+
17+
found=0
18+
while IFS= read -r line; do
19+
echo "$line" >> "$TMP_FILE"
20+
21+
# Injecter dans le bon bloc
22+
if [[ "$line" =~ \[languages\.${lang_code}\.params\] ]]; then
23+
found=1
24+
elif [[ "$found" -eq 1 && "$line" =~ ^\[ ]]; then
25+
# Fin du bloc params -> insérer et couper
26+
echo " description = \"$desc\"" >> "$TMP_FILE"
27+
echo " bio = \"$bio\"" >> "$TMP_FILE"
28+
found=0
29+
fi
30+
done < "$CONFIG_FILE"
31+
32+
# Si jamais on était encore dans le bloc à la fin
33+
if [[ "$found" -eq 1 ]]; then
34+
echo " description = \"$desc\"" >> "$TMP_FILE"
35+
echo " bio = \"$bio\"" >> "$TMP_FILE"
36+
fi
37+
38+
mv "$TMP_FILE" "$CONFIG_FILE"
39+
echo "✅ Description et bio ajoutées pour [$lang_code]"

batch/set-slogan.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Recherche le fichier de config
4+
CONFIG_FILE="$(find .. -maxdepth 2 \( -name 'hugo.toml' -o -name 'config.toml' \) | head -n 1)"
5+
if [[ ! -f "$CONFIG_FILE" ]]; then
6+
echo "❌ Fichier hugo.toml ou config.toml introuvable"
7+
exit 1
8+
fi
9+
10+
echo "📄 Fichier de config détecté : $CONFIG_FILE"
11+
12+
# Détecte les langues
13+
LANGS=$(grep -oP '^\s*\[languages\.\K[a-z]{2}(?=\])' "$CONFIG_FILE" | sort -u)
14+
if [[ -z "$LANGS" ]]; then
15+
echo "❌ Aucune langue trouvée dans [languages]"
16+
exit 1
17+
fi
18+
19+
for lang in $LANGS; do
20+
echo -n "📝 Nouveau slogan pour '$lang' : "
21+
read slogan
22+
slogan_escaped=$(printf '%s' "$slogan" | sed 's/"/\\"/g')
23+
24+
TMP_FILE=$(mktemp)
25+
inserted=0
26+
in_lang=0
27+
in_params=0
28+
29+
while IFS= read -r line; do
30+
if [[ "$line" =~ ^\[languages\.${lang}\]$ ]]; then
31+
in_lang=1
32+
elif [[ "$line" =~ ^\[languages\.[a-z]{2}\]$ ]]; then
33+
in_lang=0
34+
fi
35+
36+
if [[ "$line" =~ ^\[languages\.${lang}\.params\]$ ]]; then
37+
in_params=1
38+
echo "$line" >> "$TMP_FILE"
39+
continue
40+
elif [[ "$line" =~ ^\[languages\.[a-z]{2}(\.params)?\]$ ]]; then
41+
if [[ $in_params -eq 1 && $inserted -eq 0 ]]; then
42+
echo "slogan = \"$slogan_escaped\"" >> "$TMP_FILE"
43+
inserted=1
44+
fi
45+
in_params=0
46+
fi
47+
48+
if [[ $in_params -eq 1 && "$line" =~ ^\s*slogan\s*= ]]; then
49+
echo "slogan = \"$slogan_escaped\"" >> "$TMP_FILE"
50+
inserted=1
51+
continue
52+
fi
53+
54+
echo "$line" >> "$TMP_FILE"
55+
done < "$CONFIG_FILE"
56+
57+
# Slogan jamais inséré : bloc params existe ou non
58+
if [[ $in_params -eq 1 && $inserted -eq 0 ]]; then
59+
echo "slogan = \"$slogan_escaped\"" >> "$TMP_FILE"
60+
elif [[ $in_lang -eq 1 && $in_params -eq 0 ]]; then
61+
echo "" >> "$TMP_FILE"
62+
echo "[languages.${lang}.params]" >> "$TMP_FILE"
63+
echo "slogan = \"$slogan_escaped\"" >> "$TMP_FILE"
64+
fi
65+
66+
mv "$TMP_FILE" "$CONFIG_FILE"
67+
68+
# Ajout du shortcode dans _index.md
69+
INDEX_FILE="../content/${lang}/_index.md"
70+
if [[ ! -f "$INDEX_FILE" ]]; then
71+
echo -e "---\ntitle: \"Accueil\"\n---\n\n{{< slogan >}}" > "$INDEX_FILE"
72+
echo "🆕 Fichier créé : $INDEX_FILE"
73+
elif ! grep -q "{{< slogan >}}" "$INDEX_FILE"; then
74+
echo -e "\n{{< slogan >}}" >> "$INDEX_FILE"
75+
echo "🔧 Shortcode ajouté à : $INDEX_FILE"
76+
fi
77+
done
78+
79+
echo
80+
echo "📄 Nouveau contenu de $CONFIG_FILE :"
81+
cat "$CONFIG_FILE"
82+
echo
83+
echo "✅ Tous les slogans ont été insérés ou mis à jour."

content/ar/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
title: "Bienvenue (ar)"
33
description: "Page d'accueil en ar"
44
---
5+
6+
{{< slogan >}}

content/es/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
title: "Bienvenue (es)"
33
description: "Page d'accueil en es"
44
---
5+
6+
{{< slogan >}}

content/fa/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
title: "Bienvenue (fa)"
33
description: "Page d'accueil en fa"
44
---
5+
6+
{{< slogan >}}

content/fr/_index.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
---
2-
title: "Accueil (fr)"
3-
description: "Page d'accueil en fr"
2+
title: "Bienvenue sur ClubCode"
3+
layout: page
44
---
5+
6+
{{< slogan >}}

content/fr/posts/_index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
2-
title: "Articles"
3-
layout: list
2+
title: "Bienvenue sur ClubCode"
3+
layout: page
44
---
5+

content/he/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
title: "Bienvenue (he)"
33
description: "Page d'accueil en he"
44
---
5+
6+
{{< slogan >}}

hugo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ baseURL = "https://wilonweb.github.io/multi-author/"
22
title = "ClubCode"
33
theme = "blowfish"
44

5+
defaultContentLanguage = "fr"
6+
57
[params]
68
defaultTheme = "auto"
79
ShowReadingTime = true
@@ -10,8 +12,6 @@ theme = "blowfish"
1012
disableSRI = true
1113
ShowLanguageSwitcher = true
1214

13-
defaultContentLanguage = "fr"
14-
1515
[languages]
1616

1717
[languages.fr]
@@ -20,6 +20,7 @@ defaultContentLanguage = "fr"
2020
weight = 1
2121
[languages.fr.params]
2222
displayName = "Français"
23+
description = "ClubCode : Apprends à coder facilement."
2324
[languages.fr.menus]
2425
[[languages.fr.menus.main]]
2526
name = "Accueil"
@@ -68,6 +69,7 @@ defaultContentLanguage = "fr"
6869
contentDir = "content/ar"
6970
weight = 4
7071
[languages.ar.params]
72+
slogan = "dsdsds"
7173
displayName = "العربية"
7274
rtl = true
7375
[languages.ar.menus]
@@ -96,3 +98,4 @@ defaultContentLanguage = "fr"
9698
name = "مقالات"
9799
pageRef = "/posts/"
98100
weight = 2
101+

layouts/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{{ define "main" }}
2+
{{ $partial := print "home/" .Site.Params.homepage.layout ".html" }}
3+
{{ if templates.Exists ( printf "partials/%s" $partial ) }}
4+
{{ partial $partial . }}
5+
{{ else }}
6+
{{ partial "home/profile.html" . }}
7+
{{ end }}
8+
{{ end }}

0 commit comments

Comments
 (0)