Skip to content

Commit 0c79179

Browse files
committed
fix: make sure php versions are actually passed to the versionreplacer component
1 parent e88bc18 commit 0c79179

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

.vitepress/config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ const defaultConfig = {
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'
13+
},
1014
head: [
1115
['link', { rel: 'icon', type: 'image/png', href: '/favicon/favicon-96x96.png', sizes: '96x96' }],
1216
['link', { rel: 'icon', type: 'image/svg+xml', href: '/favicon/favicon.svg' }],
1317
['link', { rel: 'shortcut icon', href: '/favicon/favicon.ico' }],
1418
['link', { rel: 'apple-touch-icon', sizes: '180x180', href: '/favicon/apple-touch-icon.png' }],
1519
['meta', { name: 'apple-mobile-web-app-title', content: 'CakePHP' }],
1620
['link', { rel: 'manifest', href: '/favicon/site.webmanifest' }],
17-
['link', { rel: 'preconnect', href: 'https://fonts.bunny.net' }],
18-
['link', { href: 'https://fonts.bunny.net/css?family=raleway:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i', rel: 'stylesheet' }],
1921
],
2022
themeConfig: {
2123
logo: '/logo.svg',
@@ -48,16 +50,18 @@ const defaultConfig = {
4850
},
4951
markdown: {
5052
lineNumbers: true,
51-
config: (md) => {
52-
md.use(versionReplacer)
53-
}
5453
},
5554
locales: {}
5655
}
5756

5857
const overrides = await loadConfigOverrides(import.meta.url)
5958
const mergedConfig = deepMerge(defaultConfig, overrides)
6059

60+
// Configure markdown plugins after mergedConfig is available
61+
mergedConfig.markdown.config = (md) => {
62+
md.use(versionReplacer, mergedConfig.phpVersions || {})
63+
}
64+
6165
// Apply base path to head tags if base is specified
6266
if (overrides.base) {
6367
applyBaseToHeadTags(mergedConfig, overrides.base)

.vitepress/plugins/version-replacer.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@
88
* Create a version replacer plugin
99
* @param {Object} md - markdown-it instance
1010
* @param {Object} options - plugin options
11+
* @param {string} options.phpversion - Current PHP version (default: '8.4')
12+
* @param {string} options.minphpversion - Minimum PHP version (default: '8.1')
1113
* @returns {void}
1214
*/
13-
export function versionReplacer(md, _options = {}) {
15+
export function versionReplacer(md, options = {}) {
16+
// Use provided versions or fall back to defaults
17+
const phpversion = options.phpversion || '8.4'
18+
const minphpversion = options.minphpversion || '8.1'
19+
1420
// Store original render method
1521
const originalRender = md.render.bind(md)
1622

1723
md.render = function(src, env = {}) {
1824
src = src
19-
.replace(/\|phpversion\|/g, `**8.4**`)
20-
.replace(/\|minphpversion\|/g, `*8.1*`)
25+
.replace(/\|phpversion\|/g, `**${phpversion}**`)
26+
.replace(/\|minphpversion\|/g, `*${minphpversion}*`)
2127

2228
return originalRender(src, env)
2329
}

0 commit comments

Comments
 (0)