Skip to content

Commit

Permalink
Convert spaces in content files (#82).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed Jan 19, 2021
1 parent 75311ed commit 1bbac97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions cmd/build/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,19 @@ func Client(buildPath string, tempBuildDir string, ejectedPath string) {

// Replace .svelte file extension with .js.
destFile = strings.TrimSuffix(destFile, filepath.Ext(destFile)) + ".js"
// Convert any spaces into hyphens.
destFile = strings.ReplaceAll(destFile, " ", "-")

compileSvelte(ctx, SSRctx, layoutPath, destFile, stylePath, tempBuildDir)

// Remove temporary theme build directory.
destLayoutPath := strings.TrimPrefix(layoutPath, tempBuildDir)
// Create entry for layout.js.
layoutSignature := strings.ReplaceAll(strings.ReplaceAll((destLayoutPath), "/", "_"), ".", "_")
layoutSignature := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll((destLayoutPath), "/", "_"), ".", "_"), " ", "_")
// Remove layout directory.
destLayoutPath = strings.TrimPrefix(destLayoutPath, "layout/")
// Convert any spaces into hyphens.
destLayoutPath = strings.ReplaceAll(destLayoutPath, " ", "-")
// Compose entry for layout.js file.
allComponentsStr = allComponentsStr + "export {default as " + layoutSignature + "} from '../" + destLayoutPath + "';\n"

Expand Down Expand Up @@ -188,7 +192,7 @@ func compileSvelte(ctx *v8go.Context, SSRctx *v8go.Context, layoutPath string, d
// Remove temporary theme directory info from path before making a comp signature.
layoutPath = strings.TrimPrefix(layoutPath, tempBuildDir)
// Create custom variable name for component based on the file path for the layout.
componentSignature := strings.ReplaceAll(strings.ReplaceAll(layoutPath, "/", "_"), ".", "_")
componentSignature := strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(layoutPath, "/", "_"), ".", "_"), " ", "_")
// Use signature instead of generic "Component". Add space to avoid also replacing part of "loadComponent".
ssrStr = strings.ReplaceAll(ssrStr, " Component ", " "+componentSignature+" ")

Expand Down
2 changes: 2 additions & 0 deletions cmd/build/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func DataSource(buildPath string, siteConfig readers.SiteConfig, tempBuildDir st

// Remove the extension (if it exists) from single types since the filename = the type name.
contentType = strings.TrimSuffix(contentType, filepath.Ext(contentType))
// Convert any spaces (if found) into underscores.
contentType = strings.ReplaceAll(contentType, " ", "_")

// Get field key/values from content source.
typeFields := readers.GetTypeFields(fileContentBytes)
Expand Down

0 comments on commit 1bbac97

Please sign in to comment.