Skip to content

Commit ca94b24

Browse files
lcharetteCopilot
andcommitted
Enhance upgrade plan from experience on the last upgrade
Co-authored-by: Copilot <copilot@github.com>
1 parent 1019183 commit ca94b24

1 file changed

Lines changed: 46 additions & 51 deletions

File tree

.github/prompts/plan-upgradeGravDocs.prompt.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ description: Description here.
3737
- If the description value is **not** quoted but **contains a colon** (`:`) in its text, wrap the entire value in double quotes to produce valid YAML (e.g. `description: "Some text: here."`)
3838

3939
> **Edge case:** When `metadata.description:` is present but empty (no value on the line), the regex must not consume the next YAML line. Always check that the extracted description value is non-empty before promoting it.
40+
>
41+
> **Implementation note:** When extracting the value after `description:`, use `[ \t]*` (spaces/tabs only) — **not** `\s*` — to avoid crossing newline boundaries. `\s*` will consume the newline and capture the next YAML line (e.g. `taxonomy:`) as the description value when the description is empty.
4042
4143
### T2 — Notice Blocks → GitHub Alerts
4244

@@ -68,6 +70,7 @@ Line two with **bold** and a [link](/page).
6870
> **Edge cases to handle:**
6971
> - **Indented notices** (e.g. inside a numbered list): ` [notice=tip]...[/notice]` — match regardless of leading whitespace, not just at line start. Move the converted alert block *outside* the list item (alerts cannot be nested in list items).
7072
> - **Inline notices** (opening tag mid-sentence): e.g. `Some text. [notice]Warning.[/notice]` — split the sentence before the tag, then output the alert on its own line.
73+
> - **Notices inside HTML comments** (`<!-- ... -->`): do **not** convert them. Some pages use HTML comments to temporarily disable content; converting notices inside them would corrupt the comment. Detect open comment ranges before processing and skip any notice match whose start position falls within a comment range.
7174
7275
### T3 — Image `?resize=` Parameters
7376

@@ -117,6 +120,8 @@ obsolete: true
117120
(full contents of other-modular/docs.md pasted here)
118121
```
119122

123+
> **Implementation note:** Modular files often contain backslash sequences (e.g. `\wsl$`, `\h`). When substituting content via regex, **never pass the modular content as a string replacement template** — regex engines interpret `\n`, `\1`, `\h`, etc. as special sequences and will throw an error or silently corrupt the content. Always use a **literal replacement function** (e.g. a lambda that returns the string directly) so the content is treated as a plain string.
124+
120125
The modular files themselves are deleted after all injections are resolved (see Phase 6).
121126

122127
### T5 — Misc Grav Syntax
@@ -157,6 +162,17 @@ Rules:
157162

158163
---
159164

165+
## Implementation Strategy
166+
167+
**Always implement phases 1–5b as a single Python script** that iterates over all `.md` files in one pass. Manual file-by-file editing across 150+ files is error-prone and non-repeatable. A script also guarantees:
168+
- All transformations are applied atomically and in the correct order within each file
169+
- The inlining lambda workaround (T4) is easy to apply
170+
- The run can be reset via `git checkout -- app/pages/{version}/` and rerun after any fix
171+
172+
Save the script alongside the pages (e.g. `_meta/upgrade_grav_{version}.py`) and delete it after the upgrade is verified.
173+
174+
---
175+
160176
## Execution Phases
161177

162178
### Phase 0 — Discovery (run before everything else)
@@ -171,24 +187,24 @@ find app/pages/{version}/modular -name "*.md" 2>/dev/null
171187
# All injection points
172188
grep -rn "plugin:content-inject" app/pages/{version}/
173189

174-
# All image resize parameters
175-
grep -rn "?resize=" app/pages/{version}/
190+
# All image resize parameters (use -F for literal ? matching)
191+
grep -Frn '?resize=' app/pages/{version}/
176192

177193
# All notice blocks
178-
grep -rn "\[notice" app/pages/{version}/
194+
grep -rn '\[notice' app/pages/{version}/
179195

180196
# Any other unknown Grav shortcodes
181-
grep -rn "\[size=" app/pages/{version}/
182-
grep -rEn "\[[a-z]+=?" app/pages/{version}/ | grep -v "^\[!" | grep -v "notice\|size\|plugin"
197+
grep -rn '\[size=' app/pages/{version}/
198+
grep -rEn '\[[a-z]+=' app/pages/{version}/ | grep -v 'notice\|size\|plugin'
183199

184-
# Relative image paths (missing leading /)
185-
grep -rEn "!\[.*\]\((\.\.?/)?images/" app/pages/{version}/
200+
# Relative image paths (missing leading /) — use single quotes to avoid bash ! history expansion
201+
grep -rEn '!\[.*\]\((\.\./)?images/' app/pages/{version}/
186202

187203
# Internal links with numeric prefixes
188-
grep -rEn "\]\([^)]*[0-9]+\.[a-z]" app/pages/{version}/ | grep -v "http"
204+
grep -rEn '\]\([^)]*[0-9]+\.[a-z]' app/pages/{version}/ | grep -v 'http'
189205

190206
# Internal links missing leading /
191-
grep -rEn "\]\([a-z]" app/pages/{version}/ | grep -v "http"
207+
grep -rEn '\]\([a-z]' app/pages/{version}/ | grep -v 'http'
192208
```
193209

