Skip to content

Commit bcf6cdc

Browse files
author
antalike
committed
Replace API baseUrl in content during compilation
1 parent 32c25bb commit bcf6cdc

7 files changed

Lines changed: 20 additions & 6 deletions

File tree

app/components/Api/Path.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const props = defineProps<{
1414
}>()
1515
1616
const { server } = useOpenApi(inject('collectionName'))
17+
const { replaceVariables } = useVariableReplacement()
1718
1819
const colorsMap: colorsProps = {
1920
get: {
@@ -52,7 +53,7 @@ function isParameter(path: string) {
5253
5354
// Copy full path
5455
function handleCopy() {
55-
const baseUrl = server.value ?? ''
56+
const baseUrl = replaceVariables(server.value ?? '')
5657
5758
copyText(baseUrl + props.path)
5859
isCopy.value = true

app/composables/useVariableReplacement.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ export const useVariableReplacement = () => {
1111
'https://statics.memtensor.com.cn': config.public.staticCdnUrl as string,
1212
'https://memos-playground.openmem.net': config.public.playgroundUrl as string,
1313
'https://memos-dashboard.openmem.net': config.public.dashboardUrl as string,
14-
'https://memos.openmem.net': config.public.homeDomain as string
14+
'https://memos.openmem.net': config.public.homeDomain as string,
15+
'https://memos.memtensor.cn': config.public.baseUrl as string
1516
}
1617

1718
Object.keys(domains).forEach((key) => {

envConfig/config.intl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ export default {
66
dashboardUrl: 'https://memos-dashboard.memtensor.net',
77
playgroundUrl: 'https://memos-playground.memtensor.net',
88
staticCdnUrl: 'https://cdn.memt.ai/static',
9-
cdnUrl: 'https://cdn.memt.ai'
9+
cdnUrl: 'https://cdn.memt.ai',
10+
baseUrl: 'https://api.memt.ai'
1011
}

envConfig/config.pre.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ export default {
55
openMemUrl: 'https://pre.openmem.net',
66
githubMemosUrl: 'https://github.com/MemTensor/MemOS',
77
dashboardUrl: 'https://memos-dashboard-pre.openmem.net',
8-
playgroundUrl: 'https://memos-playground-pre.openmem.net'
8+
playgroundUrl: 'https://memos-playground-pre.openmem.net',
9+
baseUrl: 'https://apigw-pre.memtensor.cn'
910
}

envConfig/config.prod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default {
44
openMemUrl: 'https://openmem.net',
55
githubMemosUrl: 'https://github.com/MemTensor/MemOS',
66
dashboardUrl: 'https://memos-dashboard.openmem.net',
7-
playgroundUrl: 'https://memos-playground.openmem.net'
7+
playgroundUrl: 'https://memos-playground.openmem.net',
8+
baseUrl: 'https://memos.memtensor.cn'
89
}

nuxt.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ const config: NuxtConfig = {
109109
linkDomains: {
110110
'https://memos-playground.openmem.net': envConfig.playgroundUrl,
111111
'https://memos-dashboard.openmem.net': envConfig.dashboardUrl,
112-
'https://memos.openmem.net': envConfig.homeDomain
112+
'https://memos.openmem.net': envConfig.homeDomain,
113+
'https://memos.memtensor.cn': envConfig.baseUrl
113114
}
114115
}
115116
}

scripts/remark-replace-domains.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export default function remarkReplaceDomains(options = {}) {
2626
})
2727
}
2828

29+
// Handle code blocks
30+
if (node.type === 'code' && node.value && typeof node.value === 'string') {
31+
Object.keys(linkDomains).forEach((key) => {
32+
const regex = new RegExp(escapeRegExp(key), 'g')
33+
node.value = node.value.replace(regex, linkDomains[key])
34+
})
35+
}
36+
2937
// Handle HTML nodes for both images and links
3038
if (node.type === 'html' && node.value && typeof node.value === 'string') {
3139
// Replace image sources

0 commit comments

Comments
 (0)