Skip to content

Commit

Permalink
feat(libprepare): stripping suffix ".svelte" from page ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare committed Jan 29, 2025
1 parent 5ee00cd commit 10eb1da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 4 additions & 7 deletions libprepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func PrepareSveltePages(directoryName string) {
}

fileName := info.Name()
id := strings.ReplaceAll(
pageId := strings.ReplaceAll(
strings.ReplaceAll(
strings.TrimSuffix(fileName, ".svelte"),
"/",
Expand All @@ -36,7 +36,7 @@ func PrepareSveltePages(directoryName string) {
"::",
)

PrepareSveltePage(id, filepath.Join(directoryName, fileName))
PrepareSveltePage(pageId, filepath.Join(directoryName, fileName))

return nil
},
Expand All @@ -49,15 +49,12 @@ func PrepareSveltePages(directoryName string) {
}

// PrepareSveltePage prepares a svelte page.
func PrepareSveltePage(id string, fileName string) {
if strings.HasSuffix(id, ".svelte") {
id = strings.TrimSuffix(id, ".svelte")
}
func PrepareSveltePage(pageId string, fileName string) {
relativeFileName, err := filepath.Rel("www/.frizzante/vite-project", fileName)
if err != nil {
panic(err)
}
sveltePagesToFileNames[id] = fmt.Sprintf("./%s", relativeFileName)
sveltePagesToFileNames[pageId] = fmt.Sprintf("./%s", relativeFileName)
}

// PrepareStart begins preparation.
Expand Down
3 changes: 3 additions & 0 deletions libserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ var pathParametersPattern = regexp.MustCompile(`{([^{}]+)}`)

// ServerWithSveltePage creates a request handler that serves a svelte page.
func ServerWithSveltePage(self *Server, pattern string, pageId string, configure func(*Request) *SveltePageConfiguration) {
if strings.HasSuffix(pageId, ".svelte") {
pageId = strings.TrimSuffix(pageId, ".svelte")
}
patternParts := strings.Split(pattern, " ")
if len(patternParts) > 1 {
sveltePagesToPaths[pageId] = patternParts[1]
Expand Down

0 comments on commit 10eb1da

Please sign in to comment.