194210
Report findings before proceeding. If any unknown shortcode patterns are found, flag them and wait for instructions.
@@ -202,38 +218,15 @@ For each injection point found in Phase 0:
202218
4. For all other modular files → read the file's full content and paste it verbatim in place of the inject line
203219
5. Confirm all injection points are resolved
204220

205-
### Phase 2 — Notice Conversion (T2)
206-
207-
Convert all `[notice...]` blocks across all files using the T2 mapping table. Run *after* Phase 1 so inlined content is also covered.
208-
209-
### Phase 3 — Frontmatter Upgrade (T1)
210-
211-
Flatten `metadata.description` and remove `taxonomy:` blocks across all files. *Can run in parallel with Phase 2.*
212-
213-
After running, verify no files contain `description: taxonomy:` (sign of empty-description regex bleed) and no unquoted descriptions containing a colon:
221+
### Phase 2–5b — Apply All Remaining Transformations (T1–T6)
214222

215-
```bash
216-
grep -rn "description: taxonomy:" app/pages/{version}/
217-
grep -rn '^description:' app/pages/{version}/ | grep ':' | grep -v 'description: "'
218-
```
219-
220-
### Phase 4 — Image Path Cleanup (T3)
221-
222-
Remove `?resize=` parameters from all files identified in Phase 0. *Can run in parallel with Phase 2.*
223-
224-
### Phase 5 — Misc Syntax Cleanup (T5)
223+
In the same single script pass that processes each file, apply all remaining transformations in this order:
225224

226-
Strip any remaining Grav-only wrapper tags identified in Phase 0. *Can run in parallel with Phase 2.*
227-
228-
### Phase 5b — Link and Image Path Normalization (T6)
229-
230-
For all files with issues identified in Phase 0:
231-
1. Fix relative image paths → absolute paths starting with `/images/`
232-
2. Strip numeric prefixes from internal link path segments
233-
3. Add leading `/` to internal links that are missing it
234-
4. Do not touch external links or anchor-only links
235-
236-
*Can run in parallel with Phase 2.*
225+
1. **T2 — Notice conversion**: Convert all `[notice...]` blocks. Runs after Phase 1 so inlined content is covered.
226+
2. **T1 — Frontmatter upgrade**: Flatten `metadata.description`, remove `taxonomy:`. Remember `[ \t]*` not `\s*` when parsing the description value.
227+
3. **T3 — Image resize**: Remove `?resize=` query parameters.
228+
4. **T5 — Misc syntax**: Strip `[size=N]...[/size]` and any other unknown shortcodes.
229+
5. **T6 — Link normalization**: Fix relative image paths and internal links (leading `/`, numeric prefixes).
237230

238231
### Phase 6 — Delete Modular Folders
239232

@@ -248,31 +241,33 @@ After Phase 1 is fully complete, delete:
248241
Run these checks after all phases — each should return no results:
249242

250243
```bash
251-
grep -rn "\[notice" app/pages/{version}/
252-
grep -rn "plugin:content-inject" app/pages/{version}/
253-
grep -rn "taxonomy:" app/pages/{version}/
254-
grep -rn "^ description:" app/pages/{version}/ # catches un-flattened metadata.description
255-
grep -rn "?resize=" app/pages/{version}/
256-
grep -rn "\[size=" app/pages/{version}/
244+
grep -rn '\[notice' app/pages/{version}/
245+
grep -rn 'plugin:content-inject' app/pages/{version}/
246+
grep -rn 'taxonomy:' app/pages/{version}/
247+
grep -rn '^ description:' app/pages/{version}/ # catches un-flattened metadata.description
248+
grep -Frn '?resize=' app/pages/{version}/ # -F for literal ? matching
249+
grep -rn '\[size=' app/pages/{version}/
257250
```
258251

252+
> **Note on the `[notice` check:** Results that appear inside HTML comment blocks (`<!-- ... -->`) are **expected and acceptable** — those notices were intentionally commented out in the source and must not be converted. Confirm any hits are inside `<!--``-->` before treating them as failures.
253+
259254
```bash
260-
# No relative image paths
261-
grep -rEn "!\[.*\]\((\.\.?/)?images/" app/pages/{version}/
255+
# No relative image paths — single quotes avoid bash ! history expansion
256+
grep -rEn '!\[.*\]\((\.\./)?images/' app/pages/{version}/
262257

263258
# No internal links with numeric prefixes
264-
grep -rEn "\]\([^)]*[0-9]+\.[a-z]" app/pages/{version}/ | grep -v "http"
259+
grep -rEn '\]\([^)]*[0-9]+\.[a-z]' app/pages/{version}/ | grep -v 'http'
265260

266261
# No internal links missing leading /
267-
grep -rEn "\]\([a-z]" app/pages/{version}/ | grep -v "http"
262+
grep -rEn '\]\([a-z]' app/pages/{version}/ | grep -v 'http'
268263
```
269264

270265
Also verify:
271266
- Modular folders no longer exist under `app/pages/{version}/`
272267
- No `description: taxonomy:` values (empty-description regex bleed)
273268
- No unquoted `description:` values containing a colon — run:
274269
```bash
275-
# Descriptions with colons that are not wrapped in double quotes
276-
grep -rn '^description:' app/pages/{version}/ | grep ':' | grep -v 'description: "'
270+
# Descriptions whose value (after the key) contains a colon and is not quoted
271+
grep -rn '^description: [^"].*:' app/pages/{version}/
277272
```
278273
- Spot-check 5–6 converted pages for correct frontmatter, alert rendering, and working links in the dev server

0 commit comments

Comments
 (0)