FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: watch markdown additions, deletions, and YAML in Vite dev server · patternfly-java/patternfly-java@600ae56 · GitHub

Commit 600ae56

Browse files
committed
fix: watch markdown additions, deletions, and YAML in Vite dev server
Extend the Vite markdown plugin to handle 'add' and 'unlink' events (not just 'change'), and also watch _meta.yaml files. Add a guard against concurrent reprocessing. Update building.md to reflect the nested directory structure and link to the documentation page.
1 parent a0953d3 commit 600ae56

2 files changed

Lines changed: 31 additions & 10 deletions

File tree

‎showcase/markdown/developer/building.md‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,21 @@ cd showcase && pnpm run watch
159159

160160
### Markdown Pipeline
161161

162-
The `markdown` script transforms `showcase/markdown/*.md` files into JSON:
162+
The `markdown` script recursively walks `showcase/markdown/` and transforms `.md` files into JSON:
163163

164164
1. Parses markdown with remark (GFM + frontmatter support)
165-
2. Extracts YAML frontmatter (`id`, `title`)
165+
2. Extracts YAML frontmatter (`id`, `title`, `order`)
166166
3. Generates a table of contents from h2/h3 headings
167167
4. Converts to HTML with rehype
168168
5. Adds slug IDs and autolinks to headings
169169
6. Applies PatternFly CSS classes to headings
170170
7. Syntax-highlights code blocks (Java, XML, JavaScript, JSON, HTML, CSS, Bash)
171-
8. Writes JSON to `showcase/src/web/markdown/{id}.json`
171+
8. Writes JSON to `showcase/src/web/markdown/`, preserving the directory structure
172+
9. Generates `showcase/src/web/markdown/manifest.json` with the navigation tree
172173

173-
The Vite dev server watches the `markdown/` directory and regenerates JSON on changes. During a Maven `package` build, the `pnpm run markdown` command is executed automatically in the `prepare-package` phase via the frontend-maven-plugin.
174+
The Vite dev server watches the `markdown/` directory for changes, additions, and deletions (`.md` and `.yaml` files) and regenerates JSON automatically. During a Maven `package` build, `pnpm run markdown` runs automatically in the `prepare-package` phase.
175+
176+
See the [Documentation](/developer/documentation) page for details on the directory structure, frontmatter fields, and folder conventions.
174177

175178
### Full Showcase Build
176179

‎showcase/vite.config.js‎

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,36 @@ function serveJ2cl() {
4141
}
4242

4343
function markdownPlugin() {
44+
let reprocessing = false;
45+
46+
function reprocess() {
47+
if (reprocessing) return;
48+
reprocessing = true;
49+
try {
50+
execSync('node markdown.mjs', {stdio: 'inherit'});
51+
} finally {
52+
reprocessing = false;
53+
}
54+
}
55+
56+
function isMarkdownSource(file) {
57+
return file.startsWith(markdownDir) && (file.endsWith('.md') || file.endsWith('.yaml'));
58+
}
59+
4460
return {
4561
name: 'markdown',
4662
buildStart() {
47-
execSync('node markdown.mjs', {stdio: 'inherit'});
63+
reprocess();
4864
},
4965
configureServer(server) {
5066
server.watcher.add(markdownDir);
51-
server.watcher.on('change', (file) => {
52-
if (file.startsWith(markdownDir) && file.endsWith('.md')) {
53-
execSync('node markdown.mjs', {stdio: 'inherit'});
54-
}
55-
});
67+
for (const event of ['change', 'add', 'unlink']) {
68+
server.watcher.on(event, (file) => {
69+
if (isMarkdownSource(file)) {
70+
reprocess();
71+
}
72+
});
73+
}
5674
}
5775
};
5876
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL