Merge pull request #622 from trheyi/main
refactor: Update Namespace function to handle special characters in name
This commit is contained in:
commit
cc3a9d9140
2 changed files with 11 additions and 1 deletions
|
|
@ -208,7 +208,7 @@ func (page *Page) parse(doc *goquery.Document, option *BuildOption, warnings []s
|
|||
}
|
||||
|
||||
p := ipage.Get()
|
||||
namespace := fmt.Sprintf("__page_%s_%d", strings.ReplaceAll(name, "/", "_"), idx)
|
||||
namespace := Namespace(name, idx)
|
||||
html, style, script, warns, err := p.BuildForImport(&BuildOption{
|
||||
SSR: option.SSR,
|
||||
AssetRoot: option.AssetRoot,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package core
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
|
|
@ -25,3 +26,12 @@ func NewDocumentString(htmlContent string) (*goquery.Document, error) {
|
|||
}
|
||||
return goquery.NewDocumentFromNode(docNode), nil
|
||||
}
|
||||
|
||||
// Namespace convert the name to namespace
|
||||
func Namespace(name string, idx int) string {
|
||||
name = strings.ReplaceAll(name, "/", "_")
|
||||
name = strings.ReplaceAll(name, "[", "_")
|
||||
name = strings.ReplaceAll(name, "]", "_")
|
||||
namespace := fmt.Sprintf("__page_%s_%d", name, idx)
|
||||
return namespace
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue