Skip to content

Commit c767026

Browse files
committed
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.
1 parent b1c12e8 commit c767026

1 file changed

Lines changed: 137 additions & 43 deletions

File tree

.github/workflows/test-docs-generation.yml

Lines changed: 137 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -66,59 +66,117 @@ jobs:
6666
# Create Jekyll source directory
6767
mkdir -p site-src
6868
69-
# Copy all docs except INDEX.md (we'll handle that separately)
69+
# First, copy all docs to site-src
7070
cp -r docs/* site-src/
7171
72-
# Process INDEX.md - replace .md with .html and add proper front matter
72+
# Fix specific problematic files first before general processing
73+
74+
# 1. Fix PAGE_TEMPLATES.md - it has complex Liquid syntax
75+
if [ -f site-src/features/configuration-based/PAGE_TEMPLATES.md ]; then
76+
echo "🔧 Processing PAGE_TEMPLATES.md file with special handling..."
77+
78+
# Create a backup
79+
cp site-src/features/configuration-based/PAGE_TEMPLATES.md site-src/features/configuration-based/PAGE_TEMPLATES.md.bak
80+
81+
# Extract the filename
82+
filename="site-src/features/configuration-based/PAGE_TEMPLATES.md"
83+
84+
# Replace problematic jinja2 code block
85+
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..."
73103
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
87104
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"
92114
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"
95118
96-
# Ensure every Markdown file has front matter
119+
# Ensure every file has front matter
97120
if ! grep -q "^---" "$file"; then
98-
echo "Injecting front matter into $file"
121+
echo " ✏️ Adding front matter to $file"
99122
sed -i '1s/^/---\nlayout: default\n---\n\n/' "$file"
100123
fi
101124
102125
# Fix any 'layout: home' references
103126
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
104167
done
105168
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..."
119171
cat > site-src/_config.yml << EOF
120172
title: DXT Documentation
121173
description: Documentation for the DEFRA Forms Engine Plugin
174+
175+
# Ensure all files are included
176+
include:
177+
- "**/*.html"
178+
179+
# Basic settings
122180
markdown: kramdown
123181
kramdown:
124182
input: GFM
@@ -144,19 +202,55 @@ jobs:
144202
layout: default
145203
EOF
146204
205+
# Create Gemfile with exact dependencies
206+
cat > site-src/Gemfile << EOF
207+
source 'https://rubygems.org'
208+
209+
gem 'jekyll', '~> 4.4.0'
210+
gem 'jekyll-remote-theme', '0.4.3'
211+
gem 'jekyll-relative-links'
212+
gem 'jekyll-sass-converter', '~> 3.0.0'
213+
gem 'jekyll-seo-tag'
214+
gem 'webrick' # required for Ruby 3.x
215+
EOF
216+
147217
# Install dependencies and build
218+
echo "🔨 Building Jekyll site..."
148219
cd site-src
149220
bundle install
150-
bundle exec jekyll build --destination ../_site
221+
JEKYLL_ENV=production bundle exec jekyll build --verbose --destination ../_site
151222
cd ..
152223
153-
# Verify HTML files were generated for features
154-
echo "Checking for built HTML pages:"
155-
find _site/features -name "*.html" | head -n 10
224+
# Thorough verification
225+
echo "🔍 Verifying build results..."
226+
227+
# Check for HTML files
228+
echo "✓ HTML files generated from markdown:"
229+
find _site -name "*.html" | grep -v "assets" | head -n 15
230+
html_count=$(find _site -name "*.html" | wc -l)
231+
echo " Total HTML files: $html_count"
232+
233+
# 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
156250
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
160254
echo "... (and more files)"
161255
162256
- name: Setup Pages

0 commit comments

Comments
 (0)