Skip to content

Commit 3e86cbf

Browse files
committed
lint: fix linting erros
1 parent 00c49d9 commit 3e86cbf

4 files changed

Lines changed: 95 additions & 244 deletions

File tree

.github/scripts/docs/fix-docs.sh

Lines changed: 55 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33

44
echo "🔄 Processing documentation files..."
55

6-
# Set up sed in-place flag based on OS
76
if sed --version 2>&1 | grep -q GNU; then
8-
# GNU sed (Linux)
97
SED_INPLACE=(-i)
108
else
11-
# BSD sed (macOS)
129
SED_INPLACE=(-i "")
1310
fi
1411

@@ -21,33 +18,32 @@ for location in "." "docs"; do
2118
if [ -f "$file" ]; then
2219
echo " Processing $file"
2320
temp_file="${file}.tmp"
24-
25-
# IMPROVED: Use awk for better GitHub-style admonition conversion
21+
2622
awk '
27-
/^> \[!NOTE\]/ {
28-
print "{: .note }";
29-
in_note = 1;
30-
next;
23+
/^> \[!NOTE\]/ {
24+
print "{: .note }";
25+
in_note = 1;
26+
next;
3127
}
32-
/^> \[!TIP\]/ {
33-
print "{: .highlight }";
34-
in_note = 1;
35-
next;
28+
/^> \[!TIP\]/ {
29+
print "{: .highlight }";
30+
in_note = 1;
31+
next;
3632
}
37-
/^> \[!IMPORTANT\]/ {
38-
print "{: .important }";
39-
in_note = 1;
40-
next;
33+
/^> \[!IMPORTANT\]/ {
34+
print "{: .important }";
35+
in_note = 1;
36+
next;
4137
}
42-
/^> \[!WARNING\]/ {
43-
print "{: .warning }";
44-
in_note = 1;
45-
next;
38+
/^> \[!WARNING\]/ {
39+
print "{: .warning }";
40+
in_note = 1;
41+
next;
4642
}
47-
/^> \[!CAUTION\]/ {
48-
print "{: .warning }";
49-
in_note = 1;
50-
next;
43+
/^> \[!CAUTION\]/ {
44+
print "{: .warning }";
45+
in_note = 1;
46+
next;
5147
}
5248
/^> / {
5349
if(in_note) {
@@ -60,15 +56,13 @@ for location in "." "docs"; do
6056
print;
6157
}
6258
' "$file" > "$temp_file"
63-
64-
# Fix examples link in GETTING_STARTED
59+
6560
if [[ "$file" =~ GETTING_STARTED.md ]]; then
6661
sed "${SED_INPLACE[@]}" 's|\[examples\](test/form/definitions)|\[examples\](https://github.com/DEFRA/forms-engine-plugin/tree/main/test/form/definitions)|g' "$temp_file"
6762
fi
68-
69-
# Fix double baseurl prepending for links to PLUGIN_OPTIONS
63+
7064
sed "${SED_INPLACE[@]}" 's|/forms-engine-plugin/forms-engine-plugin/|/forms-engine-plugin/|g' "$temp_file"
71-
65+
7266
mv "$temp_file" "$file"
7367
fi
7468
done
@@ -93,47 +87,44 @@ echo "Using docs path: $DOCS_PATH"
9387
for dir in code-based configuration-based; do
9488
dir_path="$DOCS_PATH/$dir"
9589
echo "Processing $dir_path directory..."
96-
90+
9791
if [ ! -d "$dir_path" ]; then
9892
echo "❌ Directory $dir_path not found!"
9993
continue
10094
fi
101-
102-
# Change to the directory
95+
10396
pushd "$dir_path" > /dev/null || exit 1
104-
105-
# Process each file
97+
10698
for file in *.md; do
10799
echo " Processing $file"
108-
109-
# Create a temporary file
100+
110101
temp_file="${file}.tmp"
111102

112103
awk '
113-
/^> \[!NOTE\]/ {
114-
print "{: .note }";
115-
in_note = 1;
116-
next;
104+
/^> \[!NOTE\]/ {
105+
print "{: .note }";
106+
in_note = 1;
107+
next;
117108
}
118-
/^> \[!TIP\]/ {
119-
print "{: .highlight }";
120-
in_note = 1;
121-
next;
109+
/^> \[!TIP\]/ {
110+
print "{: .highlight }";
111+
in_note = 1;
112+
next;
122113
}
123-
/^> \[!IMPORTANT\]/ {
124-
print "{: .important }";
125-
in_note = 1;
126-
next;
114+
/^> \[!IMPORTANT\]/ {
115+
print "{: .important }";
116+
in_note = 1;
117+
next;
127118
}
128-
/^> \[!WARNING\]/ {
129-
print "{: .warning }";
130-
in_note = 1;
131-
next;
119+
/^> \[!WARNING\]/ {
120+
print "{: .warning }";
121+
in_note = 1;
122+
next;
132123
}
133-
/^> \[!CAUTION\]/ {
134-
print "{: .warning }";
135-
in_note = 1;
136-
next;
124+
/^> \[!CAUTION\]/ {
125+
print "{: .warning }";
126+
in_note = 1;
127+
next;
137128
}
138129
/^> / {
139130
if(in_note) {
@@ -146,83 +137,29 @@ for dir in code-based configuration-based; do
146137
print;
147138
}
148139
' "$file" > "$temp_file"
149-
150-
# Fix URL paths based on file type
140+
151141
if [[ "$file" == "PAGE_VIEWS.md" ]]; then
152-
# Fix links to PAGE_EVENTS in PAGE_VIEWS.md
153142
sed "${SED_INPLACE[@]}" 's|\(see our guidance on page events\)(\.\./configuration-based/PAGE_EVENTS.md)|\1(/features/configuration-based/PAGE_EVENTS)|g' "$temp_file"
154-
# Fix links to GitHub repos that shouldn't have baseurl
155143
sed "${SED_INPLACE[@]}" 's|\[plugin option\](/forms-engine-plugin/https://|[plugin option](https://|g' "$temp_file"
156144
fi
157-
145+
158146
if [[ "$file" == "PAGE_TEMPLATES.md" ]]; then
159-
# Fix links to PLUGIN_OPTIONS
160147
sed "${SED_INPLACE[@]}" 's|\[PLUGIN_OPTIONS.md\](../../PLUGIN_OPTIONS.md#custom-filters)|\[Plugin Options](/PLUGIN_OPTIONS#custom-filters)|g' "$temp_file"
161148
fi
162-
163-
# Fix double baseurl prepending for all external links
149+
164150
sed "${SED_INPLACE[@]}" 's|/forms-engine-plugin/forms-engine-plugin/|/forms-engine-plugin/|g' "$temp_file"
165151
sed "${SED_INPLACE[@]}" 's|/forms-engine-plugin/https://|https://|g' "$temp_file"
166-
167-
# Create lowercase version if needed
152+
168153
lowercase_file=$(echo "$file" | tr '[:upper:]' '[:lower:]')
169154
if [ "$file" != "$lowercase_file" ]; then
170155
echo " Creating lowercase copy: $lowercase_file"
171156
cp "$temp_file" "$lowercase_file"
172157
fi
173-
174-
# Replace original with fixed version
158+
175159
mv "$temp_file" "$file"
176160
done
177-
178-
# Return to the original directory
179-
popd > /dev/null
180-
done
181161

182-
# Fix Liquid syntax in templates
183-
echo "🔄 Fixing Liquid syntax in templates..."
184-
for liquid_file in "$DOCS_PATH/configuration-based/PAGE_EVENTS.md" "$DOCS_PATH/configuration-based/PAGE_TEMPLATES.md" "$DOCS_PATH/code-based/PAGE_VIEWS.md"; do
185-
if [ -f "$liquid_file" ]; then
186-
echo " Fixing Liquid syntax in $liquid_file"
187-
188-
# Create a temporary file
189-
temp_file="${liquid_file}.tmp"
190-
> "$temp_file" # Create empty temporary file
191-
192-
# Process line by line to properly wrap Liquid tags in raw tags
193-
in_code_block=false
194-
while IFS= read -r line; do
195-
# Check if line starts/ends a code block
196-
if [[ "$line" =~ ^\`\`\`.* ]]; then
197-
# Toggle code block state
198-
if $in_code_block; then
199-
in_code_block=false
200-
else
201-
in_code_block=true
202-
fi
203-
echo "$line" >> "$temp_file"
204-
continue
205-
fi
206-
207-
if $in_code_block; then
208-
# Inside code blocks, wrap any {{ }} in raw tags
209-
if [[ "$line" =~ (\{\{|\}\}) ]]; then
210-
# Replace any existing escape sequences
211-
line=$(echo "$line" | sed 's/\\{{ /{{ /g' | sed 's/ \\}}/ }}/g' | sed 's/\\{{/{{/g' | sed 's/\\}}/}}/g')
212-
# Wrap the entire line in raw tags if it contains liquid syntax
213-
echo "{% raw %}${line}{% endraw %}" >> "$temp_file"
214-
else
215-
echo "$line" >> "$temp_file"
216-
fi
217-
else
218-
# Outside code blocks, just write the line
219-
echo "$line" >> "$temp_file"
220-
fi
221-
done < "$liquid_file"
222-
223-
# Replace original with fixed version
224-
mv "$temp_file" "$liquid_file"
225-
fi
162+
popd > /dev/null
226163
done
227164

228-
echo "✅ Documentation fixes applied successfully!"
165+
echo "✅ Documentation fixes applied successfully!"

.github/scripts/docs/generate-and-publish-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ fi
7272
# Create .nojekyll file to bypass Jekyll processing
7373
touch ./docs-site/.nojekyll
7474

75-
echo "✅ Documentation generated successfully"
75+
echo "✅ Documentation generated successfully"

0 commit comments

Comments
 (0)