多语言支持初版,不支持static export

This commit is contained in:
tangly1024.com
2024-04-08 16:01:41 +08:00
parent 214b40fb5a
commit 1c9526f4b5
23 changed files with 585 additions and 230 deletions

33
lib/utils/pageId.js Normal file
View File

@@ -0,0 +1,33 @@
/**
* 截取page-id的语言前缀
* notionPageId的格式可以是 en:xxxxx
* @param {*} str
* @returns en|zh|xx
*/
function extractLangPrefix(str) {
const match = str.match(/^(.+?):/)
if (match && match[1]) {
return match[1]
} else {
return ''
}
}
/**
* 截取page-id的id
* notionPageId的格式可以是 en:xxxxx * @param {*} str
* @returns xxxxx
*/
function extractLangId(str) {
// 使用正则表达式匹配字符串
const match = str.match(/:\s*(.+)/)
// 如果匹配成功,则返回匹配到的内容
if (match && match[1]) {
return match[1]
} else {
// 如果没有匹配到,则返回空字符串或者其他你想要返回的值
return str
}
}
module.exports = { extractLangPrefix, extractLangId }