mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-16 06:11:38 +00:00
Style: simplify base path normalization
This commit is contained in:
parent
9f6d70e130
commit
e50b78e121
2 changed files with 15 additions and 22 deletions
|
|
@ -327,13 +327,11 @@ class Server {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply the current RouterBasePath to all `<base>` tags in the client html files
|
// Apply the current RouterBasePath to all html and js files
|
||||||
async applyClientBasePath() {
|
async applyClientBasePath() {
|
||||||
const basePath = `/${global.RouterBasePath}/`
|
const basePathSlash = `/${global.RouterBasePath}/`
|
||||||
.replace('///', '') // convert base path `"/""` to `""`
|
.replace(/\/\/+/, '/') // Ensure there are single `/` at the front and end
|
||||||
.replace('//', '/') // Ensure there are single `/` at the front and end
|
const basePath = basePathSlash.slice(0, -1) // Remove trailing `/`
|
||||||
.slice(0, -1) // Remove trailing `/`
|
|
||||||
const basePathSlash = `${basePath}/`
|
|
||||||
const distPath = Path.join(global.appRoot, '/client/dist')
|
const distPath = Path.join(global.appRoot, '/client/dist')
|
||||||
|
|
||||||
// Check if the client base path is already set to the current base path
|
// Check if the client base path is already set to the current base path
|
||||||
|
|
@ -356,16 +354,13 @@ class Server {
|
||||||
const htmlPath = Path.join(distPath, htmlFile)
|
const htmlPath = Path.join(distPath, htmlFile)
|
||||||
let html = await fs.readFile(htmlPath, 'utf8')
|
let html = await fs.readFile(htmlPath, 'utf8')
|
||||||
|
|
||||||
// Replace all urls with the new base path
|
html = html
|
||||||
html = html.replace(replaceUrls, `$1${basePathSlash}$2`)
|
.replace(replaceUrls, `$1${basePathSlash}$2`) // Replace all urls with the new base path
|
||||||
|
.replace(replaceNuxtConfig, (config) => config // Replace paths in nuxt config (inline script in html files)
|
||||||
// Replace paths in nuxt config (inline script in html files)
|
.replace(/routerBasePath:"([^"]*)"/, `routerBasePath:"${basePath}"`)
|
||||||
html = html.replace(replaceNuxtConfig, (config) => {
|
.replace(/basePath:"([^"]*)"/, `basePath:"${basePathSlash}"`)
|
||||||
config = config.replace(/routerBasePath:"([^"]*)"/, `routerBasePath:"${basePath}"`)
|
.replace(/assetsPath:"([^"]*)"/, `assetsPath:"${basePathSlash}_nuxt/"`)
|
||||||
config = config.replace(/basePath:"([^"]*)"/, `basePath:"${basePathSlash}"`)
|
)
|
||||||
config = config.replace(/assetsPath:"([^"]*)"/, `assetsPath:"${basePathSlash}_nuxt/"`)
|
|
||||||
return config
|
|
||||||
})
|
|
||||||
|
|
||||||
await fs.writeFile(htmlPath, html)
|
await fs.writeFile(htmlPath, html)
|
||||||
}
|
}
|
||||||
|
|
@ -374,11 +369,9 @@ class Server {
|
||||||
const jsPath = Path.join(distPath, jsFile)
|
const jsPath = Path.join(distPath, jsFile)
|
||||||
let js = await fs.readFile(jsPath, 'utf8')
|
let js = await fs.readFile(jsPath, 'utf8')
|
||||||
|
|
||||||
// Replace all urls with the new base path
|
js = js
|
||||||
js = js.replace(replaceUrls, `$1${basePathSlash}$2`)
|
.replace(replaceUrls, `$1${basePathSlash}$2`) // Replace all urls with the new base path
|
||||||
|
.replace(replaceAssetPaths, `${basePath}/$1`) // Replace asset paths in js files
|
||||||
// Replace asset paths in js files
|
|
||||||
js = js.replace(replaceAssetPaths, `${basePath}/$1`)
|
|
||||||
|
|
||||||
await fs.writeFile(jsPath, js)
|
await fs.writeFile(jsPath, js)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue