You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore: enhance documentation generation workflow with specific file fixes and thorough verification
- Implemented special handling for PAGE_TEMPLATES.md and PAGE_EVENTS.md to address Liquid syntax issues.
- Improved the processing of INDEX.md to ensure proper front matter and HTML conversion.
- Enhanced markdown file processing to escape Liquid tags outside of code blocks and ensure consistent front matter.
- Added thorough verification steps to confirm successful HTML generation and check for remaining markdown files in the output.
awk -v RS='```jinja2' -v ORS='```jinja2' 'NR==1{print} NR==2{print "\n<!-- Liquid template example (commented out for Jekyll compatibility):\n<p class=\"govuk-body\">\n {# Use Liquid\\'s `assign` to create a variable... #}\n {%- assign inEngland = \"/are-you-in-england\" | page -%}\n\n {# Use the reference to `evaluate` the title #}\n {{ inEngland.title | evaluate }}<br>\n\n {# Use the href filter to display the full page path #}\n {{ \"/are-you-in-england\" | href }}<br>\n\n {# Use the `answer` filter to render the user provided answer to a question #}\n {{ \\'TKsWbP\\' | answer }}\n</p>\n-->"; next} 1' "$filename" > "${filename}.tmp1"
86
+
87
+
# Replace problematic jsonc code block
88
+
awk -v RS='```jsonc' -v ORS='```jsonc' 'NR==1{print} NR==2{print "\n{\n // This example shows how a Html (guidance) component can use the available filters\n \"title\": \"Template example for <!-- {{ WmHfSb }} -->?\",\n \"path\": \"/example\",\n \"components\": [\n {\n \"title\": \"Html\",\n \"type\": \"Html\",\n \"content\": \"<p class=\\\"govuk-body\\\">Example content (Liquid syntax removed for docs)</p>\"\n }\n ]\n}"; next} NR==3{print} NR>3{print RS $0}' "${filename}.tmp1" > "${filename}.tmp2"
89
+
90
+
# Replace the original file
91
+
mv "${filename}.tmp2" "$filename"
92
+
rm "${filename}.tmp1" 2>/dev/null || true
93
+
fi
94
+
95
+
# 2. Fix PAGE_EVENTS.md - it has an extra endif
96
+
if [ -f site-src/features/configuration-based/PAGE_EVENTS.md ]; then
97
+
echo "🔧 Processing PAGE_EVENTS.md to fix endif issue..."
98
+
sed -i '/You have not been awarded any funding for this application/,+2 s/{% endif %}//' site-src/features/configuration-based/PAGE_EVENTS.md
99
+
fi
100
+
101
+
# Process INDEX.md - replace .md with .html
102
+
echo "🔄 Processing index.md file..."
73
103
sed 's/\.md/\.html/g' docs/INDEX.md > site-src/index.md
74
-
sed -i '1s/^/---\nlayout: default\ntitle: DXT Documentation\n---\n\n/' site-src/index.md
75
-
76
-
# Create a file to hold the problematic lines to fix
77
-
cat > fix-liquid.sed << EOF
78
-
# Fix for the specific error in PAGE_EVENTS.md
79
-
/You have not been awarded any funding for this application/,+1 s/{% endif %}//
80
-
81
-
# Escape all Liquid tags for Jekyll
82
-
s/{{/\\{{ /g
83
-
s/}}/\\}} /g
84
-
s/{%/\\{% /g
85
-
s/%}/\\%} /g
86
-
EOF
87
104
88
-
# Process all markdown files
89
-
find site-src -name "*.md" | while read file; do
90
-
# Apply the liquid fixes
91
-
sed -i -f fix-liquid.sed "$file"
105
+
# Ensure proper front matter in index.md
106
+
if ! grep -q "^---" site-src/index.md; then
107
+
sed -i '1s/^/---\nlayout: default\ntitle: DXT Documentation\n---\n\n/' site-src/index.md
108
+
fi
109
+
110
+
# Process all markdown files for general fixes
111
+
echo "🔄 Processing all markdown files..."
112
+
find site-src -type f -name "*.md" | while read file; do
113
+
echo " - Processing $file"
92
114
93
-
# Replace .md with .html in links
94
-
sed -i 's/\.md/\.html/g' "$file"
115
+
# Replace .md with .html only in links (not in code blocks or paths)
116
+
# This regex targets markdown links [text](link.md) and also bare links like path/to/file.md
117
+
sed -i -E ':a;N;$!ba;s/(\[[^\]]*\]\([^)]*)(\.md)([^)]*\))/\1.html\3/g;s/(\][[:space:]]*:.*)(\.md)([[:space:]]*$)/\1.html\3/g' "$file"
95
118
96
-
# Ensure every Markdown file has front matter
119
+
# Ensure every file has front matter
97
120
if ! grep -q "^---" "$file"; then
98
-
echo "Injecting front matter into $file"
121
+
echo " ✏️ Adding front matter to $file"
99
122
sed -i '1s/^/---\nlayout: default\n---\n\n/' "$file"
100
123
fi
101
124
102
125
# Fix any 'layout: home' references
103
126
sed -i 's/layout: home/layout: default/g' "$file"
127
+
128
+
# Escape all Liquid syntax outside of code blocks
129
+
# This is complex, we'll use a temp file approach
130
+
cp "$file" "${file}.tmp"
131
+
132
+
# Process with awk to handle code blocks differently
133
+
awk '
134
+
BEGIN {in_code=0; in_front_matter=0; front_matter_count=0;}
135
+
136
+
# Front matter handling
137
+
/^---/ {
138
+
if (in_front_matter == 0 && front_matter_count == 0) {
139
+
in_front_matter = 1;
140
+
front_matter_count++;
141
+
print; next;
142
+
} else if (in_front_matter == 1) {
143
+
in_front_matter = 0;
144
+
print; next;
145
+
}
146
+
}
147
+
148
+
# Code block handling
149
+
/^```/ {
150
+
in_code = !in_code;
151
+
print; next;
152
+
}
153
+
154
+
# Escape Liquid tags outside code blocks and front matter
155
+
!in_code && !in_front_matter && /{{|{%/ {
156
+
gsub(/{{/, "\\{{ ");
157
+
gsub(/}}/, " \\}}");
158
+
gsub(/{%/, "\\{% ");
159
+
gsub(/%}/, " \\%}");
160
+
}
161
+
162
+
# Print the line
163
+
{ print }
164
+
' "${file}.tmp" > "$file"
165
+
166
+
rm "${file}.tmp" 2>/dev/null || true
104
167
done
105
168
106
-
# Create Gemfile with exact dependencies
107
-
cat > site-src/Gemfile << EOF
108
-
source 'https://rubygems.org'
109
-
110
-
gem 'jekyll', '~> 4.4.0'
111
-
gem 'jekyll-remote-theme', '0.4.3'
112
-
gem 'jekyll-relative-links'
113
-
gem 'jekyll-sass-converter', '~> 3.0.0'
114
-
gem 'jekyll-seo-tag'
115
-
gem 'webrick' # required for Ruby 3.x
116
-
EOF
117
-
118
-
# Write Jekyll _config.yml with proper configuration
169
+
# Create _config.yml with settings to process all files
170
+
echo "📝 Creating Jekyll config files..."
119
171
cat > site-src/_config.yml << EOF
120
172
title: DXT Documentation
121
173
description: Documentation for the DEFRA Forms Engine Plugin
# Check if any markdown files remain in output (there shouldn't be any)
234
+
md_files=$(find _site -name "*.md" | wc -l)
235
+
if [ "$md_files" -gt 0 ]; then
236
+
echo "⚠️ WARNING: Found $md_files markdown files in output (should be 0):"
237
+
find _site -name "*.md" | head -n 10
238
+
else
239
+
echo "✅ No markdown files found in output (good!)"
240
+
fi
241
+
242
+
# Check for specific problematic files to make sure they were converted
243
+
for check_file in "features/configuration-based/PAGE_TEMPLATES.html" "features/configuration-based/PAGE_EVENTS.html" "features/code-based/PAGE_VIEWS.html"; do
244
+
if [ -f "_site/$check_file" ]; then
245
+
echo "✅ Successfully converted: $check_file"
246
+
else
247
+
echo "❌ FAILED to convert: $check_file"
248
+
fi
249
+
done
156
250
157
-
# Display final build structure for debugging
158
-
echo "Final site structure:"
159
-
find _site -type f | grep -v ".git" | grep -e "index.html" -e "assets" -e "schema" | head -n 10
251
+
# Final output structure
252
+
echo "📊 Final site structure:"
253
+
find _site -type f | grep -v ".git" | grep -e "index.html" -e "features" | sort | head -n 15
0 commit comments