I'm trying to utilise the package.json version tag inside of my *.md
files which get later compiled into HTML, however I can't seem to figure out how to do this. My plugin.js files contains the following which I thought I could utilise:
const { version } = require('../../package.json')
module.exports = (/*options, ctx*/) => ({
async enhanceAppFiles () {
const code = `export default ({ Vue }) => {
Vue.mixin({
computed: {
$version () {
return '${version}'
}
}
})
}`
return [{
name: 'vuepress-plugin-vue-cli-plugin-p11n',
content: code
}]
}
})
I tried using version
and $version
inside of my *.md
files with little luck, has anyone else got this issue?
The easiest way to achieve this, it's simply put the version
into themeConfig
and let VuePress do its thing
// .vuepress/config.js
const { version } = require('../../package')
module.exports = {
themeConfig: {
version: version
}
}
and use it in markdown like
{{ $themeConfig.version }}
However, it seems like that themeConfig
isn't meant for this, so you can also create your own computed properties
// .vuepress/enhanceApp.js
const { version } = require('../../package')
export default ({ Vue }) => {
Vue.mixin({
computed: {
$version: function() {
return version
}
}
})
}
and use it like
{{ $version }}
Hi, thanks! These both work, however it looks like it was working before, and I've just realised, I'm trying to use
{{ $themeConfig.version }}
within a code block, using the back ticks, the black sh sections, is this still possible? How could I get it here.I'm not sure I completely understand you. Basically, you want to use
{{}}
syntax inside a code block? I don't think it's possible. I mean, the point of a code block is to display the code as it is, right? However, I think you can try to customize a container or create a component to achieve that