Skip to content

Commit 9bccbb3

Browse files
committed
Refactor version-replacer to substitution replacer and expand with more options
1 parent e44c02a commit 9bccbb3

3 files changed

Lines changed: 32 additions & 37 deletions

File tree

.vitepress/config.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import { defineConfig } from 'vitepress'
2-
import { versionReplacer } from './plugins/version-replacer.js'
2+
import { substitutionsReplacer } from './plugins/substitutions-replacer.js'
33
import { deepMerge, loadConfigOverrides, applyBaseToHeadTags } from './utils.js'
44

55
const defaultConfig = {
66
srcDir: 'docs',
77
title: 'CakePHP',
88
description: 'CakePHP Documentation - The rapid development PHP framework',
99
ignoreDeadLinks: true,
10-
phpVersions: {
11-
phpversion: '8.4',
12-
minphpversion: '8.1'
10+
substitutions: {
11+
'|phpversion|': { value: '8.4', format: 'bold' },
12+
'|minphpversion|': { value: '8.1', format: 'italic' },
13+
// Add more substitutions here as needed
14+
// '|cakeversion|': { value: '5.1', format: 'bold' },
15+
// '|projectname|': 'CakePHP', // Simple string without formatting
1316
},
1417
head: [
1518
['link', { rel: 'icon', type: 'image/png', href: '/favicon/favicon-96x96.png', sizes: '96x96' }],
@@ -59,7 +62,7 @@ const mergedConfig = deepMerge(defaultConfig, overrides)
5962

6063
// Configure markdown plugins after mergedConfig is available
6164
mergedConfig.markdown.config = (md) => {
62-
md.use(versionReplacer, mergedConfig.phpVersions || {})
65+
md.use(substitutionsReplacer, { substitutions: mergedConfig.substitutions || {} })
6366
}
6467

6568
// Apply base path to head tags if base is specified

.vitepress/plugins/version-replacer.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,30 @@ export default {
7777

7878
All markdown documentation files should be placed in the `docs/` directory.
7979

80+
### Text Substitutions
81+
82+
You can use placeholders in your markdown files that will be automatically replaced with configured values. This is useful for version numbers or other values that need to be updated across multiple files.
83+
84+
**Configuration** (`config.js`):
85+
86+
```javascript
87+
export default {
88+
substitutions: {
89+
'|phpversion|': { value: '8.4', format: 'bold' },
90+
'|minphpversion|': { value: '8.1', format: 'italic' },
91+
'|myversion|': '1.0.0' // Simple string without formatting
92+
}
93+
}
94+
```
95+
96+
**Usage in Markdown**:
97+
98+
```markdown
99+
This plugin requires PHP |phpversion| or higher (minimum |minphpversion|).
100+
```
101+
102+
**Result**: This plugin requires PHP **8.4** or higher (minimum *8.1*).
103+
80104
## Project Structure
81105

82106
```

0 commit comments

Comments
 (0)