hexo-theme-stellar/scripts/helpers/parse_config.js

43 lines
884 B
JavaScript
Raw Normal View History

2021-02-24 21:27:31 +08:00
/**
2024-01-14 16:42:20 +08:00
* md_link(theme.menu['home']) is '/'
* md_text(theme.menu['home']) is 'Home'
2021-02-24 21:27:31 +08:00
*/
'use strict';
hexo.extend.helper.register('md_text', function(args) {
if (args == undefined) {
2024-01-17 00:27:48 +08:00
return ''
2021-02-24 21:27:31 +08:00
}
2024-02-06 14:07:46 +08:00
const { config } = hexo
args = args.replace('${config.title}', config.title)
args = args.replace('${config.subtitle}', config.subtitle)
args = args.replace('${config.avatar}', config.avatar)
2024-01-17 00:27:48 +08:00
let tmp = args.split('](')
2021-02-24 21:27:31 +08:00
if (tmp.length > 1) {
2024-01-17 00:27:48 +08:00
tmp = tmp[0]
2021-02-24 21:27:31 +08:00
if (tmp.length > 1) {
2024-01-17 00:27:48 +08:00
tmp = tmp.substring(1, tmp.length)
2021-02-24 21:27:31 +08:00
}
2024-02-06 14:07:46 +08:00
} else {
tmp = args
2021-02-24 21:27:31 +08:00
}
2024-01-17 00:27:48 +08:00
return tmp
})
2021-02-24 21:27:31 +08:00
hexo.extend.helper.register('md_link', function(args) {
if (args == undefined) {
2024-01-17 00:27:48 +08:00
return ''
2021-02-24 21:27:31 +08:00
}
2024-01-17 00:27:48 +08:00
let tmp = args.split('](')
2021-02-24 21:27:31 +08:00
if (tmp.length > 1) {
2024-01-17 00:27:48 +08:00
tmp = tmp[1]
2021-02-24 21:27:31 +08:00
if (tmp.length > 1) {
2024-01-17 00:27:48 +08:00
tmp = tmp.substring(0, tmp.length-1)
2021-02-24 21:27:31 +08:00
}
2024-01-17 00:27:48 +08:00
} else {
return ''
2021-02-24 21:27:31 +08:00
}
2024-01-17 00:27:48 +08:00
return tmp
})