[MM-25656] Adds a function to allow to update assets subpath in a given directory (#15020)

This commit is contained in:
Miguel de la Cruz
2020-09-17 16:19:26 +02:00
committed by GitHub
parent 4c64cec948
commit 42657fafa1

View File

@@ -45,14 +45,14 @@ func GetSubpathScriptHash(subpath string) string {
return fmt.Sprintf(" 'sha256-%s'", base64.StdEncoding.EncodeToString(scriptHash[:]))
}
// UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted
// at the given subpath instead of at the root. No changes are written unless necessary.
func UpdateAssetsSubpath(subpath string) error {
// UpdateAssetsSubpathInDir rewrites assets in the given directory to assume the application is
// hosted at the given subpath instead of at the root. No changes are written unless necessary.
func UpdateAssetsSubpathInDir(subpath, directory string) error {
if subpath == "" {
subpath = "/"
}
staticDir, found := fileutils.FindDir(model.CLIENT_DIR)
staticDir, found := fileutils.FindDir(directory)
if !found {
return errors.New("failed to find client dir")
}
@@ -139,6 +139,12 @@ func UpdateAssetsSubpath(subpath string) error {
return nil
}
// UpdateAssetsSubpath rewrites assets in the /client directory to assume the application is hosted
// at the given subpath instead of at the root. No changes are written unless necessary.
func UpdateAssetsSubpath(subpath string) error {
return UpdateAssetsSubpathInDir(subpath, model.CLIENT_DIR)
}
// UpdateAssetsSubpathFromConfig uses UpdateAssetsSubpath and any path defined in the SiteURL.
func UpdateAssetsSubpathFromConfig(config *model.Config) error {
// Don't rewrite in development environments, since webpack in developer mode constantly